### Example: Getting and Using the Current Window Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Demonstrates how to get the current window instance and access its ID. ```php $current = Window::current(); echo $current->getId(); // 'main' ``` -------------------------------- ### Example: Managing Background Tasks Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/process.md Demonstrates starting a persistent queue worker, monitoring its status, and stopping it using the ChildProcess facade. ```php use Native\Desktop\Facades\ChildProcess; // Start a long-running task ChildProcess::artisan( 'queue:work --queue=exports', 'queue_worker', persistent: true ); // Monitor the process $process = ChildProcess::get('queue_worker'); if ($process) { echo "Worker running with PID {$process->pid}"; } // Stop when done ChildProcess::stop('queue_worker'); ``` -------------------------------- ### Power Management Example Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/power-monitor.md An example demonstrating how to use PowerMonitor to manage power saving modes, auto-lock based on inactivity, and throttle operations due to thermal state. ```php use Native\Desktop\Facades\PowerMonitor; use Native\Desktop\Enums\{SystemIdleStatesEnum, ThermalStatesEnum}; // Monitor power state if (PowerMonitor::isOnBatteryPower()) { // Enable battery saver mode echo 'Switched to battery saver mode'; } // Check idle time $idleTime = PowerMonitor::getSystemIdleTime(); if ($idleTime > 300) { // Auto-lock after 5 minutes echo 'System locked due to inactivity'; } // Monitor thermal state $thermalState = PowerMonitor::getCurrentThermalState(); if ($thermalState === ThermalStatesEnum::CRITICAL) { // Pause CPU-intensive operations echo 'Pausing heavy operations due to thermal state'; } ``` -------------------------------- ### Create and Manage Progress Bar Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/ui-components.md This example demonstrates how to create, start, advance, and finish a progress bar. It's useful for indicating the progress of long-running tasks. ```php use Native\Desktop\ProgressBar; $progress = ProgressBar::create(100); $progress->start(); for ($i = 0; $i < 100; $i++) { // Do work $progress->advance(); } $progress->finish(); ``` -------------------------------- ### Complete Application Menu Example Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/menu.md This comprehensive example demonstrates building a multi-level application menu with file, view, and help submenus, including accelerators, checkboxes, and external links. It utilizes various menu item types and the `Menu::make()->register()` pattern. ```php use Native\Desktop\Facades\Menu; use Native\Desktop\Menu\Items\{Link, Separator, Checkbox}; Menu::make( Link::new('#', 'File')->submenu( Link::new('/new', 'New') ->accelerator('CmdOrCtrl+N'), Link::new('/open', 'Open') ->accelerator('CmdOrCtrl+O'), Separator::new(), Link::new('/exit', 'Exit') ->accelerator('CmdOrCtrl+Q') ), Link::new('#', 'View')->submenu( Checkbox::new('Show Sidebar') ->id('sidebar') ->checked(true), Separator::new(), Link::new('/fullscreen', 'Fullscreen') ->accelerator('F11') ), Link::new('#', 'Help')->submenu( Link::new('https://docs.example.com', 'Documentation') ->openInBrowser(true), Link::new('https://example.com/support', 'Support') ->openInBrowser(true) ) )->register(); ``` -------------------------------- ### Get and Set Application Theme Source: https://github.com/nativephp/desktop/blob/main/_autodocs/types.md Demonstrates how to get the current application theme and set it to light mode. Requires importing System facade and SystemThemesEnum. ```php use Native\Desktop\Facades\System; use Native\Desktop\Enums\SystemThemesEnum; $theme = System::theme(); if ($theme === SystemThemesEnum::DARK) { echo 'Dark mode enabled'; } System::theme(SystemThemesEnum::LIGHT); ``` -------------------------------- ### Example: Registering a Callback After Window Opens Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Demonstrates how to use the `afterOpen` method to focus the window after it has been initialized. ```php Window::open('main') ->afterOpen(function($window) { Window::focus(); }); ``` -------------------------------- ### Install Update Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-features.md Use the AutoUpdater facade to install a previously downloaded update. This method will quit the application and then proceed with the installation and restart. ```php AutoUpdater::quitAndInstall(); // Quits app and installs update ``` -------------------------------- ### Get or Set App Open At Login Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/app.md Use this method to get the current setting for whether the application launches at system login, or to set this preference. Pass `true` to enable, `false` to disable, or `null` to retrieve the current setting. ```php App::openAtLogin(); App::openAtLogin(true); App::openAtLogin(false); ``` -------------------------------- ### Example: Opening a Configured Window Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Shows how to open a secondary window with a specific ID, URL, and dimensions using the `Window` facade. ```php use Native\Desktop\Facades\Window; Window::open('secondary') ->url('/page') ->width(800) ->height(600); ``` -------------------------------- ### Usage Examples Source: https://github.com/nativephp/desktop/blob/main/_autodocs/README.md Demonstrates practical usage of the NativePHP Desktop library, including creating windows and registering menus. ```APIDOC ## Usage Examples ### Creating a Window ```php use Native\Desktop\Facades\Window; Window::open('main') ->title('My App') ->url('/dashboard') ->width(1200) ->height(800) ->rememberState(); ``` ### Registering a Menu ```php use Native\Desktop\Facades\Menu; use Native\Desktop\Menu\Items\Link; Menu::make( Link::new('/new', 'New') ->accelerator('CmdOrCtrl+N'), Link::new('/open', 'Open') ->accelerator('CmdOrCtrl+O'), )->register(); ``` ``` -------------------------------- ### Start Queue Worker Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-features.md Starts a queue worker process. Can be configured using an alias from configuration or a custom `QueueConfig` object. ```php use Native\Desktop\Facades\QueueWorker; use Native\Desktop\QueueConfig; // Start queue worker from config QueueWorker::up('default'); // Start with custom config QueueWorker::up( new QueueConfig( alias: 'exports', queuesToConsume: ['exports', 'notifications'], memoryLimit: 256, timeout: 120, sleep: 3 ) ); ``` -------------------------------- ### Get Fresh Process Information Snapshot Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/process.md Obtain a current snapshot of process details including platform, architecture, and uptime. This is useful for getting all relevant process info at once. ```PHP $info = Process::fresh(); echo "{$info->platform} - {$info->arch}"; ``` -------------------------------- ### Initialize Progress Bar Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/ui-components.md Starts the progress bar display. Call this before advancing or finishing. ```php public function start(): void ``` -------------------------------- ### MenuBar::create() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/ui-components.md Creates a new menu bar instance. This is the starting point for configuring and displaying a menu bar. ```APIDOC ## MenuBar::create() ### Description Creates a new menu bar. This method initiates the process of creating and configuring a menu bar. ### Method `static function create(): PendingCreateMenuBar` ### Return Type `PendingCreateMenuBar` — Allows for further configuration before the menu bar is automatically created. ### Example ```php use Native\Desktop\Facades\MenuBar; MenuBar::create() ->url('/menu-bar') ->width(400) ->height(500) ->icon(resource_path('icons/menu-bar.png')); ``` ``` -------------------------------- ### Event Dispatch Examples Source: https://github.com/nativephp/desktop/blob/main/_autodocs/endpoints.md Illustrates how to dispatch events from the native app, both for specific event classes and string identifiers. ```php // Native app sends: POST _native/api/events { "event": "App\/Events\/WindowClosed", "payload": { "windowId": "main" } } // Laravel receives: event(new App\/Events\/WindowClosed("main")); // Or for string events: POST _native/api/events { "event": "my-custom-event", "payload": { "data": "value" } } // Laravel receives: event("my-custom-event", ["data" => "value"]); ``` -------------------------------- ### theme() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-interaction.md Gets or sets the system theme preference. Accepts 'SYSTEM', 'LIGHT', or 'DARK' themes. ```APIDOC ## theme() ### Description Gets or sets the system theme preference. ### Method `public function theme(?SystemThemesEnum $theme = null): SystemThemesEnum` ### Parameters #### Path Parameters - `$theme` (SystemThemesEnum|null) - Optional - Theme to set; if null, retrieves current ### Return Type `SystemThemesEnum` — The theme enum ### Values `SYSTEM`, `LIGHT`, `DARK` ### Example ```php // Get current theme $theme = System::theme(); // Set theme System::theme(SystemThemesEnum::DARK); ``` ``` -------------------------------- ### Get All Open Windows Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Returns an array containing all currently open window instances. ```php public function all(): array ``` -------------------------------- ### Example: Hiding Title Bar and Setting Traffic Light Position Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md This example demonstrates how to hide the title bar and set the position of the traffic light buttons for a macOS window. ```php Window::open() ->titleBarHidden() ->trafficLightPosition(15, 15); ``` -------------------------------- ### Get Application Version Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/app.md Returns the application's version string as defined in its configuration. ```php $version = App::version(); // Returns: '1.0.0' ``` -------------------------------- ### Showing a Notification with a Reference Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/notification.md Example of how to create and display a notification, setting a custom reference for later tracking. The reference is accessible after the notification is shown. ```php $notification = Notification::new() ->reference('task-001') ->title('Task Started') ->message('Processing has begun') ->show(); // Now you can track this notification $notificationId = $notification->reference; ``` -------------------------------- ### AutoUpdater::quitAndInstall() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-features.md Installs a previously downloaded update and restarts the application. This action will quit the current application instance. ```APIDOC ## AutoUpdater::quitAndInstall() ### Description Installs a downloaded update and restarts the application. ### Method ```php public function quitAndInstall(): void ``` ### Example ```php AutoUpdater::quitAndInstall(); // Quits app and installs update ``` ``` -------------------------------- ### Empty Prebuild Script Source: https://github.com/nativephp/desktop/blob/main/_autodocs/configuration.md An empty prebuild script configuration. Commands defined here are executed before the build process starts. ```php 'prebuild' => [ // 'npm run build', ], ``` -------------------------------- ### Retrieve Application Settings Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-features.md Use the `get` method to retrieve a setting value by its key. A default value can be provided if the key does not exist. ```php use Native\Desktop\Facades\Settings; $theme = Settings::get('user.theme', 'light'); $preferences = Settings::get('user.preferences', []); // With callable default $lastFile = Settings::get('app.last_used_file', function() { return storage_path('default.txt'); }); ``` -------------------------------- ### Start a Generic Child Process Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/process.md Spawn a new child process for executing a command or script. Specify a unique alias for identification and optionally set the working directory and environment variables. ```PHP use Native\Desktop\Facades\ChildProcess; ChildProcess::start( 'npm run watch', 'webpack', cwd: base_path('frontend') ); ``` -------------------------------- ### Get Window by ID Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Retrieves a specific window instance using its unique identifier. ```php public function get(string $id): Window ``` -------------------------------- ### Prebuild Script with npm Commands Source: https://github.com/nativephp/desktop/blob/main/_autodocs/configuration.md Configures prebuild scripts to run npm install and npm run build before the main build process. Ensure Node.js and npm are available in the build environment. ```php 'prebuild' => [ 'npm install', 'npm run build', ], ``` -------------------------------- ### Notification::new() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/notification.md Creates a new Notification instance. This is the starting point for building and displaying notifications. ```APIDOC ## Notification::new() ### Description Creates a new Notification instance. Use this static method to begin configuring a notification. ### Method `static public function new(): self` ### Return Type `self` - A new Notification instance. ### Example ```php use Native\Desktop\Facades\Notification; Notification::new() ->title('Download Complete') ->message('Your file has finished downloading') ->show(); ``` ``` -------------------------------- ### Example NativePHP Configuration Source: https://github.com/nativephp/desktop/blob/main/_autodocs/configuration.md This snippet shows a typical configuration file for a NativePHP application. It includes settings for app version, ID, deep link scheme, author, copyright, description, website, service provider, updater, and queue workers. Environment variables are used for most settings, providing flexibility. ```php env('NATIVEPHP_APP_VERSION', '1.0.0'), 'app_id' => env('NATIVEPHP_APP_ID', 'com.mycompany.myapp'), 'deeplink_scheme' => env('NATIVEPHP_DEEPLINK_SCHEME', 'myapp'), 'author' => env('NATIVEPHP_APP_AUTHOR', 'My Company'), 'copyright' => env('NATIVEPHP_APP_COPYRIGHT', '© 2024 My Company'), 'description' => env('NATIVEPHP_APP_DESCRIPTION', 'My Desktop Application'), 'website' => env('NATIVEPHP_APP_WEBSITE', 'https://myapp.com'), 'provider' => \App\Providers\NativeAppServiceProvider::class, 'updater' => [ 'enabled' => env('NATIVEPHP_UPDATER_ENABLED', true), 'default' => env('NATIVEPHP_UPDATER_PROVIDER', 'github'), 'providers' => [ 'github' => [ 'driver' => 'github', 'owner' => env('GITHUB_OWNER', 'mycompany'), 'repo' => env('GITHUB_REPO', 'myapp'), 'token' => env('GITHUB_TOKEN'), ], ], ], 'queue_workers' => [ 'default' => [ 'queues' => ['default'], 'memory_limit' => 128, 'timeout' => 60, 'sleep' => 3, ], ], ]; ``` -------------------------------- ### App Booted Signal Source: https://github.com/nativephp/desktop/blob/main/_autodocs/endpoints.md Signals that the native app has started and is ready. Called by the Electron runtime when the app boots. ```json {} ``` -------------------------------- ### get() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/process.md Retrieves a running child process by its alias. Returns the process object if found, otherwise null. ```APIDOC ## get(?string $alias = null) ### Description Retrieves a running child process by alias. ### Parameters #### Path Parameters - **alias** (string|null) - Optional - Process alias ### Return Type `self|null` — The process or null if not running ### Example ```php $process = ChildProcess::get('webpack'); if ($process) { echo "Process PID: {$process->pid}"; } ``` ``` -------------------------------- ### Get All Display Information Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-interaction.md Fetches an array containing detailed information about all connected displays, including their bounds, work area, scale factor, and other properties. ```php $displays = Screen::displays(); foreach ($displays as $display) { echo "Display {$display['id']}: {$display['bounds']['width']}x{$display['bounds']['height']}"; } ``` -------------------------------- ### Get Application Uptime Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/process.md Fetch the application's uptime in seconds. This can be used for monitoring or logging purposes. ```PHP $uptime = Process::uptime(); echo "App has been running for {$uptime} seconds"; ``` -------------------------------- ### Start a PHP Child Process Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/process.md Spawn a child process specifically for executing PHP commands or scripts. Allows for custom environment variables and PHP ini settings. ```PHP ChildProcess::php( 'script.php arg1 arg2', 'php_worker', iniSettings: ['memory_limit' => '512M'] ); ``` -------------------------------- ### Create Alert Instance Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/alert-dialog.md Use `Alert::new()` to create a new instance of the Alert class for displaying native alerts. This is the starting point for configuring and showing alerts. ```php use Native\Desktop\Facades\Alert; $alert = Alert::new(); ``` -------------------------------- ### Get System Timezone Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-interaction.md Retrieves the current system's IANA timezone string, for example, 'America/New_York'. ```php $tz = System::timezone(); // Returns: 'America/New_York' ``` -------------------------------- ### Create and Configure Menu Bar Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/ui-components.md Use this snippet to create a new menu bar, set its URL, dimensions, and icon. This is the starting point for menu bar customization. ```php use Native\Desktop\Facades\MenuBar; MenuBar::create() ->url('/menu-bar') ->width(400) ->height(500) ->icon(resource_path('icons/menu-bar.png')); ``` -------------------------------- ### Start a Node.js Child Process Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/process.md Spawn a child process to run Node.js commands or scripts. Useful for managing Node.js based services or build tools within the application. ```PHP ChildProcess::node( 'server.js --port 3000', 'node_server' ); ``` -------------------------------- ### Manage Child Processes Source: https://github.com/nativephp/desktop/blob/main/_autodocs/README.md Start a persistent Artisan command as a child process and later stop it. Use 'Native\n *.*Desktop\n *.*Facades\n *.*ChildProcess' for process management. ```php use Native\Desktop\Facades\ChildProcess; ChildProcess::artisan('queue:work', 'queue_worker', persistent: true); // Later... ChildProcess::stop('queue_worker'); ``` -------------------------------- ### ProgressBar::start() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/ui-components.md Initializes and displays the progress bar. ```APIDOC ## ProgressBar::start() ### Description Initializes the progress bar display. This method should be called before any progress updates are made. ### Method `public function start(): void` ``` -------------------------------- ### POST _native/api/booted Source: https://github.com/nativephp/desktop/blob/main/_autodocs/endpoints.md Signals that the native app has started and is ready. Called by the Electron runtime when the app boots, triggering the ApplicationBooted event and invoking the configured service provider's boot() method. ```APIDOC ## POST _native/api/booted ### Description Signals that the native app has started and is ready. ### Method POST ### Endpoint _native/api/booted ### Request Body ```json {} ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the operation was successful. ### Response Example ```json { "success": true } ``` ``` -------------------------------- ### NSIS Installer Configuration Source: https://github.com/nativephp/desktop/blob/main/_autodocs/configuration.md Configures the NSIS installer for Windows, specifically setting whether to delete application data upon uninstallation. This uses an environment variable for flexibility. ```php 'nsis' => [ 'delete_app_data_on_uninstall' => env('NATIVEPHP_NSIS_DELETE_APP_DATA', false), ], ``` -------------------------------- ### Create and Register a Basic Menu Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/menu.md Use `Menu::make()` to create a new menu instance, chain `label()` to set its name, `add()` to append items, and `register()` to display it in the application. ```php use Native\Desktop\Menu\Menu; use Native\Desktop\Menu\Items\Link; Menu::make() ->label('File') ->add(Link::new('/new', 'New')) ->add(Link::new('/open', 'Open')) ->register(); ``` -------------------------------- ### openAtLogin() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/app.md Gets or sets whether the application launches at system login. You can retrieve the current setting by calling the method without arguments, or set it by passing a boolean value. ```APIDOC ## openAtLogin(?bool $open = null) ### Description Gets or sets whether the application launches at system login. ### Method GET/SET ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **open** (bool|null) - Optional - Whether to open at login; if null, retrieves current setting ### Request Example ```php // Get current setting $opens = App::openAtLogin(); // Enable open at login App::openAtLogin(true); // Disable open at login App::openAtLogin(false); ``` ### Response #### Success Response (200) - **openAtLogin** (bool) - The openAtLogin setting #### Response Example ```json { "openAtLogin": true } ``` ``` -------------------------------- ### Get and Print to Specific Printer Source: https://github.com/nativephp/desktop/blob/main/_autodocs/types.md Demonstrates how to retrieve a list of system printers, find a specific printer by its display name, and then print content to that printer. ```php use Native\Desktop\Facades\System; $printers = System::printers(); $officePrinter = collect($printers) ->firstWhere('displayName', 'Office Printer'); System::print($html, $officePrinter); ``` -------------------------------- ### Create and Configure a Desktop Window Source: https://github.com/nativephp/desktop/blob/main/_autodocs/README.md Opens a new desktop window with specified dimensions, title, and URL. The window's state can be remembered across sessions. ```php use Native\Desktop\Facades\Window; Window::open('main') ->title('My App') ->url('/dashboard') ->width(1200) ->height(800) ->rememberState(); ``` -------------------------------- ### Get and Set Clipboard HTML Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-interaction.md This method allows you to get or set the HTML content of the clipboard. Providing an HTML string will copy it, while calling it without arguments retrieves the current HTML content. ```php Clipboard::html('Bold text'); ``` -------------------------------- ### App Booted Response Source: https://github.com/nativephp/desktop/blob/main/_autodocs/endpoints.md Indicates a successful application boot. ```json { "success": true } ``` -------------------------------- ### Get Current Focused Window Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Retrieves the currently focused window instance. ```php public function current(): Window ``` -------------------------------- ### Create and Register a New Menu Instance Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/menu.md Use the `Menu::make()` facade method to fluently construct a new application menu with various item types. The `register()` method then makes the menu visible in the application. ```php public static function make(...$items): Menu ``` ```php use Native\Desktop\Facades\Menu; Menu::make( Link::new('/new', 'New'), Link::new('/open', 'Open'), Separator::new(), Link::new('/quit', 'Quit') )->register(); ``` -------------------------------- ### Get System Locale Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/app.md Retrieves the locale string configured for the operating system. ```php $systemLocale = App::getSystemLocale(); ``` -------------------------------- ### QueueWorker Contract Source: https://github.com/nativephp/desktop/blob/main/_autodocs/types.md Manages Laravel queue workers, allowing them to be started and stopped. ```APIDOC ## QueueWorker Contract ### Description Manages Laravel queue workers, allowing them to be started and stopped. ### Methods #### up - **Description**: Starts a queue worker. - **Parameters**: - `config` (string|QueueConfig) - The configuration for the queue worker. Can be a string alias from the config or a `QueueConfig` object. #### down - **Description**: Stops a queue worker. - **Parameters**: - `alias` (string) - The alias of the queue worker to stop. ``` -------------------------------- ### Open a Secondary Window Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Opens a new window with a specified ID and sets its initial dimensions. This demonstrates chaining multiple configuration methods. ```php Window::open('secondary') ->width(800) ->height(600); ``` -------------------------------- ### Create Dialog Instance Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/alert-dialog.md Instantiate the `Dialog` class using `Dialog::new()` to prepare for displaying native dialog windows, such as file pickers. ```php use Native\Desktop\Facades\Dialog; $dialog = Dialog::new(); ``` -------------------------------- ### Open a New Window Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Creates and returns a `PendingOpenWindow` instance for configuring and opening a new window. Accepts an optional unique ID. ```php public function open(string $id = 'main'): PendingOpenWindow ``` -------------------------------- ### Get Application Locale Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/app.md Retrieves the current locale string of the application, such as 'en-US' or 'fr-FR'. ```php $locale = App::getLocale(); // Returns: 'en-US' ``` -------------------------------- ### Open Window with Specific URL and Show Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Opens a window and loads a specific URL, then makes the window visible. This is useful for loading external or local web content. ```php Window::open() ->url('https://localhost:8000/home') ->show(); ``` -------------------------------- ### ChildProcess Contract Source: https://github.com/nativephp/desktop/blob/main/_autodocs/types.md Manages child processes, allowing for starting, stopping, restarting, and communicating with them. ```APIDOC ## ChildProcess Contract ### Description Manages child processes, allowing for starting, stopping, restarting, and communicating with them. ### Methods #### get - **Description**: Retrieves a child process by its alias. - **Parameters**: - `alias` (string|null) - The alias of the child process. If null, returns the default process. - **Returns**: `self|null` - The child process instance or null if not found. #### all - **Description**: Retrieves all managed child processes. - **Returns**: `array` - An array of all child process instances. #### start - **Description**: Starts a new child process. - **Parameters**: - `cmd` (string|array) - The command to execute. - `alias` (string) - A unique alias for the process. - `cwd` (string|null) - The working directory for the process. - `env` (array|null) - Environment variables for the process. - `persistent` (bool) - Whether the process should be persistent. - **Returns**: `self` - The child process instance. #### php - **Description**: Starts a new PHP child process. - **Parameters**: - `cmd` (string|array) - The PHP command to execute. - `alias` (string) - A unique alias for the process. - `env` (array|null) - Environment variables for the process. - `persistent` (bool|null) - Whether the process should be persistent. - `iniSettings` (array|null) - PHP ini settings for the process. - **Returns**: `self` - The child process instance. #### node - **Description**: Starts a new Node.js child process. - **Parameters**: - `cmd` (string|array) - The Node.js command to execute. - `alias` (string) - A unique alias for the process. - `env` (array|null) - Environment variables for the process. - `persistent` (bool|null) - Whether the process should be persistent. - **Returns**: `self` - The child process instance. #### artisan - **Description**: Starts a new Artisan (Laravel) child process. - **Parameters**: - `cmd` (string|array) - The Artisan command to execute. - `alias` (string) - A unique alias for the process. - `env` (array|null) - Environment variables for the process. - `persistent` (bool|null) - Whether the process should be persistent. - `iniSettings` (array|null) - PHP ini settings for the process. - **Returns**: `self` - The child process instance. #### stop - **Description**: Stops a child process. - **Parameters**: - `alias` (string|null) - The alias of the process to stop. If null, stops the default process. #### restart - **Description**: Restarts a child process. - **Parameters**: - `alias` (string|null) - The alias of the process to restart. If null, restarts the default process. - **Returns**: `self|null` - The restarted child process instance or null. #### message - **Description**: Sends a message to a child process. - **Parameters**: - `message` (string) - The message to send. - `alias` (string|null) - The alias of the target process. If null, sends to the default process. - **Returns**: `self` - The child process instance. ``` -------------------------------- ### Auto Updater Endpoints Source: https://github.com/nativephp/desktop/blob/main/_autodocs/endpoints.md Endpoints for managing application updates, including checking, downloading, and installing. ```APIDOC ## POST auto-updater/check-for-updates ### Description Check for updates. ### Method POST ### Endpoint `/auto-updater/check-for-updates` ``` ```APIDOC ## POST auto-updater/download-update ### Description Download update. ### Method POST ### Endpoint `/auto-updater/download-update` ``` ```APIDOC ## POST auto-updater/quit-and-install ### Description Install and restart. ### Method POST ### Endpoint `/auto-updater/quit-and-install` ``` -------------------------------- ### Create and Show a Basic Notification Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/notification.md Use `Notification::new()` to create a new notification instance, chain methods to set the title and message, and then call `show()` to display it. ```php use Native\Desktop\Facades\Notification; Notification::new() ->title('Download Complete') ->message('Your file has finished downloading') ->show(); ``` -------------------------------- ### Set Window Title and URL Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Opens a main window, sets its title to 'My Application', and specifies the URL to load. This showcases basic window configuration. ```php Window::open('main') ->title('My Application') ->url('/dashboard'); ``` -------------------------------- ### Clipboard Endpoints Source: https://github.com/nativephp/desktop/blob/main/_autodocs/endpoints.md Endpoints for getting, setting, and clearing clipboard content, including text, HTML, and images. ```APIDOC ## GET/POST clipboard/text ### Description Get/set text. ### Method GET/POST ### Endpoint `/clipboard/text` ``` ```APIDOC ## GET/POST clipboard/html ### Description Get/set HTML. ### Method GET/POST ### Endpoint `/clipboard/html` ``` ```APIDOC ## GET/POST clipboard/image ### Description Get/set image. ### Method GET/POST ### Endpoint `/clipboard/image` ``` ```APIDOC ## DELETE clipboard ### Description Clear clipboard. ### Method DELETE ### Endpoint `/clipboard` ``` -------------------------------- ### Get Recent Documents Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/app.md Retrieves an array containing the file paths of all documents recently opened by the application. ```php $documents = App::recentDocuments(); // Returns: ['/path/to/file1.pdf', '/path/to/file2.txt'] ``` -------------------------------- ### Fluent Window Configuration Source: https://github.com/nativephp/desktop/blob/main/_autodocs/README.md Configure window properties like dimensions, title, and transparency using method chaining. The 'Window' facade is used for this purpose. ```php Window::open() ->width(1200) ->height(800) ->title('My App') ->transparent() ->alwaysOnTop(); ``` -------------------------------- ### Menu::make() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/menu.md Creates a new Menu instance and allows for fluent API chaining to define menu items and their properties. The `register()` method should be called to apply the menu. ```APIDOC ## Menu::make() ### Description Creates a new Menu instance with a fluent API. ### Method `public static function make(...$items): Menu` ### Parameters #### Path Parameters - `...$items` (MenuItem) - Required - Variable menu items to include in the menu. ### Response #### Success Response (Menu) - Returns a `Menu` instance for further manipulation or registration. ### Request Example ```php use Native\Desktop\Facades\Menu; Menu::make( Link::new('/new', 'New'), Link::new('/open', 'Open'), Separator::new(), Link::new('/quit', 'Quit') )->register(); ``` ``` -------------------------------- ### Get Active Display Information Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-interaction.md Returns an array containing information about the display that currently contains the mouse cursor. ```php $active = Screen::active(); ``` -------------------------------- ### Show Menu Bar on All Workspaces Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/ui-components.md Configures the menu bar to be visible on all virtual desktops. Defaults to true. ```php public function showOnAllWorkspaces($showOnAllWorkspaces = true): self ``` -------------------------------- ### getCurrentThermalState() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/power-monitor.md Gets the current CPU thermal state. Returns one of: NOMINAL, FAIR, SERIOUS, CRITICAL, UNKNOWN. ```APIDOC ## getCurrentThermalState() ### Description Gets the current CPU thermal state. ### Method GET ### Endpoint /power-monitor/thermal-state ### Parameters None ### Response #### Success Response (200) - **state** (string) - One of: `NOMINAL`, `FAIR`, `SERIOUS`, `CRITICAL`, `UNKNOWN` ### Response Example ```json { "state": "NOMINAL" } ``` ``` -------------------------------- ### minWidth(), minHeight(), maxWidth(), maxHeight() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Sets the minimum and maximum dimensions for the window. These methods support method chaining. ```APIDOC ## minWidth(), minHeight(), maxWidth(), maxHeight() ### Description Sets the minimum and maximum dimensions for the window. ### Method `public function minWidth($width): self` `public function minHeight($height): self` `public function maxWidth($width): self` `public function maxHeight($height): self` ### Parameters #### Path Parameters - **width** (int) - Required - The minimum or maximum width in pixels. - **height** (int) - Required - The minimum or maximum height in pixels. ### Return Type `self` - For method chaining. ### Example ```php Window::open('editor') ->width(1200) ->height(800) ->minWidth(400) ->minHeight(300) ->maxWidth(2000); ``` ``` -------------------------------- ### showInFolder() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-interaction.md Opens the system's file manager to display the specified file or directory. ```APIDOC ## showInFolder() ### Description Opens the file manager showing the specified path. ### Method `public function showInFolder(string $path): void` ### Parameters #### Path Parameters - `$path` (string) - Required - File or directory path ### Return Type `void` ### Example ```php use Native\Desktop\Facades\Shell; Shell::showInFolder('/path/to/file.txt'); // Opens file manager with file selected ``` ``` -------------------------------- ### Child Process Endpoints Source: https://github.com/nativephp/desktop/blob/main/_autodocs/endpoints.md Endpoints for managing child processes, including listing, starting, stopping, restarting, and messaging. ```APIDOC ## GET child-process/ ### Description List all child processes. ### Method GET ### Endpoint `/child-process/` ``` ```APIDOC ## GET child-process/get/{alias} ### Description Get child process by alias. ### Method GET ### Endpoint `/child-process/get/{alias}` ``` ```APIDOC ## POST child-process/start ### Description Start child process. ### Method POST ### Endpoint `/child-process/start` ``` ```APIDOC ## POST child-process/start-php ### Description Start PHP process. ### Method POST ### Endpoint `/child-process/start-php` ``` ```APIDOC ## POST child-process/start-node ### Description Start Node.js process. ### Method POST ### Endpoint `/child-process/start-node` ``` ```APIDOC ## POST child-process/stop ### Description Stop child process. ### Method POST ### Endpoint `/child-process/stop` ``` ```APIDOC ## POST child-process/restart ### Description Restart child process. ### Method POST ### Endpoint `/child-process/restart` ``` ```APIDOC ## POST child-process/message ### Description Send message to process. ### Method POST ### Endpoint `/child-process/message` ``` -------------------------------- ### Window Management Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Methods for opening, closing, hiding, showing, and retrieving window instances. ```APIDOC ## WindowManager Class **Namespace:** `Native\Desktop\Windows` **Facade:** `Native\Desktop\Facades\Window` ### open() Creates a new window. ```php public function open(string $id = 'main'): PendingOpenWindow ``` **Parameters:** - `$id` (string, optional, default: 'main'): Unique window identifier **Return Type:** `PendingOpenWindow` — Configure and call methods on it **Example:** ```php use Native\Desktop\Facades\Window; Window::open('secondary') ->url('/page') ->width(800) ->height(600); ``` ### close() Closes a window. ```php public function close($id = null): void ``` **Parameters:** - `$id` (string|null, optional, default: Current window): Window ID to close **Return Type:** `void` ### hide() Hides a window. ```php public function hide($id = null): void ``` **Parameters:** - `$id` (string|null, optional): Window ID ### show() Shows a hidden window. ```php public function show($id = null): void ``` **Parameters:** - `$id` (string|null, optional): Window ID ### current() Gets the currently focused window. ```php public function current(): Window ``` **Return Type:** `Window` — Current window instance **Example:** ```php $current = Window::current(); echo $current->getId(); // 'main' ``` ### all() Gets all open windows. ```php public function all(): array ``` **Return Type:** `array` — Array of Window instances ### get() Gets a specific window by ID. ```php public function get(string $id): Window ``` **Parameters:** - `$id` (string): Window ID **Return Type:** `Window` — The window instance ``` -------------------------------- ### Get Cursor Position Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-interaction.md Retrieves the current X and Y coordinates of the mouse cursor on the screen. The returned object has 'x' and 'y' properties. ```php use Native\Desktop\Facades\Screen; $position = Screen::cursorPosition(); echo "Cursor at: {$position->x}, {$position->y}"; ``` -------------------------------- ### MenuBar::show() Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/ui-components.md Makes the menu bar visible. ```APIDOC ## MenuBar::show() ### Description Shows the menu bar. This makes the previously configured menu bar visible to the user. ### Method `static function show(): void` ``` -------------------------------- ### Settings Endpoints Source: https://github.com/nativephp/desktop/blob/main/_autodocs/endpoints.md Endpoints for managing application settings, including getting, setting, deleting individual settings, and clearing all settings. ```APIDOC ## GET settings/{key} ### Description Get setting. ### Method GET ### Endpoint `/settings/{key}` ``` ```APIDOC ## POST settings/{key} ### Description Set setting. ### Method POST ### Endpoint `/settings/{key}` ``` ```APIDOC ## DELETE settings/{key} ### Description Delete setting. ### Method DELETE ### Endpoint `/settings/{key}` ``` ```APIDOC ## DELETE settings/ ### Description Clear all settings. ### Method DELETE ### Endpoint `/settings/` ``` -------------------------------- ### Create Menu Bar with URL and Dimensions Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/ui-components.md Configures a menu bar, setting its initial URL and dimensions. This is useful for creating custom menu bar interfaces. ```php MenuBar::create() ->url('/menu-bar') ->width(300) ->height(400) ``` -------------------------------- ### GET _native/api/cookie Source: https://github.com/nativephp/desktop/blob/main/_autodocs/endpoints.md Creates a security cookie for CSRF protection. Generates and returns a session cookie for authenticating subsequent requests. ```APIDOC ## GET _native/api/cookie ### Description Creates a security cookie for CSRF protection. ### Method GET ### Endpoint _native/api/cookie ### Response #### Success Response (200) - **cookie** (string) - The generated security cookie string. ### Response Example ```json { "cookie": "laravel_session=..." } ``` ``` -------------------------------- ### Open File with System Default Application Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-interaction.md Use this method to open a specified file using the system's default application for that file type. Provide the full path to the file. ```php public function openFile(string $path): string ``` ```php Shell::openFile('/path/to/document.pdf'); // Opens in default PDF viewer ``` -------------------------------- ### Get a Child Process by Alias Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/process.md Retrieves a running child process using its alias. Returns null if the process is not found. ```php public function get(?string $alias = null): ?self ``` ```php $process = ChildProcess::get('webpack'); if ($process) { echo "Process PID: {$process->pid}"; } ``` -------------------------------- ### Register Application Menu with Accelerators Source: https://github.com/nativephp/desktop/blob/main/_autodocs/README.md Registers a new application menu with 'New' and 'Open' items. Each item includes a keyboard accelerator for quick access. ```php use Native\Desktop\Facades\Menu; use Native\Desktop\Menu\Items\Link; Menu::make( Link::new('/new', 'New') ->accelerator('CmdOrCtrl+N'), Link::new('/open', 'Open') ->accelerator('CmdOrCtrl+O'), )->register(); ``` -------------------------------- ### Get Application Locale Country Code Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/app.md Extracts and returns the country code portion from the application's locale string. ```php $countryCode = App::getLocaleCountryCode(); ``` -------------------------------- ### Get System Idle Time Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/power-monitor.md Returns the total number of seconds the system has been idle. Useful for implementing inactivity-based actions. ```php $idleSeconds = PowerMonitor::getSystemIdleTime(); $idleMinutes = floor($idleSeconds / 60); echo "System idle for {$idleMinutes} minutes"; ``` -------------------------------- ### Window Configuration Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Methods for configuring window properties like size, position, and behavior. ```APIDOC ## Window Configuration Methods ### suppressNewWindows() Prevents links from opening in new windows. ```php public function suppressNewWindows(): self ``` **Return Type:** `self` — For method chaining ### invisibleFrameless() Shortcut to create an invisible frameless window. ```php public function invisibleFrameless(): self ``` **Return Type:** `self` — For method chaining Equivalent to: frameless + transparent + not focusable + no shadow ### hideMenu() Auto-hides the menu bar. ```php public function hideMenu($autoHideMenuBar = true): self ``` **Parameters:** - `$autoHideMenuBar` (bool, optional, default: true) **Return Type:** `self` — For method chaining ### rememberState() Persists window size and position between sessions. ```php public function rememberState(): self ``` **Return Type:** `self` — For method chaining ### hasShadow() Controls the window shadow. ```php public function hasShadow($value = true): self ``` **Parameters:** - `$value` (bool, optional, default: true) **Return Type:** `self` — For method chaining ### webPreferences() Sets Chromium web preferences. ```php public function webPreferences(array $preferences): self ``` **Parameters:** - `$preferences` (array): Electron webPreferences object **Return Type:** `self` — For method chaining ### afterOpen() Registers a callback to run after the window opens. ```php public function afterOpen(callable $cb): self ``` **Parameters:** - `$cb` (callable): Callback receiving the Window instance **Return Type:** `self` — For method chaining **Example:** ```php Window::open('main') ->afterOpen(function($window) { Window::focus(); }); ``` ### resize() Resizes a window. ```php public function resize($width, $height, $id = null): void ``` **Parameters:** - `$width` (int): New width in pixels - `$height` (int): New height in pixels - `$id` (string|null, optional, default: Current window): Window ID ### position() Positions a window on the screen. ```php public function position($x, $y, $animated = false, $id = null): void ``` **Parameters:** - `$x` (int): X coordinate - `$y` (int): Y coordinate - `$animated` (bool, optional, default: false): Animate the movement - `$id` (string|null, optional): Window ID ### maximize() Maximizes a window. ```php public function maximize($id = null): void ``` **Parameters:** - `$id` (string|null, optional): Window ID ### minimize() Minimizes a window. ```php public function minimize($id = null): void ``` **Parameters:** - `$id` (string|null, optional): Window ID ### reload() Reloads the window content. ```php public function reload($id = null): void ``` **Parameters:** - `$id` (string|null, optional): Window ID ### alwaysOnTop() Sets window always-on-top state. ```php public function alwaysOnTop($alwaysOnTop = true, $id = null): void ``` **Parameters:** - `$alwaysOnTop` (bool, optional, default: true): Whether the window should always be on top - `$id` (string|null, optional): Window ID ``` -------------------------------- ### QueueWorker Class Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/system-features.md Manage queue worker processes. Start and stop workers using configuration aliases or custom configurations. ```APIDOC ## QueueWorker::up() ### Description Starts a queue worker process. ### Method `up(string|QueueConfig $config): void` ### Parameters #### Path Parameters - **$config** (string|QueueConfig) - Required - Config alias or QueueConfig object. ### Request Example ```php use Native\Desktop\Facades\QueueWorker; use Native\Desktop\QueueConfig; // Start queue worker from config QueueWorker::up('default'); // Start with custom config QueueWorker::up( new QueueConfig( alias: 'exports', queuesToConsume: ['exports', 'notifications'], memoryLimit: 256, timeout: 120, sleep: 3 ) ); ``` ## QueueWorker::down() ### Description Stops a queue worker by alias. ### Method `down(string $alias): void` ### Parameters #### Path Parameters - **$alias** (string) - Required - Worker alias. ### Request Example ```php QueueWorker::down('default'); QueueWorker::down('exports'); ``` ``` -------------------------------- ### Register Global Shortcut Source: https://github.com/nativephp/desktop/blob/main/_autodocs/README.md Register a global keyboard shortcut that triggers a specific event in your application. Ensure the 'Native *.*Desktop *.*Facades *.*GlobalShortcut' facade is imported. ```php use Native\Desktop\Facades\GlobalShortcut; GlobalShortcut::new() ->key('CmdOrCtrl+K') ->event('App\Events\CommandPaletteRequested') ->register(); ``` -------------------------------- ### Set Window Dimensions and Constraints Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/window.md Opens an editor window, sets its initial dimensions, and defines minimum and maximum size constraints. This ensures the window is usable within defined boundaries. ```php Window::open('editor') ->width(1200) ->height(800) ->minWidth(400) ->minHeight(300) ->maxWidth(2000); ``` -------------------------------- ### Get CPU Architecture Source: https://github.com/nativephp/desktop/blob/main/_autodocs/api-reference/process.md Retrieve the CPU architecture of the running process. Useful for conditional logic based on the system's architecture. ```PHP use Native\Desktop\Facades\Process; $arch = Process::arch(); // Returns: 'x64' ```