using System; using System.Threading; using System.Threading.Tasks; using ElectronNET.API.Entities; namespace ElectronNET.API.Interfaces { /// /// Control your application's event lifecycle. /// public interface IApp { /// /// Emitted when all windows have been closed. /// /// If you do not subscribe to this event and all windows are closed, the default behavior is to quit /// the app; however, if you subscribe, you control whether the app quits or not.If the user pressed /// Cmd + Q, or the developer called , Electron will first try to close all the windows /// and then emit the event, and in this case the event /// would not be emitted. /// event Action WindowAllClosed; /// /// Emitted before the application starts closing its windows. /// /// Note: If application quit was initiated by then /// is emitted after emitting close event on all windows and closing them. /// /// Note: On Windows, this event will not be emitted if the app is closed due to a shutdown/restart of the system or a user logout. /// event Func BeforeQuit; /// /// Emitted when all windows have been closed and the application will quit. /// /// See the description of the event for the differences between the /// and events. /// /// Note: On Windows, this event will not be emitted if the app is closed due to a shutdown/restart of the system or a user logout. /// event Func WillQuit; /// /// Emitted when the application is quitting. /// /// Note: On Windows, this event will not be emitted if the app is closed due to a shutdown/restart of the system or a user logout. /// event Func Quitting; /// /// Emitted when a blurred. /// event Action BrowserWindowBlur; /// /// Emitted when a gets focused. /// event Action BrowserWindowFocus; /// /// Emitted when a new is created. /// event Action BrowserWindowCreated; /// /// Emitted when a new is created. /// event Action WebContentsCreated; /// /// Emitted when Chrome’s accessibility support changes. This event fires when assistive technologies, such as /// screen readers, are enabled or disabled. See https://www.chromium.org/developers/design-documents/accessibility for more details. /// /// when Chrome's accessibility support is enabled, otherwise. event Action AccessibilitySupportChanged; /// /// Emitted when the application has finished basic startup. /// event Action Ready; /// /// Application host fully started. /// bool IsReady { get; } /// /// A property that indicates the current application's name, which is the name in the /// application's package.json file. /// /// Usually the name field of package.json is a short lowercase name, according to the npm modules spec. You /// should usually also specify a productName field, which is your application's full capitalized name, and /// which will be preferred over name by Electron. /// string Name { set; } /// /// A property that indicates the current application's name, which is the name in the /// application's package.json file. /// /// Usually the name field of package.json is a short lowercase name, according to the npm modules spec. You /// should usually also specify a productName field, which is your application's full capitalized name, and /// which will be preferred over name by Electron. /// Task GetNameAsync { get; } /// /// A object that allows you to read and manipulate the command line arguments that Chromium uses. /// CommandLine CommandLine { get; } /// /// A which is the user agent string Electron will use as a global fallback. /// /// This is the user agent that will be used when no user agent is set at the webContents or /// session level. It is useful for ensuring that your entire app has the same user agent. Set to a /// custom value as early as possible in your app's initialization to ensure that your overridden value /// is used. /// string UserAgentFallback { set; } /// /// A which is the user agent string Electron will use as a global fallback. /// /// This is the user agent that will be used when no user agent is set at the webContents or /// session level. It is useful for ensuring that your entire app has the same user agent. Set to a /// custom value as early as possible in your app's initialization to ensure that your overridden value /// is used. /// Task GetUserAgentFallbackAsync { get; } /// /// Emitted when a MacOS user wants to open a file with the application. The open-file event is usually emitted /// when the application is already open and the OS wants to reuse the application to open the file. /// open-file is also emitted when a file is dropped onto the dock and the application is not yet running. /// /// On Windows, you have to parse the arguments using App.CommandLine to get the filepath. /// event Action OpenFile; /// /// Emitted when a MacOS user wants to open a URL with the application. Your application's Info.plist file must /// define the URL scheme within the CFBundleURLTypes key, and set NSPrincipalClass to AtomApplication. /// event Action OpenUrl; /// /// Try to close all windows. The event will be emitted first. If all windows are successfully /// closed, the event will be emitted and by default the application will terminate. This method /// guarantees that all beforeunload and unload event handlers are correctly executed. It is possible /// that a window cancels the quitting by returning in the beforeunload event handler. /// void Quit(); /// /// All windows will be closed immediately without asking user and the and /// events will not be emitted. /// /// Exits immediately with exitCode. exitCode defaults to 0. void Exit(int exitCode = 0); /// /// 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. /// /// Note that this method does not quit the app when executed, you have to call or /// after calling to make the app restart. /// /// When is called for multiple times, multiple instances will be started after current instance /// exited. /// void Relaunch(); /// /// 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. When is specified, the /// will be passed as command line arguments instead. When /// is specified, the will be executed for relaunch instead of current app. /// /// Note that this method does not quit the app when executed, you have to call or /// after calling to make the app restart. /// /// When is called for multiple times, multiple instances will be started after current instance /// exited. /// /// Options for the relaunch. void Relaunch(RelaunchOptions relaunchOptions); /// /// 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. /// void Focus(); /// /// 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. /// /// You should seek to use the option as sparingly as possible. /// void Focus(FocusOptions focusOptions); /// /// Hides all application windows without minimizing them. /// void Hide(); /// /// Shows application windows after they were hidden. Does not automatically focus them. /// void Show(); /// /// The current application directory. /// Task GetAppPathAsync(CancellationToken cancellationToken = default); /// /// Sets or creates a directory your app's logs which can then be manipulated with /// or . /// /// Calling without a path parameter will result in this directory being set to /// ~/Library/Logs/YourAppName on macOS, and inside the userData directory on Linux and Windows. /// /// A custom path for your logs. Must be absolute. void SetAppLogsPath(string path); /// /// The path to a special directory. If is called without called /// being called first, a default directory will be created equivalent /// to calling without a path parameter. /// /// Special directory. /// The cancellation token. /// A path to a special directory or file associated with name. Task GetPathAsync(PathName pathName, CancellationToken cancellationToken = default); /// /// Overrides the path to a special directory or file associated with name. If the path specifies a directory /// that does not exist, an Error is thrown. In that case, the directory should be created with fs.mkdirSync or similar. /// /// You can only override paths of a name defined in . /// /// By default, web pages' cookies and caches will be stored under the directory. If you /// want to change this location, you have to override the path before the /// event of the module is emitted. /// Special directory. /// New path to a special directory. /// void SetPath(PathName name, string path); /// /// The version of the loaded application. If no version is found in the application’s package.json file, /// the version of the current bundle or executable is returned. /// /// The version of the loaded application. Task GetVersionAsync(CancellationToken cancellationToken = default); /// /// The current application locale. Possible return values are documented here. /// /// Note: When distributing your packaged app, you have to also ship the locales folder. /// /// Note: On Windows, you have to call it after the events gets emitted. /// /// The current application locale. Task GetLocaleAsync(CancellationToken cancellationToken = default); /// /// Adds path to the recent documents list. This list is managed by the OS. On Windows you can visit the /// list from the task bar, and on macOS you can visit it from dock menu. /// /// Path to add. void AddRecentDocument(string path); /// /// Clears the recent documents list. /// void ClearRecentDocuments(); /// /// Sets the current executable as the default handler for a protocol (aka URI scheme). It allows you to /// integrate your app deeper into the operating system. Once registered, all links with your-protocol:// /// will be opened with the current executable. The whole link, including protocol, will be passed to your /// application as a parameter. /// /// Note: On macOS, you can only register protocols that have been added to your app's info.plist, which /// cannot be modified at runtime. However, you can change the file during build time via /// Electron Forge, /// Electron Packager, or by editing info.plist /// with a text editor. Please refer to /// Apple's documentation /// for details. /// /// Note: In a Windows Store environment (when packaged as an appx) this API will return true for all calls but /// the registry key it sets won't be accessible by other applications. In order to register your Windows Store /// application as a default protocol handler you must declare the protocol in your manifest. /// /// The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme internally. /// /// /// The name of your protocol, without ://. For example, if you want your app to handle electron:// links, /// call this method with electron as the parameter. /// The cancellation token. /// Whether the call succeeded. Task SetAsDefaultProtocolClientAsync(string protocol, CancellationToken cancellationToken = default); /// /// Sets the current executable as the default handler for a protocol (aka URI scheme). It allows you to /// integrate your app deeper into the operating system. Once registered, all links with your-protocol:// /// will be opened with the current executable. The whole link, including protocol, will be passed to your /// application as a parameter. /// /// Note: On macOS, you can only register protocols that have been added to your app's info.plist, which /// cannot be modified at runtime. However, you can change the file during build time via /// Electron Forge, /// Electron Packager, or by editing info.plist /// with a text editor. Please refer to /// Apple's documentation /// for details. /// /// Note: In a Windows Store environment (when packaged as an appx) this API will return true for all calls but /// the registry key it sets won't be accessible by other applications. In order to register your Windows Store /// application as a default protocol handler you must declare the protocol in your manifest. /// /// The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme internally. /// /// /// The name of your protocol, without ://. For example, if you want your app to handle electron:// links, /// call this method with electron as the parameter. /// The path to the Electron executable. Defaults to process.execPath /// The cancellation token. /// Whether the call succeeded. Task SetAsDefaultProtocolClientAsync(string protocol, string path, CancellationToken cancellationToken = default); /// /// Sets the current executable as the default handler for a protocol (aka URI scheme). It allows you to /// integrate your app deeper into the operating system. Once registered, all links with your-protocol:// /// will be opened with the current executable. The whole link, including protocol, will be passed to your /// application as a parameter. /// /// Note: On macOS, you can only register protocols that have been added to your app's info.plist, which /// cannot be modified at runtime. However, you can change the file during build time via /// Electron Forge, /// Electron Packager, or by editing info.plist /// with a text editor. Please refer to /// Apple's documentation /// for details. /// /// Note: In a Windows Store environment (when packaged as an appx) this API will return true for all calls but /// the registry key it sets won't be accessible by other applications. In order to register your Windows Store /// application as a default protocol handler you must declare the protocol in your manifest. /// /// The API uses the Windows Registry and LSSetDefaultHandlerForURLScheme internally. /// /// /// The name of your protocol, without ://. For example, if you want your app to handle electron:// links, /// call this method with electron as the parameter. /// The path to the Electron executable. Defaults to process.execPath /// Arguments passed to the executable. Defaults to an empty array. /// The cancellation token. /// Whether the call succeeded. Task SetAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default); /// /// This method checks if the current executable as the default handler for a protocol (aka URI scheme). /// If so, it will remove the app as the default handler. /// /// The name of your protocol, without ://. /// The cancellation token. /// Whether the call succeeded. Task RemoveAsDefaultProtocolClientAsync(string protocol, CancellationToken cancellationToken = default); /// /// This method checks if the current executable as the default handler for a protocol (aka URI scheme). /// If so, it will remove the app as the default handler. /// /// The name of your protocol, without ://. /// Defaults to process.execPath. /// The cancellation token. /// Whether the call succeeded. Task RemoveAsDefaultProtocolClientAsync(string protocol, string path, CancellationToken cancellationToken = default); /// /// This method checks if the current executable as the default handler for a protocol (aka URI scheme). /// If so, it will remove the app as the default handler. /// /// The name of your protocol, without ://. /// Defaults to process.execPath. /// Defaults to an empty array. /// The cancellation token. /// Whether the call succeeded. Task RemoveAsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default); /// /// This method checks if the current executable is the default handler for a protocol (aka URI scheme). /// /// Note: On macOS, you can use this method to check if the app has been registered as the default protocol /// handler for a protocol. You can also verify this by checking ~/Library/Preferences/com.apple.LaunchServices.plist /// on the macOS machine. Please refer to Apple's documentation /// for details. /// /// The API uses the Windows Registry and LSCopyDefaultHandlerForURLScheme internally. /// /// The name of your protocol, without ://. /// The cancellation token. /// Whether the current executable is the default handler for a protocol (aka URI scheme). Task IsDefaultProtocolClientAsync(string protocol, CancellationToken cancellationToken = default); /// /// This method checks if the current executable is the default handler for a protocol (aka URI scheme). /// /// Note: On macOS, you can use this method to check if the app has been registered as the default protocol /// handler for a protocol. You can also verify this by checking ~/Library/Preferences/com.apple.LaunchServices.plist /// on the macOS machine. Please refer to Apple's documentation /// for details. /// /// The API uses the Windows Registry and LSCopyDefaultHandlerForURLScheme internally. /// /// The name of your protocol, without ://. /// Defaults to process.execPath. /// The cancellation token. /// Whether the current executable is the default handler for a protocol (aka URI scheme). Task IsDefaultProtocolClientAsync(string protocol, string path, CancellationToken cancellationToken = default); /// /// This method checks if the current executable is the default handler for a protocol (aka URI scheme). /// /// Note: On macOS, you can use this method to check if the app has been registered as the default protocol /// handler for a protocol. You can also verify this by checking ~/Library/Preferences/com.apple.LaunchServices.plist /// on the macOS machine. Please refer to Apple's documentation /// for details. /// /// The API uses the Windows Registry and LSCopyDefaultHandlerForURLScheme internally. /// /// The name of your protocol, without ://. /// Defaults to process.execPath. /// Defaults to an empty array. /// The cancellation token. /// Whether the current executable is the default handler for a protocol (aka URI scheme). Task IsDefaultProtocolClientAsync(string protocol, string path, string[] args, CancellationToken cancellationToken = default); /// /// Adds tasks to the category of the JumpList on Windows. /// /// Note: If you'd like to customize the Jump List even more use instead. /// /// Array of objects. /// The cancellation token. /// Whether the call succeeded. Task SetUserTasksAsync(UserTask[] userTasks, CancellationToken cancellationToken = default); /// /// Jump List settings for the application. /// /// The cancellation token. /// Jump List settings. Task GetJumpListSettingsAsync(CancellationToken cancellationToken = default); /// /// Sets or removes a custom Jump List for the application. If categories is null the previously set custom /// Jump List (if any) will be replaced by the standard Jump List for the app (managed by Windows). /// /// Note: If a object has neither the nor /// the property set then its is assumed /// to be . If the property is set but /// the property is omitted then the is /// assumed to be . /// /// Note: Users can remove items from custom categories, and Windows will not allow a removed item to be added /// back into a custom category until after the next successful call to . Any attempt /// to re-add a removed item to a custom category earlier than that will result in the entire custom category being /// omitted from the Jump List. The list of removed items can be obtained using . /// /// Array of objects. void SetJumpList(JumpListCategory[] categories); /// /// The return value of this method indicates whether or not this instance of your application successfully obtained /// the lock. If it failed to obtain the lock, you can assume that another instance of your application is already /// running with the lock and exit immediately. /// /// I.e.This method returns if your process is the primary instance of your application and your /// app should continue loading. It returns if your process should immediately quit as it has /// sent its parameters to another instance that has already acquired the lock. /// /// On macOS, the system enforces single instance automatically when users try to open a second instance of your app /// in Finder, and the open-file and open-url events will be emitted for that.However when users start your app in /// command line, the system's single instance mechanism will be bypassed, and you have to use this method to ensure /// single instance. /// /// Lambda with an array of the second instance’s command line arguments. /// The second parameter is the working directory path. /// The cancellation token. /// This method returns false if your process is the primary instance of the application and your app /// should continue loading. And returns true if your process has sent its parameters to another instance, and /// you should immediately quit. /// Task RequestSingleInstanceLockAsync(Action newInstanceOpened, CancellationToken cancellationToken = default); /// /// Releases all locks that were created by makeSingleInstance. This will allow /// multiple instances of the application to once again run side by side. /// void ReleaseSingleInstanceLock(); /// /// This method returns whether or not this instance of your app is currently holding the single instance lock. /// You can request the lock with and release with /// . /// /// The cancellation token. Task HasSingleInstanceLockAsync(CancellationToken cancellationToken = default); /// /// Creates an NSUserActivity and sets it as the current activity. The activity is /// eligible for Handoff /// to another device afterward. /// /// Uniquely identifies the activity. Maps to NSUserActivity.activityType. /// App-specific state to store for use by another device. void SetUserActivity(string type, object userInfo); /// /// Creates an NSUserActivity and sets it as the current activity. The activity is /// eligible for Handoff /// to another device afterward. /// /// /// Uniquely identifies the activity. Maps to NSUserActivity.activityType. /// /// App-specific state to store for use by another device. /// /// The webpage to load in a browser if no suitable app is installed on the resuming device. The scheme must be http or https. /// void SetUserActivity(string type, object userInfo, string webpageUrl); /// /// The type of the currently running activity. /// /// The cancellation token. Task GetCurrentActivityTypeAsync(CancellationToken cancellationToken = default); /// /// Invalidates the current Handoff user activity. /// void InvalidateCurrentActivity(); /// /// Marks the current Handoff user activity as inactive without invalidating it. /// void ResignCurrentActivity(); /// /// Changes the Application User Model ID to id. /// /// Model Id. void SetAppUserModelId(string id); /// TODO: Check new parameter which is a function [App.ImportCertificate] /// /// Imports the certificate in pkcs12 format into the platform certificate store. /// callback is called with the result of import operation, a value of 0 indicates /// success while any other value indicates failure according to chromium net_error_list. /// /// /// The cancellation token. /// Result of import. Value of 0 indicates success. Task ImportCertificateAsync(ImportCertificateOptions options, CancellationToken cancellationToken = default); /// /// Memory and cpu usage statistics of all the processes associated with the app. /// /// /// Array of ProcessMetric objects that correspond to memory and cpu usage /// statistics of all the processes associated with the app. /// The cancellation token. /// Task GetAppMetricsAsync(CancellationToken cancellationToken = default); /// /// The Graphics Feature Status from chrome://gpu/. /// /// Note: This information is only usable after the gpu-info-update event is emitted. /// The cancellation token. /// Task GetGpuFeatureStatusAsync(CancellationToken cancellationToken = default); /// /// Sets the counter badge for current app. Setting the count to 0 will hide the badge. /// On macOS it shows on the dock icon. On Linux it only works for Unity launcher. /// /// Note: Unity launcher requires the existence of a .desktop file to work, for more /// information please read Desktop Environment Integration. /// /// Counter badge. /// The cancellation token. /// Whether the call succeeded. Task SetBadgeCountAsync(int count, CancellationToken cancellationToken = default); /// /// The current value displayed in the counter badge. /// /// The cancellation token. Task GetBadgeCountAsync(CancellationToken cancellationToken = default); /// /// Whether the current desktop environment is Unity launcher. /// /// The cancellation token. Task IsUnityRunningAsync(CancellationToken cancellationToken = default); /// /// If you provided path and args options to then you need to pass the same /// arguments here for to be set correctly. /// Task GetLoginItemSettingsAsync(CancellationToken cancellationToken = default); /// /// If you provided path and args options to then you need to pass the same /// arguments here for to be set correctly. /// /// /// The cancellation token. Task GetLoginItemSettingsAsync(LoginItemSettingsOptions options, CancellationToken cancellationToken = default); /// /// Set the app's login item settings. /// To work with Electron's autoUpdater on Windows, which uses Squirrel, /// you'll want to set the launch path to Update.exe, and pass arguments that specify your application name. /// /// void SetLoginItemSettings(LoginSettings loginSettings); /// /// if Chrome's accessibility support is enabled, otherwise. This API will /// return if the use of assistive technologies, such as screen readers, has been detected. /// See Chromium's accessibility docs for more details. /// /// if Chrome’s accessibility support is enabled, otherwise. Task IsAccessibilitySupportEnabledAsync(CancellationToken cancellationToken = default); /// /// Manually enables Chrome's accessibility support, allowing to expose accessibility switch to users in application settings. /// See Chromium's accessibility docs for more details. /// Disabled () by default. /// /// This API must be called after the event is emitted. /// /// Note: Rendering accessibility tree can significantly affect the performance of your app. It should not be enabled by default. /// /// Enable or disable accessibility tree rendering. void SetAccessibilitySupportEnabled(bool enabled); /// /// Show the app's about panel options. These options can be overridden with /// . /// void ShowAboutPanel(); /// /// Set the about panel options. This will override the values defined in the app's .plist file on macOS. See the /// Apple docs /// for more details. On Linux, values must be set in order to be shown; there are no defaults. /// /// If you do not set credits but still wish to surface them in your app, AppKit will look for a file named "Credits.html", /// "Credits.rtf", and "Credits.rtfd", in that order, in the bundle returned by the NSBundle class method main. The first file /// found is used, and if none is found, the info area is left blank. See Apple /// documentation for more information. /// /// About panel options. void SetAboutPanelOptions(AboutPanelOptions options); /// /// Subscribe to an unmapped event on the module. /// /// The event name /// The handler void On(string eventName, Action fn); /// /// Subscribe to an unmapped event on the module. /// /// The event name /// The handler void On(string eventName, Action fn); /// /// Subscribe to an unmapped event on the module once. /// /// The event name /// The handler void Once(string eventName, Action fn); /// /// Subscribe to an unmapped event on the module once. /// /// The event name /// The handler void Once(string eventName, Action fn); } }