-
Notifications
You must be signed in to change notification settings - Fork 0
App
Control your application's event lifecycle.
The Electron.App API provides comprehensive control over your application's lifecycle, including startup, shutdown, window management, and system integration. It handles application-level events and provides methods for managing the overall application state.
Description: Try to close all windows. The BeforeQuit event will be emitted first. If all windows are successfully closed, the WillQuit event will be emitted and by default the application will terminate.
Parameters:
-
exitCode(optional) - Exits immediately with exitCode. Defaults to 0.
Description: All windows will be closed immediately without asking user and the BeforeQuit and WillQuit events will not be emitted.
Description: Relaunches the app when current instance exits. By default the new instance will use the same working directory and command line arguments with current instance.
Parameters:
-
relaunchOptions- Options for the relaunch
Description: Relaunches the app with custom options for executable path and arguments.
Description: On Linux, focuses on the first visible window. On macOS, makes the application the active app. On Windows, focuses on the application's first window.
Parameters:
-
focusOptions- Focus options
Description: Focus application with additional options like steal focus.
Description: Hides all application windows without minimizing them.
Description: Shows application windows after they were hidden. Does not automatically focus them.
Returns: The current application directory.
Returns: The version of the loaded application.
Returns: The current application locale.
Description: A string property that indicates the current application's name.
Returns: The current application's name as a Task.
Parameters:
-
pathName- Special directory name
Returns: A path to a special directory or file associated with name.
Parameters:
-
name- Special directory name -
path- New path to a special directory
Description: Overrides the path to a special directory or file associated with name.
Parameters:
-
path- A custom path for your logs. Must be absolute
Description: Sets or creates a directory your app's logs which can then be manipulated with GetPathAsync or SetPath.
Parameters:
-
protocol- The name of your protocol, without :// -
cancellationToken(optional) - The cancellation token
Returns: Whether the call succeeded.
Parameters:
-
protocol- The name of your protocol, without :// -
path- The path to the Electron executable. Defaults to process.execPath -
cancellationToken(optional) - The cancellation token
Returns: Whether the call succeeded.
Parameters:
-
protocol- The name of your protocol, without :// -
path- The path to the Electron executable. Defaults to process.execPath -
args- Arguments passed to the executable. Defaults to an empty array -
cancellationToken(optional) - The cancellation token
Returns: Whether the call succeeded.
Parameters:
-
protocol- The name of your protocol, without :// -
cancellationToken(optional) - The cancellation token
Returns: Whether the current executable is the default handler for a protocol.
Parameters:
-
protocol- The name of your protocol, without :// -
cancellationToken(optional) - The cancellation token
Returns: Whether the call succeeded.
Parameters:
-
userTasks- Array of UserTask objects -
cancellationToken(optional) - The cancellation token
Returns: Whether the call succeeded.
Returns: Jump List settings.
Parameters:
-
categories- Array of JumpListCategory objects
Description: Sets or removes a custom Jump List for the application.
Parameters:
-
newInstanceOpened- Callback with an array of the second instance's command line arguments -
cancellationToken(optional) - The cancellation token
Returns: Whether this process is the primary instance.
Description: Releases all locks that were created by makeSingleInstance. This will allow multiple instances of the application to once again run side by side.
Returns: Whether this instance of your app is currently holding the single instance lock.
Returns: Login item settings.
Parameters:
-
options- Login item settings options -
cancellationToken(optional) - The cancellation token
Returns: Login item settings.
Parameters:
-
loginSettings- Login settings
Description: Set the app's login item settings.
Parameters:
-
type- Uniquely identifies the activity -
userInfo- App-specific state to store for use by another device
Description: Creates an NSUserActivity and sets it as the current activity.
Parameters:
-
type- Uniquely identifies the activity -
userInfo- App-specific state to store for use by another device -
webpageUrl- The webpage to load in a browser if no suitable app is installed
Description: Creates an NSUserActivity and sets it as the current activity.
Returns: The type of the currently running activity.
Description: Invalidates the current Handoff user activity.
Description: Marks the current Handoff user activity as inactive without invalidating it.
Parameters:
-
id- Model Id
Description: Changes the Application User Model ID to id.
Parameters:
-
path- Path to add
Description: Adds path to the recent documents list.
Description: Clears the recent documents list.
Parameters:
-
count- Counter badge -
cancellationToken(optional) - The cancellation token
Returns: Whether the call succeeded.
Returns: The current value displayed in the counter badge.
Returns: Whether the current desktop environment is Unity launcher.
Parameters:
-
options- Import certificate options -
cancellationToken(optional) - The cancellation token
Returns: Result of import. Value of 0 indicates success.
Returns: Array of ProcessMetric objects that correspond to memory and cpu usage statistics of all the processes associated with the app.
Returns: The Graphics Feature Status from chrome://gpu/.
Returns: true if Chrome's accessibility support is enabled, false otherwise.
Parameters:
-
enabled- Enable or disable accessibility tree rendering
Description: Manually enables Chrome's accessibility support.
Description: Show the app's about panel options.
Parameters:
-
options- About panel options
Description: Set the about panel options.
Description: A string which is the user agent string Electron will use as a global fallback.
Returns: The user agent string Electron will use as a global fallback.
Description: Emitted when all windows have been closed.
Description: Emitted before the application starts closing its windows.
Description: Emitted when all windows have been closed and the application will quit.
Description: Emitted when the application is quitting.
Description: Emitted when a BrowserWindow blurred.
Description: Emitted when a BrowserWindow gets focused.
Description: Emitted when a new BrowserWindow is created.
Description: Emitted when a new WebContents is created.
Description: Emitted when Chrome's accessibility support changes.
Description: Emitted when the application has finished basic startup.
Description: Emitted when a macOS user wants to open a file with the application.
Description: Emitted when a macOS user wants to open a URL with the application.
// Handle app startup
Electron.App.Ready += () =>
{
Console.WriteLine("App is ready!");
};
// Handle window management
Electron.App.WindowAllClosed += () =>
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Electron.App.Quit();
}
};
// Prevent quit
Electron.App.BeforeQuit += async (args) =>
{
var result = await Electron.Dialog.ShowMessageBoxAsync("Do you want to quit?");
if (result.Response == 1) // Cancel
{
args.PreventDefault = true;
}
};// Register custom protocol
var success = await Electron.App.SetAsDefaultProtocolClientAsync("myapp");
// Check if registered
var isDefault = await Electron.App.IsDefaultProtocolClientAsync("myapp");// Set user tasks
await Electron.App.SetUserTasksAsync(new[]
{
new UserTask
{
Program = "myapp.exe",
Arguments = "--new-document",
Title = "New Document",
Description = "Create a new document"
}
});// Get app information
var appPath = await Electron.App.GetAppPathAsync();
var version = await Electron.App.GetVersionAsync();
var locale = await Electron.App.GetLocaleAsync();
// Set app name
await Electron.App.NameAsync; // Get current name
Electron.App.Name = "My Custom App Name";// Set badge count
await Electron.App.SetBadgeCountAsync(5);
// Get current badge count
var count = await Electron.App.GetBadgeCountAsync();- Electron.WindowManager - Window creation and management
- Electron.Dialog - User interaction dialogs
- Electron.Menu - Application menus
- Electron App Documentation - Official Electron app API
- Startup Methods - Different application startup modes
Want to contribute to this documentation? Please fork and create a PR! The Wiki is autogenerated from the /docs content in the repository.