Application
On this page
#Application
The App
facade allows you to perform basic operations with the Electron app.
Note: Some methods are only available on specific operating systems and are labeled as such.
To use the App
facade, add the following to the top of your file:
use Native\Laravel\Facades\App;
#Quit the app
To quit the app, use the quit
method:
App::quit();
#Relaunch the app
To relaunch the app, use the relaunch
method. This will quit the app and relaunch it.
App::relaunch();
#Focus the app
To focus the app, use the focus
method.
On Linux, it focuses on the first visible window. On macOS, it makes the application the active one. On Windows, it focuses on the application's first window.
App::focus();
#Hide the app
Only available on macOS
The hide
method will hide all application windows without minimizing them. This method is only available on macOS.
App::hide();
#Check if the app is hidden
Only available on macOS
To check if the app is hidden, use the isHidden
method. This method is only available on macOS.
Returns a boolean: true
if the application—including all its windows—is hidden (e.g., with Command-H), false
otherwise.
$isHidden = App::isHidden();
#Current Version
To get the current app version, use the version
method. The version is defined in the config/nativephp.php
file.
$version = App::version();
#Locale information
The facade offers several methods for accessing some of the system's localisation information. This data can be helpful for localising your application, e.g. if you want to suggest the corresponding language to the user on first launch.
App::getLocale(); // e.g. "de", "fr-FR"App::getLocaleCountryCode(); // e.g. "US", "DE"App::getSystemLocale(); // e.g. "it-IT", "de-DE"
The getLocale
method will return the locale used by the app.
Dependening on the user's settings, this might include both the language and the country / region or the language only.
It is based on Chromiums l10n_util
library; see this page to see possible values.
getLocaleCountryCode
returns the user's system country code (using the ISO 3166 code).
This information is pulled from native OS APIs. If it is not possible to detect this information, an empty string will be returned.
With getSystemLocale
you can access the system-wide locale setting. This is the locale set at the operating system level, not necessarily what the app is using.
Under Windows and Linux, Chromium's i18n
library is used to evaluate this information. macOS will use [NSLocale currentLocale]
.
#App Badge Count
Only available on macOS and Linux
You can set the app's badge count. On macOS, it shows on the dock icon. On Linux, it only works for Unity launcher.
To set the badge count, use the badgeCount
method:
App::badgeCount(5);
To remove the badge count, use the badgeCount
method with 0
as the argument:
App::badgeCount(0);
To get the badge count, use the badgeCount
method without any arguments:
$badgeCount = App::badgeCount();
#Recent documents list
Only available on macOS and Windows
The recent documents list is a list of files that the user has recently opened. This list is available on macOS and Windows.
To add a document to the recent documents list, use the addRecentDocument
method:
App::addRecentDocument('/path/to/document');
To clear the recent documents list, use the clearRecentDocuments
method:
App::clearRecentDocuments();
#Open at login
Only available on macOS and Windows
To enable 'open at login', use the openAtLogin
method:
App::openAtLogin(true);
To disable open at login, use the openAtLogin
method with false
as the argument:
App::openAtLogin(false);
To check if the app is set to open at login, use the openAtLogin
method without any arguments:
$isOpenAtLogin = App::openAtLogin();