### Install wine for Linux cross-compilation Source: https://nativephp.com/docs/desktop/2/publishing/building Example commands to install 32-bit wine on Debian-based distributions to support Windows binary compilation. ```bash # Example installation of wine for Debian based distributions (Ubuntu) dpkg --add-architecture i386 apt-get -y update apt-get -y install wine32 ``` -------------------------------- ### Start a child process with custom environment variables Source: https://nativephp.com/docs/desktop/2/digging-deeper/child-processes Use the $env parameter in the start method to provide extra environment variables to the child process. ```php ChildProcess::start( cmd: 'tail ...', alias: 'tail', env: [ 'CUSTOM_ENV_VAR' => 'custom value', ] ); ``` -------------------------------- ### Retrieve all windows with Window::all Source: https://nativephp.com/docs/desktop/2/the-basics/windows Get a collection of all currently open windows. ```php foreach (Window::all() as $window) { $window->url(route('home')); } ``` -------------------------------- ### ChildProcess::start Source: https://nativephp.com/docs/desktop/2/digging-deeper/child-processes Starts a child process with a given command and alias. Returns a Native\Desktop\ChildProcess instance. The process may not start immediately; listen for the ProcessSpawned event to confirm. ```APIDOC ## ChildProcess::start ### Description Starts a child process with the given command and alias. Returns a Native\Desktop\ChildProcess instance representing the process. The process may not start immediately; listen for the ProcessSpawned event to confirm successful startup. ### Method start ### Parameters - **cmd** (string|array) - Required - The command to execute. Can be a string or an array of command parts. - **alias** (string) - Required - A unique alias to reference the process throughout the application. - **cwd** (string) - Optional - The current working directory for the process. Defaults to the application's working directory. - **persistent** (bool) - Optional - If true, the runtime will ensure the process is always running, restarting it if it crashes. ### Request Example ```php use Native\Desktop\Facades\ChildProcess; ChildProcess::start( cmd: 'tail -f storage/logs/laravel.log', alias: 'tail' ); ``` ### Response Returns a Native\Desktop\ChildProcess instance. The process may not be started yet; listen for the ProcessSpawned event to determine if it started successfully. ``` -------------------------------- ### Start a child process with ChildProcess::start Source: https://nativephp.com/docs/desktop/2/digging-deeper/child-processes Initiates a new child process by providing a command string and a unique alias. ```php use Native\Desktop\Facades\ChildProcess; ChildProcess::start( cmd: 'tail -f storage/logs/laravel.log', alias: 'tail' ); ``` -------------------------------- ### Quit and install an update Source: https://nativephp.com/docs/desktop/2/publishing/updating Call quitAndInstall to immediately apply a downloaded update by restarting the application. ```php use Native\Desktop\Facades\AutoUpdater; AutoUpdater::quitAndInstall(); ``` -------------------------------- ### Custom Page Size and Orientation Settings Source: https://nativephp.com/docs/desktop/2/the-basics/system Example of configuring page size and orientation settings for a print job. ```php // Print with custom page size and orientation $settings = [ 'pageSize' => 'A4', 'landscape' => true, ]; System::print('...', $printer, $settings); ``` -------------------------------- ### AutoUpdater::quitAndInstall() Source: https://nativephp.com/docs/desktop/2/publishing/updating Quits the application and installs the downloaded update. The application will relaunch automatically after installation. ```APIDOC ## AutoUpdater::quitAndInstall() ### Description Quits the application and installs the downloaded update. The application will relaunch automatically. ### Method quitAndInstall ### Signature AutoUpdater::quitAndInstall() ### Parameters None ### Return Value None ### Example ```php use Native\Desktop\Facades\AutoUpdater; AutoUpdater::quitAndInstall(); ``` ### Notes Calling this method is optional - any successfully downloaded update will be applied the next time the application starts. ``` -------------------------------- ### Multi-copy and Duplex Print Settings Source: https://nativephp.com/docs/desktop/2/the-basics/system Example of configuring multiple copies, duplex mode, and color settings. ```php // Print multiple copies with duplex $settings = [ 'copies' => 3, 'duplexMode' => 'longEdge', // 'simplex', 'shortEdge', 'longEdge' 'color' => false, // true for color, false for monochrome ]; System::print('...', $printer, $settings); ``` -------------------------------- ### Start a Child Process with ChildProcess::start Source: https://nativephp.com/docs/desktop/2/digging-deeper/child-processes Spawns a non-blocking background process using the specified command and an alias for management. ```php ChildProcess::start( cmd: 'tail -f storage/logs/laravel.log', alias: 'tail' ); ``` -------------------------------- ### Start a child process with command line arguments Source: https://nativephp.com/docs/desktop/2/digging-deeper/child-processes Pass arguments to the program using the $cmd parameter, which accepts either a string or an array. ```php ChildProcess::start( cmd: ['tail', '-f', 'storage/logs/laravel.log'], alias: 'tail' ); ``` -------------------------------- ### Update package and install Source: https://nativephp.com/docs/desktop/2/getting-started/upgrade-guide Run these commands to update your dependencies and install the new NativePHP package. ```sh composer update php artisan native:install ``` -------------------------------- ### Menu Bar Icon File Naming Source: https://nativephp.com/docs/desktop/2/the-basics/menu-bar Example of standard icon file naming conventions for regular and retina displays. ```text menuBarIcon.png menuBarIcon@2x.png ``` -------------------------------- ### Run development server with native:run Source: https://nativephp.com/docs/desktop/2/getting-started/commands Starts the NativePHP development server to build and run your Electron app locally. ```shell php artisan native:run ``` -------------------------------- ### Start Vite development server Source: https://nativephp.com/docs/desktop/2/getting-started/development Run this in a separate terminal session alongside the native:run command to enable hot reloading for your application. ```shell npm run dev ``` -------------------------------- ### Import App facade Source: https://nativephp.com/docs/desktop/2/the-basics/application Include this statement at the top of your file to use the App facade. ```php use Native\Desktop\Facades\App; ``` -------------------------------- ### Install NativePHP with native:install Source: https://nativephp.com/docs/desktop/2/getting-started/commands Installs NativePHP into your Laravel application. ```shell php artisan native:install ``` -------------------------------- ### Open a window with Window::open Source: https://nativephp.com/docs/desktop/2/the-basics/windows Use the Window facade to open a new window, optionally chaining width and height methods. ```php namespace App\Providers; use Native\Desktop\Facades\Window; class NativeAppServiceProvider { public function boot(): void { Window::open() ->width(800) ->height(800); } } ``` -------------------------------- ### Install NativePHP via Composer Source: https://nativephp.com/docs/desktop/2/getting-started/installation Install the nativephp/desktop package into your Laravel application. ```shell composer require nativephp/desktop ``` -------------------------------- ### Get a setting value Source: https://nativephp.com/docs/desktop/2/the-basics/settings Retrieve a stored setting using the get method. ```php $value = Settings::get('key'); ``` -------------------------------- ### Import Clipboard Facade Source: https://nativephp.com/docs/desktop/2/the-basics/clipboard Import the Clipboard facade to begin using clipboard functionality. ```php use Native\Desktop\Facades\Clipboard; ``` -------------------------------- ### Import Settings Facade Source: https://nativephp.com/docs/desktop/2/the-basics/settings Import the Settings facade to begin managing application settings. ```php use Native\Desktop\Facades\Settings; ``` -------------------------------- ### Configure NSIS installer Source: https://nativephp.com/docs/desktop/2/getting-started/configuration Sets options for the NSIS installer used in Windows builds, such as deleting app data on uninstall. ```php /** * The NSIS installer configuration for Windows builds. * * @see https://www.electron.build/generated/nsisoptions */ 'nsis' => [ 'delete_app_data_on_uninstall' => env('NATIVEPHP_NSIS_DELETE_APP_DATA', false), ], ``` -------------------------------- ### Enable open at login (macOS and Windows) Source: https://nativephp.com/docs/desktop/2/the-basics/application Enable the application to launch automatically at login. ```php App::openAtLogin(true); ``` -------------------------------- ### Get a single process by alias Source: https://nativephp.com/docs/desktop/2/digging-deeper/child-processes Use the ChildProcess facade's get method to retrieve a specific running process instance. ```php $tail = ChildProcess::get('tail'); ``` -------------------------------- ### Build the application Source: https://nativephp.com/docs/desktop/2/publishing/building Run the artisan command to build the application for the current platform and architecture. ```shell php artisan native:build ``` -------------------------------- ### PowerMonitor::getSystemIdleTime Source: https://nativephp.com/docs/desktop/2/the-basics/power-monitor Gets the number of seconds the system has been idle. Returns an integer. ```APIDOC ## PowerMonitor::getSystemIdleTime ### Description Gets the number of seconds the system has been idle. Returns an integer. ### Method PowerMonitor::getSystemIdleTime ### Parameters None ### Return Value Returns an integer representing the number of seconds the system has been idle. ### Example ```php use Native\Desktop\Facades\PowerMonitor; $seconds = PowerMonitor::getSystemIdleTime(); ``` ``` -------------------------------- ### Get current app version Source: https://nativephp.com/docs/desktop/2/the-basics/application Retrieve the version defined in the config/nativephp.php file. ```php $version = App::version(); ``` -------------------------------- ### PowerMonitor::getCurrentThermalState Source: https://nativephp.com/docs/desktop/2/the-basics/power-monitor Gets the current thermal state of the system. Returns a ThermalStatesEnum value. ```APIDOC ## PowerMonitor::getCurrentThermalState ### Description Gets the current thermal state of the system. Returns a ThermalStatesEnum value. ### Method PowerMonitor::getCurrentThermalState ### Parameters None ### Return Value Returns an enum value of `ThermalStatesEnum`. ### Possible Enum Values - `ThermalStatesEnum::UNKNOWN` - `ThermalStatesEnum::NOMINAL` - `ThermalStatesEnum::FAIR` - `ThermalStatesEnum::SERIOUS` - `ThermalStatesEnum::CRITICAL` ### 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! } ``` ``` -------------------------------- ### App::version() Source: https://nativephp.com/docs/desktop/2/the-basics/application Gets the current app version. The version is defined in the config/nativephp.php file. ```APIDOC ## App::version() ### Description Gets the current app version. The version is defined in the config/nativephp.php file. ### Method version ### Parameters None ### Returns - **string** - The current app version. ### Example ```php $version = App::version(); ``` ``` -------------------------------- ### Import Screen facade Source: https://nativephp.com/docs/desktop/2/the-basics/screens Import the Screen facade to access display and cursor information. ```php use Native\Desktop\Facades\Screen; ``` -------------------------------- ### Retrieve current window with Window::current Source: https://nativephp.com/docs/desktop/2/the-basics/windows Get an object containing properties of the currently focused window. ```php $currentWindow = Window::current(); ``` -------------------------------- ### Window::open()->width() and height() Source: https://nativephp.com/docs/desktop/2/the-basics/windows Sets the width and height of the window. ```APIDOC ## Window::open()->width() and height() ### Description Sets the width and height of the window. ### Method Window::open()->width() and height() ### Parameters - **width** (int) - Required - The width of the window. - **height** (int) - Required - The height of the window. ### Usage Example ```php Window::open() ->width(800) ->height(800); ``` ``` -------------------------------- ### Get a setting with a closure default Source: https://nativephp.com/docs/desktop/2/the-basics/settings Provide a closure as a default value to return if the setting key does not exist. ```php $value = Settings::get('key', function () { return 'default'; }); ``` -------------------------------- ### Get a setting with a static default Source: https://nativephp.com/docs/desktop/2/the-basics/settings Provide a static default value to return if the setting key does not exist. ```php $value = Settings::get('key', 'default'); ``` -------------------------------- ### Mock window instance with Window::alwaysReturnWindows Source: https://nativephp.com/docs/desktop/2/testing/windows Use Window::alwaysReturnWindows to inject a Mockery mock of the WindowImplementation for advanced assertions on window properties. ```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')); } ``` -------------------------------- ### Import Alert Facade Source: https://nativephp.com/docs/desktop/2/the-basics/alerts Import the Alert facade to begin using native alerts in your application. ```php use Native\Desktop\Facades\Alert; ``` -------------------------------- ### Get System Idle Time Source: https://nativephp.com/docs/desktop/2/the-basics/power-monitor Retrieve the number of seconds the system has been idle using the getSystemIdleTime method. ```php use Native\Desktop\Facades\PowerMonitor; $seconds = PowerMonitor::getSystemIdleTime(); ``` -------------------------------- ### Define prebuild and postbuild scripts Source: https://nativephp.com/docs/desktop/2/getting-started/configuration Specifies shell commands to execute before and after the application build process. ```php /** * Define your own scripts to run before and after the build process. */ 'prebuild' => [ // 'npm run build', ], 'postbuild' => [ // 'rm -rf public/build', ], ``` -------------------------------- ### Retrieve displays information Source: https://nativephp.com/docs/desktop/2/the-basics/screens Use the displays method to get an array of information about all active physical displays. ```php $screens = Screen::displays(); [ 0 => [ 'bounds' => [ 'x' => 0, 'y' => 0, 'width' => 2560, 'height' => 1440, ], 'detected' => true, 'id' => 2026675401, 'internal' => false, 'label' => 'U3277WB', 'size' => [ 'width' => 2560, 'height' => 1440, ], 'workArea' => [ 'x' => 0, 'y' => 25, 'width' => 2560, 'height' => 1345, ], // ... ], // ... ] ``` -------------------------------- ### Creating a custom application menu Source: https://nativephp.com/docs/desktop/2/the-basics/application-menu Define the application menu structure within the boot method of the NativeAppServiceProvider using Menu::create. ```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(); } } ``` -------------------------------- ### Get all running processes Source: https://nativephp.com/docs/desktop/2/digging-deeper/child-processes Use the ChildProcess facade's all method to retrieve an array of all active process instances. ```php $processes = ChildProcess::all(); ``` -------------------------------- ### Using the default application menu Source: https://nativephp.com/docs/desktop/2/the-basics/application-menu The Menu::default() method provides a standard set of menu items including File, Edit, View, and Window. ```php // Instead of... Menu::create( Menu::app(), Menu::file(), Menu::edit(), Menu::view(), Menu::window(), ); // You can just write... Menu::default(); ``` -------------------------------- ### Import Dialog facade Source: https://nativephp.com/docs/desktop/2/the-basics/dialogs Import the Dialog facade from the Native\Desktop namespace. ```php use Native\Desktop\Dialog; ``` -------------------------------- ### Import System facade Source: https://nativephp.com/docs/desktop/2/the-basics/system Import the System facade to access system-related features in your application. ```php use Native\Desktop\Facades\System; ``` -------------------------------- ### Get Current Thermal State Source: https://nativephp.com/docs/desktop/2/the-basics/power-monitor Use the getCurrentThermalState method to retrieve the current thermal state of the system as a ThermalStatesEnum value. ```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 app badge count (macOS and Linux) Source: https://nativephp.com/docs/desktop/2/the-basics/application Retrieve the current badge count by calling the method without arguments. ```php $badgeCount = App::badgeCount(); ``` -------------------------------- ### Set Window Dimensions Source: https://nativephp.com/docs/desktop/2/the-basics/windows Use width() and height() to define the initial window size. ```php Window::open() ->width(800) ->height(800); ``` -------------------------------- ### Run native:publish command Source: https://nativephp.com/docs/desktop/2/publishing/publishing Executes the build process for the current platform and architecture. Ensure the application version is updated in the .env file before running. ```shell php artisan native:publish ``` -------------------------------- ### Configure Web Preferences Source: https://nativephp.com/docs/desktop/2/the-basics/windows Pass a webPreferences configuration array to customize Electron window behavior and features. ```php Window::open() ->webPreferences([ 'nodeIntegration' => true, 'spellcheck' => true, 'backgroundThrottling' => true, ]); ``` -------------------------------- ### Import Shell facade Source: https://nativephp.com/docs/desktop/2/the-basics/shell Add this statement to the top of your file to use the Shell facade. ```php use Native\Desktop\Facades\Shell; ``` -------------------------------- ### Window::open()->fullscreen() Source: https://nativephp.com/docs/desktop/2/the-basics/windows Opens the window in full screen mode. ```APIDOC ## Window::open()->fullscreen() ### Description Opens the window in full screen mode. ### Method Window::open()->fullscreen() ### Usage Example ```php Window::open()->fullscreen(); ``` ``` -------------------------------- ### Get cursor position Source: https://nativephp.com/docs/desktop/2/the-basics/screens Use the cursorPosition method to retrieve the current absolute coordinates of the mouse cursor relative to the primary display. ```php $position = Screen::cursorPosition(); (object) [ 'x' => 627, 'y' => 168, ] ``` -------------------------------- ### System::printers() Source: https://nativephp.com/docs/desktop/2/the-basics/system List all available printers. Each printer is a \Native\Desktop\DataObjects\Printer object containing device details and default configuration. ```APIDOC ## System::printers() ### Description List all available printers. Each printer is a \Native\Desktop\DataObjects\Printer object containing device details and default configuration. ### Method System::printers() - array of Printer objects ### Response #### Success Response - Returns an array of Printer objects. Each Printer has a displayName property. ``` -------------------------------- ### Show hidden files in dialog Source: https://nativephp.com/docs/desktop/2/the-basics/dialogs Changes the dialog to show hidden files (files starting with a dot) using the withHiddenFiles() method. ```php Dialog::new() ->withHiddenFiles() ->open(); ``` -------------------------------- ### Shell::fake() and Shell::assertOpenedExternal() Source: https://nativephp.com/docs/desktop/2/testing/shell Example test case demonstrating how to fake the Shell facade and assert that an external URL was opened. ```APIDOC ## Shell::fake() ### Description Fakes the Shell facade so that no real shell operations are performed during tests. ### Method fake() ### Parameters None ### Return Value None ## Shell::assertOpenedExternal() ### Description Asserts that the Shell facade was called to open an external URL. ### Method assertOpenedExternal(string $url) ### Parameters - **$url** (string) - Required - The external URL that should have been opened. ### Return Value None ### Example ```php Shell::fake(); $this->get('/whatever-action'); Shell::assertOpenedExternal('https://some-url.test'); ``` ``` -------------------------------- ### System::printFile() Source: https://nativephp.com/docs/desktop/2/the-basics/system Print an existing file, such as a PDF. Accepts the same printer and settings arguments as print(). ```APIDOC ## System::printFile() ### Description Print an existing file, such as a PDF. Accepts the same printer and settings arguments as print(). ### Method System::printFile(string $filePath, Printer $printer = null, array $settings = []) ### Parameters #### Parameters - **$filePath** (string) - Required - The path to the file to print. - **$printer** (Printer) - Optional - The printer object to use. If omitted, the default printer is used. - **$settings** (array) - Optional - Print settings to customize behavior. ### Request Example ```php System::printFile('/path/to/file.pdf', $printer); ``` ### Response #### Success Response - Returns true once the file has been sent to the printer. ``` -------------------------------- ### Build for a specific platform Source: https://nativephp.com/docs/desktop/2/publishing/building Specify the target operating system using the os argument. Supported options are mac, win, and linux. ```shell php artisan native:build win ``` -------------------------------- ### Print Existing Files Source: https://nativephp.com/docs/desktop/2/the-basics/system Use System::printFile to send files like PDFs to a printer. ```php System::printFile('/path/to/file.pdf', $printer); ``` -------------------------------- ### Menu Bar Template Icon File Naming Source: https://nativephp.com/docs/desktop/2/the-basics/menu-bar Example of template icon file naming conventions for automatic macOS template image conversion. ```text menuBarIconTemplate.png menuBarIconTemplate@2x.png ``` -------------------------------- ### Resize windows with Window::resize Source: https://nativephp.com/docs/desktop/2/the-basics/windows Resize a window by specifying width and height, optionally providing a window ID. ```php Window::resize(400, 300); Window::resize(400, 300, 'settings'); ``` -------------------------------- ### Default NativeAppServiceProvider implementation Source: https://nativephp.com/docs/desktop/2/the-basics/app-lifecycle The default service provider generated by native:install, used to bootstrap the application via the boot method and configure php.ini 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 [ ]; } } ``` -------------------------------- ### Seed the database Source: https://nativephp.com/docs/desktop/2/digging-deeper/databases Use this command to run database seeders and populate the development database with sample data. ```shell php artisan native:seed ``` -------------------------------- ### Manage queue workers with QueueWorker facade Source: https://nativephp.com/docs/desktop/2/digging-deeper/queues Use the QueueWorker facade to manually start or stop workers using a QueueConfig object or a pre-defined configuration alias. ```php use Native\DTOs\QueueConfig; use Native\Desktop\Facades\QueueWorker; $queueConfig = new QueueConfig(alias: 'manual', queuesToConsume: ['default'], memoryLimit: 1024, timeout: 600, sleep: 5); QueueWorker::up($queueConfig); // Alternatively, if you already have the worker config in your config/nativephp.php file, you may simply use its alias: QueueWorker::up(config: 'manual'); // Later... QueueWorker::down(alias: 'manual'); ``` -------------------------------- ### Registering a specific global shortcut Source: https://nativephp.com/docs/desktop/2/the-basics/global-hotkeys Use the GlobalShortcut facade to listen for specific key combinations and trigger a corresponding event. ```php GlobalShortcut::key('Cmd+Shift+D') ->event(\App\Events\MyEvent::class) ->register(); ``` -------------------------------- ### App::badgeCount() Source: https://nativephp.com/docs/desktop/2/the-basics/application Sets, removes, or gets the app's badge count. On macOS, it shows on the dock icon. On Linux, it only works for Unity launcher. Only available on macOS and Linux. ```APIDOC ## App::badgeCount() ### Description Sets, removes, or gets the app's badge count. On macOS, it shows on the dock icon. On Linux, it only works for Unity launcher. Only available on macOS and Linux. ### Method badgeCount ### Parameters - **count** (int) - Optional - The badge count to set. If 0, removes the badge. If omitted, returns the current badge count. ### Returns - **int** - The current badge count when called without arguments. ### Examples ```php App::badgeCount(5); App::badgeCount(0); $badgeCount = App::badgeCount(); ``` ``` -------------------------------- ### Test queue worker with QueueWorker::fake Source: https://nativephp.com/docs/desktop/2/testing/queue-worker Use QueueWorker::fake() to intercept queue worker calls during testing. The assertUp method verifies that the worker was started with the expected configuration. ```php use Native\Desktop\Facades\QueueWorker; use Native\Desktop\DTOs\QueueConfig; #["PHPUnit\\Framework\\Attributes\\Test"] public function example(): void { QueueWorker::fake(); $this->get('/whatever-action'); QueueWorker::assertUp(fn (QueueConfig $config) => $config->alias === 'custom'); } ``` -------------------------------- ### Accessing Bundled Files with Storage Facade Source: https://nativephp.com/docs/desktop/2/digging-deeper/files Use the Storage facade with the extras disk to retrieve the path to a bundled file. ```php use Illuminate\Support\Facades\Storage; $toolPath = Storage::disk('extras')->path('my-tool.exe'); ``` -------------------------------- ### Get the current system time zone Source: https://nativephp.com/docs/desktop/2/the-basics/system Retrieves the user's operating system time zone as a PHP-compatible identifier. This mechanism uses an approximation and may not always match the exact time zone. ```php $timezone = System::timezone(); // $timezone => 'Europe/London' ``` -------------------------------- ### Executing Bundled Tools with ChildProcess Source: https://nativephp.com/docs/desktop/2/digging-deeper/files Retrieve the path to a bundled executable and run it using the ChildProcess facade. ```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' ); ``` -------------------------------- ### Show a custom context menu on event listener Source: https://nativephp.com/docs/desktop/2/the-basics/application-menu This example shows how to listen for the contextmenu event on a specific DOM element, prevent the default browser menu, and trigger a custom NativePHP context menu. ```js const element = document.getElementById('your-element') element.addEventListener('contextmenu', (event) => { event.preventDefault() Native.contextMenu([ { label: 'Duplicate', accelerator: 'd', click() { duplicateEntry(element.dataset.id) }, }, { label: 'Edit', accelerator: 'e', click() { showEditForm(element.dataset.id) }, }, { label: 'Delete', click() { if (confirm('Are you sure you want to delete this entry?')) { deleteEntry(element.dataset.id) } }, }, ]) }) ``` -------------------------------- ### Create Default App Menu Source: https://nativephp.com/docs/desktop/2/the-basics/application-menu Use the Menu::app() method to create the default application menu, which is available only on macOS. ```php Menu::create( Menu::app(), ); ``` -------------------------------- ### Run migrations in development Source: https://nativephp.com/docs/desktop/2/digging-deeper/databases Use this command to manually migrate the development database. ```shell php artisan native:migrate ``` -------------------------------- ### Show file in folder Source: https://nativephp.com/docs/desktop/2/the-basics/shell The showInFolder method opens the specified path in the user's default file manager. ```php Shell::showInFolder($path); ``` -------------------------------- ### Window::open()->webPreferences() Source: https://nativephp.com/docs/desktop/2/the-basics/windows Sets web preferences for the Electron window, customizing behavior and available features. ```APIDOC ## Window::open()->webPreferences() ### Description Controls various web page features by passing an optional `webPreferences` configuration array. This allows customization of how the Electron window behaves and what features are available to the web content. ### Method `webPreferences(array $options)` ### Parameters - **options** (array) - Required - Configuration array for web preferences. ### Usage Example ```php Window::open() ->webPreferences([ 'nodeIntegration' => true, 'spellcheck' => true, 'backgroundThrottling' => true, ]); ``` ### Default Settings NativePHP sets the following defaults for security and compatibility: ```php [ 'sandbox' => false, // locked 'preload' => '{preload-path}', // locked 'contextIsolation' => true, // locked 'spellcheck' => false, 'nodeIntegration' => false, 'backgroundThrottling' => false, ] ``` ### Notes - The `preload`, `contextIsolation`, and `sandbox` options are locked and cannot be changed for security reasons. - All other options from the Electron WebPreferences documentation may be passed and will override the defaults. ``` -------------------------------- ### App::relaunch() Source: https://nativephp.com/docs/desktop/2/the-basics/application Relaunches the application. This will quit the app and relaunch it. ```APIDOC ## App::relaunch() ### Description Relaunches the application. This will quit the app and relaunch it. ### Method relaunch ### Parameters None ### Example ```php App::relaunch(); ``` ``` -------------------------------- ### Create a custom submenu with Menu::make() Source: https://nativephp.com/docs/desktop/2/the-basics/application-menu Builds a custom menu using Menu::make() and nests it within the main application menu as a submenu with a custom label. Menu instances are also MenuItems, allowing this nesting. ```php Menu::create( Menu::app(), Menu::make( Menu::link('https://nativephp.com', 'Documentation'), )->label('My Submenu') ); ``` -------------------------------- ### Relaunch the app Source: https://nativephp.com/docs/desktop/2/the-basics/application Use the relaunch method to quit and immediately restart the application. ```php App::relaunch(); ``` -------------------------------- ### Open Window in Full Screen Source: https://nativephp.com/docs/desktop/2/the-basics/windows Use the fullscreen() method to open the window in full screen mode. ```php Window::open()->fullscreen(); ``` -------------------------------- ### Test window states with Window::fake Source: https://nativephp.com/docs/desktop/2/testing/windows Use Window::fake to mock window behavior and verify states like opened, closed, or hidden during a test. ```php use Native\Desktop\Facades\Window; use Illuminate\Support\Facades\Http; #[\PHPUnit\Framework\Attributes\Test] public function example(): void { Http::fake(); Window::fake(); $this->get('/whatever-action'); Window::assertOpened(fn (string $windowId) => Str::startsWith($windowId, ['window-name'])); Window::assertClosed('window-name'); Window::assertHidden('window-name'); } ``` -------------------------------- ### Configure Window URL Source: https://nativephp.com/docs/desktop/2/the-basics/windows Use the url() method to open an absolute URL in a window. ```php Window::open() ->url('https://google.com'); ``` -------------------------------- ### Apply Print Settings Source: https://nativephp.com/docs/desktop/2/the-basics/system Pass an optional settings array to print() or printToPDF() to customize behavior. ```php System::print('...', $printer, $settings); ``` -------------------------------- ### Define hotkeys via parameter or chainable method Source: https://nativephp.com/docs/desktop/2/the-basics/application-menu Shows two equivalent ways to set a hotkey on a menu item: using the hotkey named parameter in the Menu facade method, or using the chainable hotkey() method. ```php Menu::label('Quick search', hotkey: 'Ctrl+K'); // Or Menu::label('Quick search')->hotkey('Ctrl+K'); ``` -------------------------------- ### Window::open() Source: https://nativephp.com/docs/desktop/2/the-basics/windows Opens a new native application window. Accepts an optional unique identifier and can be chained with methods like width(), height(), minimized(), and maximized(). ```APIDOC ## Window::open() ### Description Opens a new native application window. If no ID is provided, the default ID is 'main'. The window will load the root URL of the application. ### Method open() ### Parameters - **id** (string) - Optional - Unique identifier for the window. Defaults to 'main'. ### Chained Methods - **width(int)** - Sets the window width. - **height(int)** - Sets the window height. - **minimized()** - Opens the window minimized. - **maximized()** - Opens the window maximized. ### Example ```php Window::open() ->width(800) ->height(800); ``` ### Response No return value specified. ``` -------------------------------- ### Focus the app Source: https://nativephp.com/docs/desktop/2/the-basics/application Use the focus method to bring the application to the foreground. ```php App::focus(); ```