### Install Wine for Cross-Compilation on Linux Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/publishing/building.md Example commands for installing 32-bit Wine on Debian-based systems (like Ubuntu) to facilitate building Windows x64 applications. ```bash # Example installation of wine for Debian based distributions (Ubuntu) dpkg --add-architecture i386 apt-get -y update apt-get -y install wine32 ``` -------------------------------- ### Install a Premium Plugin Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/using-plugins.md Install a premium plugin after configuring the private repository and credentials. ```shell composer require vendor/nativephp-premium-plugin ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/environment-setup.md Installs the necessary command-line tools for Xcode. Verify the installation by checking the path. ```shell xcode-select --install ``` ```shell xcode-select -p ``` -------------------------------- ### Quit and Install Update Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/publishing/updating.md After an update has been downloaded, you can prompt the user to quit the application and install the update using the `quitAndInstall` method. The application will automatically relaunch after the installation. ```php use Native\Desktop\Facades\AutoUpdater; AutoUpdater::quitAndInstall(); ``` -------------------------------- ### Download and Copy ML Model Example Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/lifecycle-hooks.md This example demonstrates downloading an ML model if it's not cached and then copying it to the appropriate platform-specific asset or bundle location. It utilizes helper methods like downloadIfMissing(), copyToAndroidAssets(), and copyToIosBundle(). ```php public function handle(): int { $modelPath = $this->pluginPath() . '/resources/models/model.tflite'; // Download if not cached locally $this->downloadIfMissing( 'https://example.com/models/v2/model.tflite', $modelPath ); // Copy to the appropriate platform location if ($this->isAndroid()) { $this->copyToAndroidAssets('models/model.tflite', 'models/model.tflite'); $this->info('Model copied to Android assets'); } if ($this->isIos()) { $this->copyToIosBundle('models/model.tflite', 'models/model.tflite'); $this->info('Model copied to iOS bundle'); } return self::SUCCESS; } ``` -------------------------------- ### Install AI Agents for Plugin Development Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/commands.md Install AI agents to aid in plugin development. Use `--force` to overwrite existing files or `--all` to install all agents without prompting. ```shell php artisan native:plugin:install-agent ``` -------------------------------- ### Start Process with Command Line Arguments Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/digging-deeper/child-processes.md Pass command line arguments to a child process when starting it. The `cmd` parameter accepts either a string or an array of arguments. ```php ChildProcess::start( cmd: ['tail', '-f', 'storage/logs/laravel.log'], alias: 'tail' ); ``` -------------------------------- ### Start Process with Environment Variables Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/digging-deeper/child-processes.md When starting a child process, you can provide custom environment variables using the `env` parameter. These variables will be available to the child process. ```php ChildProcess::start( cmd: 'tail ...', alias: 'tail', env: [ 'CUSTOM_ENV_VAR' => 'custom value', ] ); ``` -------------------------------- ### Plugin Installation Commands Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/best-practices.md Standard commands for installing and registering a NativePHP plugin using Composer and Artisan. ```markdown ## Installation composer require vendor/my-plugin php artisan native:plugin:register vendor/my-plugin ``` -------------------------------- ### Start Jump Development Server Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/the-basics/jump.md Run this command in your Laravel project to start the development server for Jump. This will generate a QR code to scan with the Jump app on your device. ```shell php artisan native:jump ``` -------------------------------- ### Run NativePHP Installer Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/getting-started/installation.md Execute the NativePHP installer to set up your application. This command publishes the service provider, configuration file, and registers necessary scripts in composer.json. ```shell php artisan native:install ``` -------------------------------- ### Install a Standard Plugin Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/using-plugins.md Use Composer to install a standard NativePHP plugin package. ```shell composer require vendor/nativephp-plugin-name ``` -------------------------------- ### Get All Open Windows Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/windows.md Use `Window::all()` to get a collection of all currently open windows. You can then iterate over this collection to perform actions on each window. ```php foreach (Window::all() as $window) { $window->url(route('home')); } ``` -------------------------------- ### PHP Usage Example with Livewire Event Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/best-practices.md Demonstrates basic PHP facade usage and listening for plugin-dispatched events within a Livewire component. ```markdown ## Usage (PHP) use Vendor\MyPlugin\Facades\MyPlugin; // Basic usage $result = MyPlugin::doSomething(['option' => 'value']); // Listening for events in Livewire #[OnNative(SomethingCompleted::class)] public function handleResult($data) { $this->result = $data['result']; } ``` -------------------------------- ### Install CocoaPods Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/environment-setup.md Installs CocoaPods, a dependency manager for Swift and Objective-C Cocoa projects. Verify the installation by checking the version. ```shell brew install cocoapods ``` ```shell pod --version ``` -------------------------------- ### Using Bundled Tools with ChildProcess Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/digging-deeper/files.md Access a bundled executable using the 'extras' disk and then start it as a child process. Ensure the file exists in the `extras/` directory. ```php use Illuminate\Support\Facades\Storage; use Native\Desktop\Facades\ChildProcess; // Get the path to a bundled executable $toolPath = Storage::disk('extras')->path('my-tool.sh'); ChildProcess::start( cmd: $toolPath, alias: 'my-tool' ); ``` -------------------------------- ### Start a Basic Child Process Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/digging-deeper/child-processes.md Spawns a new child process to execute a command. The process will continue running in the background even after the request that started it has finished. Ensure the command is executable and consider platform-specific arguments. ```php use Native\Desktop\Facades\ChildProcess; ChildProcess::start( cmd: 'tail -f storage/logs/laravel.log', alias: 'tail' ); ``` -------------------------------- ### Relaunch the Application Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/application.md The `relaunch` method will quit the application and then start it again. ```php App::relaunch(); ``` -------------------------------- ### Start a Child Process with Custom Working Directory Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/digging-deeper/child-processes.md Starts a child process and sets its current working directory to a specified path. This is useful when the command relies on relative paths or needs to operate within a specific directory context. The command can be provided as a string or an array of arguments. ```php ChildProcess::start( cmd: ['tail', '-f', 'logs/laravel.log'], alias: 'tail', cwd: storage_path() ); ``` -------------------------------- ### Livewire Component Example Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/best-practices.md Demonstrates how to use NativePHP attributes and facades within a Livewire component for handling native events and actions. ```php use Livewire\Component; use Native\Mobile\Attributes\OnNative; use Vendor\MyPlugin\Facades\MyPlugin; use Vendor\MyPlugin\Events\ScanComplete; class Scanner extends Component { public ?string $result = null; public function scan(): void { MyPlugin::startScan(); } #[OnNative(ScanComplete::class)] public function handleScan($data): void { $this->result = $data['value']; } public function render() { return view('livewire.scanner'); } } ``` -------------------------------- ### Using the Native Script Helper Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/quick-start.md After running `php artisan native:install`, a `native` script helper is created. This demonstrates how to use it as a wrapper for the `native` Artisan command namespace. ```shell # Instead of... php artisan native:run # Do php native run # Or ./native run ``` -------------------------------- ### Get Command Help Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/development.md Use the `--help` flag to discover available arguments and options for commands like `native:run` to skip prompts. ```shell php artisan native:run --help ``` -------------------------------- ### Install and Run NativePHP Mobile App Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/quick-start.md Commands to install NativePHP for mobile into a new Laravel app and then prepare and run the app on a mobile device. ```bash # Install NativePHP for Mobile into a new Laravel app composer require nativephp/mobile # Ready your app to go native php artisan native:install # Run your app on a mobile device php artisan native:run ``` -------------------------------- ### Set Application Start URL Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/configuration.md Configure the initial URL that loads when your NativePHP app starts. Useful for directing users to specific pages like '/dashboard' or '/onboarding'. ```php 'start_url' => env('NATIVEPHP_START_URL', '/'), ``` -------------------------------- ### Livewire Lifecycle Hook Examples Source: https://github.com/nativephp/nativephp.com/blob/main/AGENTS.md Utilize lifecycle hooks like `mount()` for initialization and `updatedFoo()` for reactive side effects in Livewire components. ```php public function mount(User $user) { $this->user = $user; } public function updatedSearch() { $this->resetPage(); } ``` -------------------------------- ### Start Hot Reloading Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/development.md Initiate the hot reloading process to enable live updates during development. ```shell php artisan native:watch ``` -------------------------------- ### Livewire Component Test Example Source: https://github.com/nativephp/nativephp.com/blob/main/AGENTS.md A basic test for a Livewire component, asserting initial state, method calls, and rendered output. ```php Livewire::test(Counter::class) ->assertSet('count', 0) ->call('increment') ->assertSet('count', 1) ->assertSee(1) ->assertStatus(200); ``` -------------------------------- ### JavaScript Usage Example for SPAs Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/best-practices.md Shows how to import and use a plugin's JavaScript functions within SPA frameworks like Vue or React. ```markdown ## Usage (JavaScript) import { DoSomething } from 'vendor-my-plugin'; // In Vue/React components const result = await DoSomething({ option: 'value' }); ``` -------------------------------- ### Create Boost Guidelines for AI Assistants Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/creating-plugins.md Generates AI guidelines for your plugin, documenting its facade, methods, events, and JavaScript usage. These guidelines are automatically loaded when users run `php artisan boost:install`. ```shell php artisan native:plugin:boost ``` -------------------------------- ### Run NativePHP Installer Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/installation.md Execute this Artisan command to set up and configure your Laravel application for NativePHP. ```shell php artisan native:install ``` -------------------------------- ### List Registered Plugins Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/creating-plugins.md View all plugins that are currently registered in your application. Use the `--all` flag to see all installed plugins, including unregistered ones. ```shell # Show registered plugins php artisan native:plugin:list # Show all installed plugins (including unregistered) php artisan native:plugin:list --all ``` -------------------------------- ### Configure JavaScript Native Library Import Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/the-basics/native-functions.md Add this configuration to your package.json to enable the import of the Native JavaScript library. Run 'npm install' after updating. ```json { "dependencies": { ... }, "imports": { "#nativephp": "./vendor/nativephp/mobile/resources/dist/native.js" } } ``` -------------------------------- ### Basic Side Navigation Structure Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/edge-components/side-nav.md This example demonstrates the basic structure of a side navigation component, including a header, navigation items, a grouped section, and a divider. Use this as a starting point for building your app's navigation. ```blade ``` -------------------------------- ### Configure Windows Environment Variables Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/environment-setup.md Sets ANDROID_HOME and updates the PATH for Android development tools on Windows. Assumes default installation paths for Android SDK and JDK. ```shell set ANDROID_HOME=C:\Users\yourname\AppData\Local\Android\Sdk set PATH=%PATH%;%JAVA_HOME%\bin;%ANDROID_HOME%\platform-tools # This isn't required if JAVA_HOME is already set in the Windows Env Variables set JAVA_HOME=C:\Program Files\Microsoft\jdk-17.0.8.7-hotspot ``` -------------------------------- ### Register Global Hotkeys in Service Provider Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/global-hotkeys.md Register global hotkeys within the `boot` method of your `NativeAppServiceProvider`. This ensures hotkeys are available when the application starts. ```php namespace App\Providers; use Native\Desktop\Facades\GlobalShortcut; class NativeAppServiceProvider { public function boot(): void { GlobalShortcut::key('CmdOrCtrl+Shift+A') ->event(\App\Events\MyShortcutEvent::class) ->register(); // Additional code, such as registering a menu, opening windows, etc. } } ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/contributing.md Clone your forked repository locally and navigate into the project directory to begin making changes. ```bash git clone git@github.com:your-username/mobile-air.git cd mobile-air ``` -------------------------------- ### Plugin Initialization Functions Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/advanced-configuration.md Specify native functions to call during app initialization for SDKs requiring early setup. These functions run once when the app starts, before any bridge functions are available. Keep them fast to avoid slowing down app launch. ```json { "android": { "init_function": "com.myvendor.plugins.myplugin.MyPluginInit.initialize" }, "ios": { "init_function": "MyPluginInit.initialize" } } ``` -------------------------------- ### Using Plugin Facades and Events in PHP Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/introduction.md Demonstrates how to interact with a plugin's functionality from your PHP code using facades and how to listen for events dispatched from native code. ```php use Vendor\MyPlugin\Facades\MyPlugin; // Call native functions MyPlugin::doSomething(); // Listen for events #[OnNative(MyPlugin\Events\SomethingHappened::class)] public function handleResult($data) { // Handle it } ``` -------------------------------- ### Install Homebrew Package Manager Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/environment-setup.md Installs Homebrew, a package manager for macOS, used to install other development tools like CocoaPods. ```shell /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### PHP Constructor Property Promotion Source: https://github.com/nativephp/nativephp.com/blob/main/AGENTS.md Use PHP 8 constructor property promotion for concise constructor definitions. This example shows a constructor that accepts a GitHub object. ```php public function __construct(public GitHub $github) { } ``` -------------------------------- ### Basic Top Bar with Actions Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/edge-components/top-bar.md This example demonstrates how to implement a top bar with a title, subtitle, and two action buttons. One action navigates within the app, while the other opens an external URL. ```blade ``` -------------------------------- ### Placeholder Substitution in Text Assets Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/advanced-configuration.md Example of an XML asset file demonstrating placeholder substitution for environment variables. These placeholders are replaced during the build process. ```xml ${MY_PLUGIN_API_KEY} ``` -------------------------------- ### Default NativeAppServiceProvider Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/app-lifecycle.md This service provider is published when running `php artisan native:install`. Use its `boot()` method to initialize application features like opening windows or registering shortcuts. It also implements `ProvidesPhpIni` to set PHP configuration directives. ```php namespace App\Providers; use Native\Desktop\Facades\Window; use Native\Desktop\Contracts\ProvidesPhpIni; class NativeAppServiceProvider implements ProvidesPhpIni { /** * Executed once the native application has been booted. * Use this method to open windows, register global shortcuts, etc. */ public function boot(): void { Window::open(); } /** * Return an array of php.ini directives to be set. */ public function phpIni(): array { return [ ]; } } ``` -------------------------------- ### Creating the Application Menu Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/application-menu.md Register a new application menu by calling `Menu::create()`. You can pass predefined menus or custom menu items as arguments. This configuration should typically be done in the `boot` method of your `NativeAppServiceProvider`. ```APIDOC ## Creating the menu To create a new application menu, you may use the `Menu::create()` method. This method creates _and registers_ your menu in one step. You can customize the items that appear in the menu by passing them as parameters to the `create` method: ```php use Native\Desktop\Facades\Menu; use Native\Desktop\Facades\Window; class NativeAppServiceProvider { public function boot(): void { Menu::create( Menu::app(), // Only on macOS Menu::file(), Menu::edit(), Menu::view(), Menu::window(), ); Window::open(); } } ``` ``` -------------------------------- ### Listen to Native Events with Livewire (String) Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/digging-deeper/broadcasting.md When using Livewire, prefix native event names with 'native:' to listen for them. This example shows listening for window focus and blur events. ```php class AppSettings extends Component { public $windowFocused = true; #[On('native:\Native\Desktop\Events\Windows\WindowFocused')] public function windowFocused() { $this->windowFocused = true; } #[On('native:\Native\Desktop\Events\Windows\WindowBlurred')] public function windowBlurred() { $this->windowFocused = false; } } ``` -------------------------------- ### Example Livewire Component Test Source: https://github.com/nativephp/nativephp.com/blob/main/CLAUDE.md Test Livewire component interactions by asserting initial state, calling actions, and verifying UI changes and HTTP status. ```php Livewire::test(Counter::class) ->assertSet('count', 0) ->call('increment') ->assertSet('count', 1) ->assertSee(1) ->assertStatus(200); ``` -------------------------------- ### Install NativePHP Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/commands.md Use this command to install NativePHP into your Laravel application. You can specify the target platform. ```shell php artisan native:install {platform?} ``` -------------------------------- ### JavaScript Integration with Native Functions Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/the-basics/native-functions.md Import and use native functions from JavaScript, mirroring the PHP API. This example demonstrates microphone usage with event listeners for mounting and unmounting. ```javascript import { On, Off, Microphone, Events } from '#nativephp'; import { onMounted, onUnmounted } from 'vue'; const buttonClicked = () => { Microphone.record(); }; const handleRecordingFinished = () => { // Update the UI }; onMounted(() => { On(Events.Microphone.MicrophoneRecorded, handleRecordingFinished); }); onUnmounted(() => { Off(Events.Microphone.MicrophoneRecorded, handleRecordingFinished); }); ``` -------------------------------- ### Create Boost AI Guidelines for a Plugin Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/commands.md Scaffold Boost AI guidelines for a specified plugin. Use `--force` to overwrite existing guidelines. ```shell php artisan native:plugin:boost {plugin?} ``` -------------------------------- ### Update Composer and Install NativePHP Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/getting-started/upgrade-guide.md After updating your composer.json, run `composer update` to fetch the new package and then `php artisan native:install` to set up the NativePHP environment. The `native:install` script is automatically registered as a `post-update-cmd` for future composer updates. ```sh composer update php artisan native:install ``` -------------------------------- ### Install Axios for Inertia 3 Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/development.md If using Inertia 3 with NativePHP, install axios as a direct dependency to handle client-side requests. ```shell npm install axios ``` -------------------------------- ### Create and Register Application Menu Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/application-menu.md Create and register a new application menu by passing predefined menu items as parameters to the `Menu::create()` method. This configuration should typically be done in the `boot` method of your `NativeAppServiceProvider`. ```php namespace App\Providers; use Native\Desktop\Facades\Menu; use Native\Desktop\Facades\Window; class NativeAppServiceProvider { public function boot(): void { Menu::create( Menu::app(), // Only on macOS Menu::file(), Menu::edit(), Menu::view(), Menu::window(), ); Window::open(); } } ``` -------------------------------- ### List Installed NativePHP Plugins Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/commands.md View all installed NativePHP plugins. Use the `--json` option for machine-readable output or `--all` to include unregistered plugins. ```shell php artisan native:plugin:list ``` -------------------------------- ### Advanced Window Instance Assertion Test Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/testing/windows.md This advanced example demonstrates how to mock a window instance to assert specific method calls like `route`, `transparent`, `height`, `width`, `minHeight`, and `minWidth`. This is useful for testing complex window configurations. ```php use Illuminate\Support\Facades\Http; use Native\Desktop\Facades\Window; use Native\Desktop\Windows\Window as WindowImplementation; use Mockery; #[ PHPUnit\Framework\Attributes\Test ] public function example(): void { Http::fake(); Window::fake(); Window::alwaysReturnWindows([ $mockWindow = Mockery::mock(WindowImplementation::class)->makePartial(), ]); $mockWindow->shouldReceive('route')->once()->with('action')->andReturnSelf(); $mockWindow->shouldReceive('transparent')->once()->andReturnSelf(); $mockWindow->shouldReceive('height')->once()->with(500)->andReturnSelf(); $mockWindow->shouldReceive('width')->once()->with(775)->andReturnSelf(); $mockWindow->shouldReceive('minHeight')->once()->with(500)->andReturnSelf(); $mockWindow->shouldReceive('minWidth')->once()->with(775)->andReturnSelf(); $this->get(route('action')); } ``` -------------------------------- ### Valid Flex Gap Spacing Example Source: https://github.com/nativephp/nativephp.com/blob/main/AGENTS.md Use gap utilities for spacing when listing items instead of margins. This example shows how to apply spacing between flex items. ```html
Superior
Michigan
Erie
``` -------------------------------- ### Use Default Application Menu Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/application-menu.md Utilize the `Menu::default()` method to quickly create a standard application menu that includes File, Edit, View, and Window items. ```php // Instead of... Menu::create( Menu::app(), Menu::file(), Menu::edit(), Menu::view(), Menu::window(), ); // You can just write... Menu::default(); ``` -------------------------------- ### Install NativePHP Composer Package Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/getting-started/installation.md Install the NativePHP desktop package using Composer. This command adds all necessary classes, commands, and interfaces for your application to work with the Electron runtime. ```shell composer require nativephp/desktop ``` -------------------------------- ### Import the App Facade Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/application.md To use the App facade, include this import statement at the top of your file. ```php use Native\Desktop\Facades\App; ``` -------------------------------- ### Flux UI Button Component Example Source: https://github.com/nativephp/nativephp.com/blob/main/AGENTS.md Example of using a primary variant Flux UI button component. Use Flux UI components when available for your Livewire application. ```blade ``` -------------------------------- ### Create New Laravel App with NativePHP Mobile Starter Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/quick-start.md Use this command to create a new Laravel application pre-configured with the NativePHP mobile starter kit. ```bash laravel new my-app --using=nativephp/mobile-starter cd my-app php artisan native:jump ``` -------------------------------- ### Start Vite Development Server Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/getting-started/development.md Run this command in a separate terminal session to start the Vite development server. This enables hot reloading for your application's assets when integrated with NativePHP. ```shell npm run dev ``` -------------------------------- ### Import Shell Facade Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/shell.md Include this statement at the top of your file to use the Shell facade. ```php use Native\Desktop\Facades\Shell; ``` -------------------------------- ### Build and Run App Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/commands.md Build and run your application on a device or simulator. Supports specifying the OS, UDID, build type, and watch mode. ```shell php artisan native:run {os?} {udid?} ``` -------------------------------- ### Get System Idle Time Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/power-monitor.md Retrieves the number of seconds the system has been idle. ```APIDOC ## Get System Idle Time ### Description Retrieves the number of seconds the system has been idle. ### Method ```php PowerMonitor::getSystemIdleTime() ``` ### Response - **int** - The number of seconds the system has been idle. ### Example ```php use Native\Desktop\Facades\PowerMonitor; $seconds = PowerMonitor::getSystemIdleTime(); ``` ``` -------------------------------- ### Import System Facade Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/system.md Import the System facade to access its methods for system-level operations. ```php use Native\Desktop\Facades\System; ``` -------------------------------- ### Get System Idle Time Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/power-monitor.md Retrieve the number of seconds the system has been idle. ```php use Native\Desktop\Facades\PowerMonitor; $seconds = PowerMonitor::getSystemIdleTime(); ``` -------------------------------- ### Run Release Build Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/deployment.md Builds your application with release optimizations, reducing size and improving performance. Test this build on a real device before submission. ```shell php artisan native:run --build=release ``` -------------------------------- ### Install NativePHP Composer Package Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/installation.md Use this command to add the NativePHP mobile package to your project. ```shell composer require nativephp/mobile ``` -------------------------------- ### Get current app version Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/application.md Retrieves the current version of the application, as defined in the `config/nativephp.php` file. ```APIDOC ## Current Version ### Description Retrieves the current application version defined in `config/nativephp.php`. ### Method GET ### Endpoint /app/version ### Response #### Success Response (200) - **version** (string) - The current application version. ### Code ```php $version = App::version(); ``` ``` -------------------------------- ### Open a New Window Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/windows.md Use the `Window::open()` method to create a new native application window. You can specify dimensions like width and height. The root URL of your application will be opened by default. ```php namespace App\Providers; use Native\Desktop\Facades\Window; class NativeAppServiceProvider { public function boot(): void { Window::open() ->width(800) ->height(800); } } ``` -------------------------------- ### Rebuild Application Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/plugins/using-plugins.md Rebuild your NativePHP application to compile the native code of newly installed or updated plugins. ```shell php artisan:run ``` -------------------------------- ### Get locale information Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/application.md Provides methods to access the application's locale and system localization settings. ```APIDOC ## Locale information ### Description Provides methods to access the application's locale, system country code, and system-wide locale settings. ### Methods - `getLocale()`: Returns the locale used by the app (e.g., "de", "fr-FR"). - `getLocaleCountryCode()`: Returns the user's system country code (e.g., "US", "DE"). Returns an empty string if detection fails. - `getSystemLocale()`: Returns the system-wide locale setting (e.g., "it-IT", "de-DE"). ### Endpoints - GET /app/locale - GET /app/locale/country-code - GET /app/locale/system ### Code ```php // Get app locale $locale = App::getLocale(); // Get system country code $countryCode = App::getLocaleCountryCode(); // Get system locale $systemLocale = App::getSystemLocale(); ``` ``` -------------------------------- ### Create a Basic Context Menu Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/application-menu.md Use the `Native.contextMenu()` method to define a simple context menu with a label and an accelerator. The `click` function executes when the menu item is selected. ```javascript Native.contextMenu([ { label: 'Edit', accelerator: 'e', click(menuItem, window, event) { // Code to execute when the menu item is clicked }, }, // Other options ]) ``` -------------------------------- ### Get Notification Reference Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/notifications.md Retrieve the reference property of a notification after it has been created. This is useful for tracking specific notifications. ```php $notification = Notification::title('Hello from NativePHP')->show(); $notification->reference; ``` -------------------------------- ### Open a File Dialog Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/dialogs.md Use the `Dialog::new()->open()` method to allow users to select a file or folder. The return value is the selected path(s) or null. ```php use Native\Desktop\Dialog; Dialog::new() ->title('Select a file') ->open(); ``` -------------------------------- ### Show Hidden Files Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/dialogs.md Include hidden files (starting with a dot) in the dialog by using the `withHiddenFiles()` method. ```php Dialog::new() ->withHiddenFiles() ->open(); ``` -------------------------------- ### Configure App ID in .env Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/installation.md Set your application's unique identifier in the .env file before running the installer. ```dotenv NATIVEPHP_APP_ID=com.yourcompany.yourapp ``` -------------------------------- ### Using the Default Menu Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/application-menu.md Simplify the creation of a standard application menu by using the `Menu::default()` method. This method includes the common File, Edit, View, and Window menus. ```APIDOC ## The Default menu You may use the `Menu::default()` method to create the default application menu. This menu contains all the items that you would expect in a typical application menu (File, Edit, View, Window): ```php // Instead of... Menu::create( Menu::app(), Menu::file(), Menu::edit(), Menu::view(), Menu::window(), ); // You can just write... Menu::default(); ``` ``` -------------------------------- ### Get Current Thermal State Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/power-monitor.md Retrieves the current thermal state of the system, returning an enum value of `ThermalStatesEnum`. ```APIDOC ## Get Current Thermal State ### Description Retrieves the current thermal state of the system, returning an enum value of `ThermalStatesEnum`. ### Method ```php PowerMonitor::getCurrentThermalState() ``` ### Response - **ThermalStatesEnum** - An enum value representing the current thermal state (e.g., `ThermalStatesEnum::NOMINAL`, `ThermalStatesEnum::FAIR`, `ThermalStatesEnum::SERIOUS`, `ThermalStatesEnum::CRITICAL`, `ThermalStatesEnum::UNKNOWN`). ### Example ```php use Native\Desktop\Enums\ThermalStatesEnum; use Native\Desktop\Facades\PowerMonitor; $thermalState = PowerMonitor::getCurrentThermalState(); if ($state === ThermalStatesEnum::CRITICAL) { // Wow, the CPU is running hot! } ``` ``` -------------------------------- ### Get Current Application Version Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/application.md Retrieve the application's version, which is defined in `config/nativephp.php`, using the `version` method. ```php $version = App::version(); ``` -------------------------------- ### Run All Tests with Compact Output Source: https://github.com/nativephp/nativephp.com/blob/main/AGENTS.md Execute the entire test suite with compact output for a concise summary. ```bash php artisan test --compact ``` -------------------------------- ### Get Current Thermal State Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/power-monitor.md Retrieve the current thermal state of the system. The returned value is an enum of ThermalStatesEnum. ```php use Native\Desktop\Enums\ThermalStatesEnum; use Native\Desktop\Facades\PowerMonitor; $thermalState = PowerMonitor::getCurrentThermalState(); if ($state === ThermalStatesEnum::CRITICAL) { // Wow, the CPU is running hot! } ``` -------------------------------- ### Get System Idle State Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/power-monitor.md Checks if the system is idle. It expects a threshold in seconds and returns an enum value of `SystemIdleStatesEnum`. ```APIDOC ## Get System Idle State ### Description Checks if the system is idle. It expects a threshold in seconds and returns an enum value of `SystemIdleStatesEnum`. ### Method ```php PowerMonitor::getSystemIdleState(int $threshold) ``` ### Parameters #### Path Parameters - **threshold** (int) - Required - The number of seconds the system must be idle before it is considered idle. ### Response - **SystemIdleStatesEnum** - An enum value representing the system's idle state (e.g., `SystemIdleStatesEnum::IDLE`, `SystemIdleStatesEnum::ACTIVE`, `SystemIdleStatesEnum::LOCKED`, `SystemIdleStatesEnum::UNKNOWN`). ### Example ```php use Native\Desktop\Enums\SystemIdleStatesEnum; use Native\Desktop\Facades\PowerMonitor; $state = PowerMonitor::getSystemIdleState(60); if ($state === SystemIdleStatesEnum::IDLE) { // The system is idle! } ``` ``` -------------------------------- ### Import Settings Facade Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/settings.md Import the Settings facade to access its methods for managing application settings. ```php use Native\Desktop\Facades\Settings; ``` -------------------------------- ### Get a Setting Value with Default Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/settings.md Provide a default value to be returned if the setting key does not exist. This can be a static value or a closure. ```php $value = Settings::get('key', 'default'); ``` ```php $value = Settings::get('key', function () { return 'default'; }); ``` -------------------------------- ### Managing Multiple Windows Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/windows.md Demonstrates how to open and manage multiple distinct windows by assigning unique identifiers. ```APIDOC ## Managing Multiple Windows If you would like to open multiple windows, you may use the `Window::open()` method multiple times. In order to distinguish between the individual windows, you may pass a unique identifier to the `open()` method. If you do not specify an ID, NativePHP will automatically use `main` as the ID. This ID can be used to reference the window in other methods, such as `Window::close()` or `Window::resize()`. ```php Window::open('home') ->width(800) ->height(800); Window::open('settings') ->route('settings') ->width(800) ->height(800); ``` ``` -------------------------------- ### Get a Setting Value Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/settings.md Retrieve a setting's value using its key. If the setting does not exist, `null` is returned by default. ```php $value = Settings::get('key'); ``` -------------------------------- ### Allow Multiple File Selections Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/dialogs.md Enable selecting multiple files by calling `multiple()`. The `open()` method will then return an array of file paths. ```php $files = Dialog::new() ->multiple() ->open(); ``` -------------------------------- ### Retrieving the Current Window Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/windows.md Gets the currently focused window object, providing details like its ID, title, dimensions, and position. ```APIDOC ### Retrieving the Current Window You may use the `Window::current()` method to retrieve the currently focused window. This method returns an object with the following properties: - `id`: The ID of the window. - `title`: The title of the window. - `width`: The width of the window. - `height`: The height of the window. - `x`: The x position of the window. - `y`: The y position of the window. - `alwaysOnTop`: Whether the window is always on top. ```php $currentWindow = Window::current(); ``` ``` -------------------------------- ### Import Clipboard Facade Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/clipboard.md Import the Clipboard facade to access its methods. This is typically done at the top of your PHP file. ```php use Native\Desktop\Facades\Clipboard; ``` -------------------------------- ### Get Locale Information Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/application.md Access system localization details like the app's locale, country code, and system-wide locale. ```php App::getLocale(); // e.g. "de", "fr-FR" App::getLocaleCountryCode(); // e.g. "US", "DE" App::getSystemLocale(); // e.g. "it-IT", "de-DE" ``` -------------------------------- ### Register a Specific Global Hotkey Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/global-hotkeys.md Use the `GlobalShortcut::key()` method to specify the hotkey combination and the `event()` method to link it to an application event. Call `register()` to activate it. ```php GlobalShortcut::key('Cmd+Shift+D') ->event(\App\Events\MyEvent::class) ->register(); ``` -------------------------------- ### Package App for Distribution Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/mobile/3/getting-started/commands.md Use this command to package your application for distribution. Specify the target platform (android/a or ios/i) and optionally configure build type, output directory, and versioning. ```shell php artisan native:package {platform} ``` -------------------------------- ### Get Cursor Position Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/the-basics/screens.md The `cursorPosition` method returns the current absolute coordinates (x, y) of the mouse cursor relative to the primary display. ```APIDOC ## GET Screen::cursorPosition() ### Description Retrieves the current absolute position of the mouse cursor. ### Method GET ### Endpoint Screen::cursorPosition() ### Response #### Success Response (200) - **position** (object) - An object with `x` and `y` properties representing the cursor's coordinates. ``` -------------------------------- ### Get All Running Processes Source: https://github.com/nativephp/nativephp.com/blob/main/resources/views/docs/desktop/2/digging-deeper/child-processes.md Retrieve an array of all currently running child process instances. Useful for monitoring or managing multiple processes. ```php $processes = ChildProcess::all(); ```