ContentTracing

Electron Api

Collect tracing data from Chromium to find performance bottlenecks and slow operations. Process: Main This module does not include a web interface. To view recorded traces, use trace viewer, available at chrome://tracing in Chrome. Note: You should not use this module until the ready event of the app module is emitted. Methods​ The contentTracing module has the following methods: contentTracing.getCategories()​ Returns Promise<string[]> – resolves with an array of category groups once all child processes have acknowledged the getCategories request Get a set of category groups. The category groups can change as new code paths are reached. See also the list of built-in tracing categories. NOTE: Electron adds a non-default tracing category called “electron”. This category can be used to capture Electron-specific tracing events. contentTracing.startRecording(options)​ Returns Promise<void> – resolved once all child processes have acknowledged the startRecording request. Start recording on all processes. Recording begins immediately locally and asynchronously on child processes as soon as they receive the EnableRecording request. If a recording is already running, the promise will be immediately resolved, as only one trace operation can be in progress at a time. contentTracing.stopRecording([resultFilePath])​ Returns Promise<string> – resolves with a path to a file that contains the traced data once all child processes have acknowledged the stopRecording request Stop recording on all processes. Child processes typically cache trace data and only rarely flush and send trace data back to the main process. This helps to minimize the runtime overhead of tracing since sending trace data over IPC can be an expensive operation. So, to end tracing, Chromium asynchronously asks all child processes to flush any pending trace data. Trace data will be written into resultFilePath. If resultFilePath is empty or not provided, trace data will be written to a temporary file, and the path will be returned in the promise. contentTracing.getTraceBufferUsage()​ Returns Promise<Object> – Resolves with an object containing the value and percentage of trace buffer maximum usage Get the maximum usage across processes of trace buffer as a percentage of the full state.

August 19, 2024 / 0 Comments
read more

Clipboard

Electron Api

Perform copy and paste operations on the system clipboard. Process: Main, Renderer (non-sandboxed only) On Linux, there is also a selection clipboard. To manipulate it you need to pass selection to each method: Methods​ The clipboard module has the following methods: Note: Experimental APIs are marked as such and could be removed in future. clipboard.readText([type])​ Returns string – The content in the clipboard as plain text. clipboard.writeText(text[, type])​ Writes the text into the clipboard as plain text. clipboard.readHTML([type])​ Returns string – The content in the clipboard as markup. clipboard.writeHTML(markup[, type])​ Writes markup to the clipboard. clipboard.readImage([type])​ Returns NativeImage – The image content in the clipboard. clipboard.writeImage(image[, type])​ Writes image to the clipboard. clipboard.readRTF([type])​ Returns string – The content in the clipboard as RTF. clipboard.writeRTF(text[, type])​ Writes the text into the clipboard in RTF. clipboard.readBookmark() macOS Windows​ Returns Object: Returns an Object containing title and url keys representing the bookmark in the clipboard. The title and url values will be empty strings when the bookmark is unavailable. The title value will always be empty on Windows. clipboard.writeBookmark(title, url[, type]) macOS Windows​ Writes the title (macOS only) and url into the clipboard as a bookmark. Note: Most apps on Windows don’t support pasting bookmarks into them so you can use clipboard.write to write both a bookmark and fallback text to the clipboard. clipboard.readFindText() macOS​ Returns string – The text on the find pasteboard, which is the pasteboard that holds information about the current state of the active application’s find panel. This method uses synchronous IPC when called from the renderer process. The cached value is reread from the find pasteboard whenever the application is activated. clipboard.writeFindText(text) macOS​ Writes the text into the find pasteboard (the pasteboard that holds information about the current state of the active application’s find panel) as plain text. This method uses synchronous IPC when called from the renderer process. clipboard.clear([type])​ Clears the clipboard content. clipboard.availableFormats([type])​ Returns string[] – An array of supported formats for the clipboard type. clipboard.has(format[, type]) Experimental​ Returns boolean – Whether the clipboard supports the specified format. clipboard.read(format) Experimental​ Returns string – Reads format type from the clipboard. format should contain valid ASCII characters and have / separator. a/c, a/bc are valid formats while /abc, abc/, a/, /a, a are not valid. clipboard.readBuffer(format) Experimental​ Returns Buffer – Reads format type from the clipboard. clipboard.writeBuffer(format, buffer[, type]) Experimental​ Writes the buffer into the clipboard as format. clipboard.write(data[, type])​ Writes data to the clipboard.

August 19, 2024 / 0 Comments
read more

BrowserWindow

Electron Api

Create and control browser windows. Process: Main This module cannot be used until the ready event of the app module is emitted. Window customization​ The BrowserWindow class exposes various ways to modify the look and behavior of your app’s windows. For more details, see the Window Customization tutorial. Showing the window gracefully​ When loading a page in the window directly, users may see the page load incrementally, which is not a good experience for a native app. To make the window display without a visual flash, there are two solutions for different situations. Using the ready-to-show event​ While loading the page, the ready-to-show event will be emitted when the renderer process has rendered the page for the first time if the window has not been shown yet. Showing the window after this event will have no visual flash: This event is usually emitted after the did-finish-load event, but for pages with many remote resources, it may be emitted before the did-finish-load event. Please note that using this event implies that the renderer will be considered “visible” and paint even though show is false. This event will never fire if you use paintWhenInitiallyHidden: false Setting the backgroundColor property​ For a complex app, the ready-to-show event could be emitted too late, making the app feel slow. In this case, it is recommended to show the window immediately, and use a backgroundColor close to your app’s background: Note that even for apps that use ready-to-show event, it is still recommended to set backgroundColor to make the app feel more native. Some examples of valid backgroundColor values include: For more information about these color types see valid options in win.setBackgroundColor. Parent and child windows​ By using parent option, you can create child windows: The child window will always show on top of the top window. Modal windows​ A modal window is a child window that disables parent window. To create a modal window, you have to set both the parent and modal options: Page visibility​ The Page Visibility API works as follows: It is recommended that you pause expensive operations when the visibility state is hidden in order to minimize power consumption. Platform notices​ Class: BrowserWindow extends BaseWindow​ Create and control browser windows. Process: Main BrowserWindow is an EventEmitter. It creates a new BrowserWindow with native properties as set by the options. new BrowserWindow([options])​ Instance Events​ Objects created with new BrowserWindow emit the following events: Note: Some events are only available on specific operating systems and are labeled as such. Event: ‘page-title-updated’​ Returns: Emitted when the document changed its title, calling event.preventDefault() will prevent the native window’s title from changing. explicitSet is false when title is synthesized from file URL. Event: ‘close’​ Returns: Emitted when the window is going to be closed. It’s emitted before the beforeunload and unload event of the DOM. Calling event.preventDefault() will cancel the close. Usually you would want to use the beforeunload handler to decide whether the window should be closed, which will also be called when the window is reloaded. In Electron, returning any value other than undefined would cancel the close. For example: Note: There is a subtle difference between the behaviors of window.onbeforeunload = handler and window.addEventListener(‘beforeunload’, handler). It is recommended to always set the event.returnValue explicitly, instead of only returning a value, as the former works more consistently within Electron. Event: ‘closed’​ Emitted when the window is closed. After you have received this event you should remove the reference to the window and avoid using it any more. Event: ‘session-end’ Windows​ Emitted when window session is going to end due to force shutdown or machine restart or session log off. Event: ‘unresponsive’​ Emitted when the web page becomes unresponsive. Event: ‘responsive’​ Emitted when the unresponsive web page becomes responsive again. Event: ‘blur’​ Emitted when the window loses focus. Event: ‘focus’​ Emitted when the window gains focus. Event: ‘show’​ Emitted when the window is shown. Event: ‘hide’​ Emitted when the window is hidden. Event: ‘ready-to-show’​ Emitted when the web page has been rendered (while not being shown) and window can be displayed without a visual flash. Please note that using this event implies that the renderer will be considered “visible” and paint even though show is false. This event will never fire if you use paintWhenInitiallyHidden: false Event: ‘maximize’​ Emitted when window is maximized. Event: ‘unmaximize’​ Emitted when the window exits from a maximized state. Event: ‘minimize’​ Emitted when the window is minimized. Event: ‘restore’​ Emitted when the window is restored from a minimized state. Event: ‘will-resize’ macOS Windows​ Returns: Emitted before the window is resized. Calling event.preventDefault() will prevent the window from being resized. Note that this is only emitted when the window is being resized manually. Resizing the window with setBounds/setSize will not emit this event. The possible values and behaviors of the edge option are platform dependent. Possible values are: Event: ‘resize’​ Emitted after the window has been resized. Event: ‘resized’ macOS Windows​ Emitted once when the window has finished being resized. This is usually emitted when the window has been resized manually. On macOS, resizing the window with setBounds/setSize and setting the animate parameter to true will also emit this event once resizing has finished. Event: ‘will-move’ macOS Windows​ Returns: Emitted before the window is moved. On Windows, calling event.preventDefault() will prevent the window from being moved. Note that this is only emitted when the window is being moved manually. Moving the window with setPosition/setBounds/center will not emit this event. Event: ‘move’​ Emitted when the window is being moved to a new position. Event: ‘moved’ macOS Windows​ Emitted once when the window is moved to a new position. Note: On macOS this event is an alias of move. Event: ‘enter-full-screen’​ Emitted when the window enters a full-screen state. Event: ‘leave-full-screen’​ Emitted when the window leaves a full-screen state. Event: ‘enter-html-full-screen’​ Emitted when the window enters a full-screen state triggered by HTML API. Event: ‘leave-html-full-screen’​ Emitted when the window leaves a full-screen state triggered by HTML API. Event: ‘always-on-top-changed’​ Returns: Emitted when the window is set or unset to show always on top of other windows. Event: ‘app-command’ Windows Linux​ Returns: Emitted when an App Command is invoked. These are typically related to keyboard media keys or browser commands, as well as the “Back” button built into some mice on Windows. Commands are lowercased, underscores are replaced with hyphens, and the APPCOMMAND_ prefix is stripped off. e.g. APPCOMMAND_BROWSER_BACKWARD is emitted as browser-backward. The following app commands are explicitly supported on Linux: Event: ‘swipe’ macOS​ Returns: Emitted on 3-finger swipe. Possible directions are up, right, down, left. The method underlying this event is built to handle older macOS-style trackpad swiping, where the content on the screen doesn’t move with the swipe. Most

August 19, 2024 / 0 Comments
read more

BrowserView

Electron Api

Note The BrowserView class is deprecated, and replaced by the new WebContentsView class. A BrowserView can be used to embed additional web content into a BrowserWindow. It is like a child window, except that it is positioned relative to its owning window. It is meant to be an alternative to the webview tag. Class: BrowserView​ Create and control views. Note The BrowserView class is deprecated, and replaced by the new WebContentsView class. Process: Main This module cannot be used until the ready event of the app module is emitted. Example​ new BrowserView([options]) Experimental Deprecated​ Instance Properties​ Objects created with new BrowserView have the following properties: view.webContents Experimental Deprecated​ A WebContents object owned by this view. Instance Methods​ Objects created with new BrowserView have the following instance methods: view.setAutoResize(options) Experimental Deprecated​ view.setBounds(bounds) Experimental Deprecated​ Resizes and moves the view to the supplied bounds relative to the window. view.getBounds() Experimental Deprecated​ Returns Rectangle The bounds of this BrowserView instance as Object. view.setBackgroundColor(color) Experimental Deprecated​ Examples of valid color values: Note: Hex format with alpha takes AARRGGBB or ARGB, not RRGGBBAA or RGB.

August 19, 2024 / 0 Comments
read more

BaseWindow

Electron Api

Create and control windows. Process: Main Note BaseWindow provides a flexible way to compose multiple web views in a single window. For windows with only a single, full-size web view, the BrowserWindow class may be a simpler option. This module cannot be used until the ready event of the app module is emitted. Parent and child windows​ By using parent option, you can create child windows: The child window will always show on top of the parent window. Modal windows​ A modal window is a child window that disables parent window. To create a modal window, you have to set both the parent and modal options: Platform notices​ Class: BaseWindow​ Create and control windows. Process: Main BaseWindow is an EventEmitter. It creates a new BaseWindow with native properties as set by the options. new BaseWindow([options])​ When setting minimum or maximum window size with minWidth/maxWidth/ minHeight/maxHeight, it only constrains the users. It won’t prevent you from passing a size that does not follow size constraints to setBounds/setSize or to the constructor of BrowserWindow. The possible values and behaviors of the type option are platform dependent. Possible values are: Instance Events​ Objects created with new BaseWindow emit the following events: Note: Some events are only available on specific operating systems and are labeled as such. Event: ‘close’​ Returns: Emitted when the window is going to be closed. It’s emitted before the beforeunload and unload event of the DOM. Calling event.preventDefault() will cancel the close. Usually you would want to use the beforeunload handler to decide whether the window should be closed, which will also be called when the window is reloaded. In Electron, returning any value other than undefined would cancel the close. For example: Note: There is a subtle difference between the behaviors of window.onbeforeunload = handler and window.addEventListener(‘beforeunload’, handler). It is recommended to always set the event.returnValue explicitly, instead of only returning a value, as the former works more consistently within Electron. Event: ‘closed’​ Emitted when the window is closed. After you have received this event you should remove the reference to the window and avoid using it any more. Event: ‘session-end’ Windows​ Emitted when window session is going to end due to force shutdown or machine restart or session log off. Event: ‘blur’​ Emitted when the window loses focus. Event: ‘focus’​ Emitted when the window gains focus. Event: ‘show’​ Emitted when the window is shown. Event: ‘hide’​ Emitted when the window is hidden. Event: ‘maximize’​ Emitted when window is maximized. Event: ‘unmaximize’​ Emitted when the window exits from a maximized state. Event: ‘minimize’​ Emitted when the window is minimized. Event: ‘restore’​ Emitted when the window is restored from a minimized state. Event: ‘will-resize’ macOS Windows​ Returns: Emitted before the window is resized. Calling event.preventDefault() will prevent the window from being resized. Note that this is only emitted when the window is being resized manually. Resizing the window with setBounds/setSize will not emit this event. The possible values and behaviors of the edge option are platform dependent. Possible values are: Event: ‘resize’​ Emitted after the window has been resized. Event: ‘resized’ macOS Windows​ Emitted once when the window has finished being resized. This is usually emitted when the window has been resized manually. On macOS, resizing the window with setBounds/setSize and setting the animate parameter to true will also emit this event once resizing has finished. Event: ‘will-move’ macOS Windows​ Returns: Emitted before the window is moved. On Windows, calling event.preventDefault() will prevent the window from being moved. Note that this is only emitted when the window is being moved manually. Moving the window with setPosition/setBounds/center will not emit this event. Event: ‘move’​ Emitted when the window is being moved to a new position. Event: ‘moved’ macOS Windows​ Emitted once when the window is moved to a new position. Note: On macOS this event is an alias of move. Event: ‘enter-full-screen’​ Emitted when the window enters a full-screen state. Event: ‘leave-full-screen’​ Emitted when the window leaves a full-screen state. Event: ‘always-on-top-changed’​ Returns: Emitted when the window is set or unset to show always on top of other windows. Event: ‘app-command’ Windows Linux​ Returns: Emitted when an App Command is invoked. These are typically related to keyboard media keys or browser commands, as well as the “Back” button built into some mice on Windows. Commands are lowercased, underscores are replaced with hyphens, and the APPCOMMAND_ prefix is stripped off. e.g. APPCOMMAND_BROWSER_BACKWARD is emitted as browser-backward. The following app commands are explicitly supported on Linux: Event: ‘swipe’ macOS​ Returns: Emitted on 3-finger swipe. Possible directions are up, right, down, left. The method underlying this event is built to handle older macOS-style trackpad swiping, where the content on the screen doesn’t move with the swipe. Most macOS trackpads are not configured to allow this kind of swiping anymore, so in order for it to emit properly the ‘Swipe between pages’ preference in System Preferences > Trackpad > More Gestures must be set to ‘Swipe with two or three fingers’. Event: ‘rotate-gesture’ macOS​ Returns: Emitted on trackpad rotation gesture. Continually emitted until rotation gesture is ended. The rotation value on each emission is the angle in degrees rotated since the last emission. The last emitted event upon a rotation gesture will always be of value 0. Counter-clockwise rotation values are positive, while clockwise ones are negative. Event: ‘sheet-begin’ macOS​ Emitted when the window opens a sheet. Event: ‘sheet-end’ macOS​ Emitted when the window has closed a sheet. Event: ‘new-window-for-tab’ macOS​ Emitted when the native new tab button is clicked. Event: ‘system-context-menu’ Windows​ Returns: Emitted when the system context menu is triggered on the window, this is normally only triggered when the user right clicks on the non-client area of your window. This is the window titlebar or any area you have declared as -webkit-app-region: drag in a frameless window. Calling event.preventDefault() will prevent the menu from being displayed. Static Methods​ The BaseWindow class has the following static methods: BaseWindow.getAllWindows()​ Returns BaseWindow[] – An array of all opened browser windows. BaseWindow.getFocusedWindow()​ Returns BaseWindow | null – The window that is focused in this application, otherwise returns null. BaseWindow.fromId(id)​ Returns BaseWindow | null – The window with the given id. Instance Properties​ Objects created with new BaseWindow have the following properties: win.id Readonly​ A Integer property representing the unique ID of the window. Each ID is unique among all BaseWindow instances of the entire Electron application. win.contentView​ A View property for the content view of the window. win.tabbingIdentifier macOS Readonly​ A string (optional) property that is equal to the tabbingIdentifier passed to the BrowserWindow constructor or undefined if none was set. win.autoHideMenuBar​ A boolean property that determines whether the window menu bar should hide itself automatically. Once set, the menu bar will only show when users press the single Alt key. If the menu bar is already visible, setting this property to true won’t

August 19, 2024 / 0 Comments
read more

AutoUpdater

Electron Api

Enable apps to automatically update themselves. Process: Main See also: A detailed guide about how to implement updates in your application. autoUpdater is an EventEmitter. Platform Notices​ Currently, only macOS and Windows are supported. There is no built-in support for auto-updater on Linux, so it is recommended to use the distribution’s package manager to update your app. In addition, there are some subtle differences on each platform: macOS​ On macOS, the autoUpdater module is built upon Squirrel.Mac, meaning you don’t need any special setup to make it work. For server-side requirements, you can read Server Support. Note that App Transport Security (ATS) applies to all requests made as part of the update process. Apps that need to disable ATS can add the NSAllowsArbitraryLoads key to their app’s plist. Note: Your application must be signed for automatic updates on macOS. This is a requirement of Squirrel.Mac. Windows​ On Windows, you have to install your app into a user’s machine before you can use the autoUpdater, so it is recommended that you use the electron-winstaller, Electron Forge or the grunt-electron-installer package to generate a Windows installer. When using electron-winstaller or Electron Forge make sure you do not try to update your app the first time it runs (Also see this issue for more info). It’s also recommended to use electron-squirrel-startup to get desktop shortcuts for your app. The installer generated with Squirrel will create a shortcut icon with an Application User Model ID in the format of com.squirrel.PACKAGE_ID.YOUR_EXE_WITHOUT_DOT_EXE, examples are com.squirrel.slack.Slack and com.squirrel.code.Code. You have to use the same ID for your app with app.setAppUserModelId API, otherwise Windows will not be able to pin your app properly in task bar. Like Squirrel.Mac, Windows can host updates on S3 or any other static file host. You can read the documents of Squirrel.Windows to get more details about how Squirrel.Windows works. Events​ The autoUpdater object emits the following events: Event: ‘error’​ Returns: Emitted when there is an error while updating. Event: ‘checking-for-update’​ Emitted when checking if an update has started. Event: ‘update-available’​ Emitted when there is an available update. The update is downloaded automatically. Event: ‘update-not-available’​ Emitted when there is no available update. Event: ‘update-downloaded’​ Returns: Emitted when an update has been downloaded. On Windows only releaseName is available. Note: It is not strictly necessary to handle this event. A successfully downloaded update will still be applied the next time the application starts. Event: ‘before-quit-for-update’​ This event is emitted after a user calls quitAndInstall(). When this API is called, the before-quit event is not emitted before all windows are closed. As a result you should listen to this event if you wish to perform actions before the windows are closed while a process is quitting, as well as listening to before-quit. Methods​ The autoUpdater object has the following methods: autoUpdater.setFeedURL(options)​ Sets the url and initialize the auto updater. autoUpdater.getFeedURL()​ Returns string – The current update feed URL. autoUpdater.checkForUpdates()​ Asks the server whether there is an update. You must call setFeedURL before using this API. Note: If an update is available it will be downloaded automatically. Calling autoUpdater.checkForUpdates() twice will download the update two times. autoUpdater.quitAndInstall()​ Restarts the app and installs the update after it has been downloaded. It should only be called after update-downloaded has been emitted. Under the hood calling autoUpdater.quitAndInstall() will close all application windows first, and automatically call app.quit() after all windows have been closed. Note: It is not strictly necessary to call this function to apply an update, as a successfully downloaded update will always be applied the next time the application starts.

August 19, 2024 / 0 Comments
read more

App

Electron Api

Control your application’s event lifecycle. Process: Main The following example shows how to quit the application when the last window is closed: Events​ The app object emits the following events: Event: ‘will-finish-launching’​ Emitted when the application has finished basic startup. On Windows and Linux, the will-finish-launching event is the same as the ready event; on macOS, this event represents the applicationWillFinishLaunching notification of NSApplication. In most cases, you should do everything in the ready event handler. Event: ‘ready’​ Returns: Emitted once, when Electron has finished initializing. On macOS, launchInfo holds the userInfo of the NSUserNotification or information from UNNotificationResponse that was used to open the application, if it was launched from Notification Center. You can also call app.isReady() to check if this event has already fired and app.whenReady() to get a Promise that is fulfilled when Electron is initialized. Note: The ready event is only fired after the main process has finished running the first tick of the event loop. If an Electron API needs to be called before the ready event, ensure that it is called synchronously in the top-level context of the main process. Event: ‘window-all-closed’​ 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 app.quit(), Electron will first try to close all the windows and then emit the will-quit event, and in this case the window-all-closed event would not be emitted. Event: ‘before-quit’​ Returns: Emitted before the application starts closing its windows. Calling event.preventDefault() will prevent the default behavior, which is terminating the application. Note: If application quit was initiated by autoUpdater.quitAndInstall(), then before-quit 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: ‘will-quit’​ Returns: Emitted when all windows have been closed and the application will quit. Calling event.preventDefault() will prevent the default behavior, which is terminating the application. See the description of the window-all-closed event for the differences between the will-quit and window-all-closed 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: ‘quit’​ Returns: 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: ‘open-file’ macOS​ Returns: Emitted when the 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. Make sure to listen for the open-file event very early in your application startup to handle this case (even before the ready event is emitted). You should call event.preventDefault() if you want to handle this event. On Windows, you have to parse process.argv (in the main process) to get the filepath. Event: ‘open-url’ macOS​ Returns: Emitted when the 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. As with the open-file event, be sure to register a listener for the open-url event early in your application startup to detect if the application is being opened to handle a URL. If you register the listener in response to a ready event, you’ll miss URLs that trigger the launch of your application. Event: ‘activate’ macOS​ Returns: Emitted when the application is activated. Various actions can trigger this event, such as launching the application for the first time, attempting to re-launch the application when it’s already running, or clicking on the application’s dock or taskbar icon. Event: ‘did-become-active’ macOS​ Returns: Emitted when the application becomes active. This differs from the activate event in that did-become-active is emitted every time the app becomes active, not only when Dock icon is clicked or application is re-launched. It is also emitted when a user switches to the app via the macOS App Switcher. Event: ‘did-resign-active’ macOS​ Returns: Emitted when the app is no longer active and doesn’t have focus. This can be triggered, for example, by clicking on another application or by using the macOS App Switcher to switch to another application. Event: ‘continue-activity’ macOS​ Returns: Emitted during Handoff when an activity from a different device wants to be resumed. You should call event.preventDefault() if you want to handle this event. A user activity can be continued only in an app that has the same developer Team ID as the activity’s source app and that supports the activity’s type. Supported activity types are specified in the app’s Info.plist under the NSUserActivityTypes key. Event: ‘will-continue-activity’ macOS​ Returns: Emitted during Handoff before an activity from a different device wants to be resumed. You should call event.preventDefault() if you want to handle this event. Event: ‘continue-activity-error’ macOS​ Returns: Emitted during Handoff when an activity from a different device fails to be resumed. Event: ‘activity-was-continued’ macOS​ Returns: Emitted during Handoff after an activity from this device was successfully resumed on another one. Event: ‘update-activity-state’ macOS​ Returns: Emitted when Handoff is about to be resumed on another device. If you need to update the state to be transferred, you should call event.preventDefault() immediately, construct a new userInfo dictionary and call app.updateCurrentActivity() in a timely manner. Otherwise, the operation will fail and continue-activity-error will be called. Event: ‘new-window-for-tab’ macOS​ Returns: Emitted when the user clicks the native macOS new tab button. The new tab button is only visible if the current BrowserWindow has a tabbingIdentifier Event: ‘browser-window-blur’​ Returns: Emitted when a browserWindow gets blurred. Event: ‘browser-window-focus’​ Returns: Emitted when a browserWindow gets focused. Event: ‘browser-window-created’​ Returns: Emitted when a new browserWindow is created. Event: ‘web-contents-created’​ Returns: Emitted when a new webContents is created. Event: ‘certificate-error’​ Returns: Emitted when failed to verify the certificate for url, to trust the certificate you should prevent the default behavior with event.preventDefault() and call callback(true). Event: ‘select-client-certificate’​ Returns: Emitted when a client certificate is requested. The url corresponds to the navigation entry requesting the client certificate and callback can be called with an entry filtered from the list. Using event.preventDefault() prevents the application from using the first certificate from the store. Event: ‘login’​ Returns: Emitted when webContents wants to do basic auth. The default behavior is to cancel all authentications. To override this you should prevent the default behavior with event.preventDefault() and call callback(username, password) with the credentials. If callback is called without a username or password, the authentication request will be cancelled

August 19, 2024 / 0 Comments
read more

 Resources

Electron

We have used the following resources to learn more about Electron. We have referred to these while creating this tutorial. The most important resource is the Electron documentation. The Documentation has extensive coverage of almost all features and quirks of the framework. They are alone enough to make your way through building an app. There are also some very good Electron examples presented in the electron-sample-apps respository. Video Resources Desktop apps with web languages Rapid cross platform desktop app development using JavaScript and Electron Blog Posts Building a desktop application with Electron Build a Music Player with React & Electron Creating Your First Desktop App With HTML, JS and Electron Create Cross-Platform Desktop Node Apps with Electron

August 19, 2024 / 0 Comments
read more

Packaging Apps

Electron

Packaging and distributing apps is an integral part of the development process of a desktop application. Since Electron is a cross-platform desktop application development framework, packaging and distribution of apps for all the platforms should also be a seamless experience. The electron community has created a project, electron-packager that takes care of the same for us. It allows us to package and distribute our Electron app with OS-specific bundles (.app, .exe etc) via JS or CLI. Supported Platforms Electron Packager runs on the following host platforms − It generates executables/bundles for the following target platforms − Installation Install the electron packager using − Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career. Packaging Apps In this section, we will see how to run the packager from the command line. The basic form of the command is − This will − –platform and –arch can be omitted, in two cases. If you specify –all instead, bundles for all valid combinations of target platforms/architectures will be created. Otherwise, a single bundle for the host platform/architecture will be created.

August 19, 2024 / 0 Comments
read more

Debugging

Electron

We have two processes that run our application – the main process and the renderer process. Since the renderer process is the one being executed in our browser window, we can use the Chrome Devtools to debug it. To open DevTools, use the shortcut “Ctrl+Shift+I” or the <F12> key. You can check out how to use devtools here. When you open the DevTools, your app will look like as shown in the following screenshot − Debugging the Main Process The DevTools in an Electron browser window can only debug JavaScript that is executed in that window (i.e., the web pages). To debug JavaScript that is executed in the main process you will need to use an external debugger and launch Electron with the –debug or the –debug-brk switch. Electron will listen for the V8 debugger protocol messages on the specified port; an external debugger will need to connect on this port. The default port is 5858. Run your app using the following − Now you will need a debugger that supports the V8 debugger protocol. You can use VSCode or node-inspector for this purpose. For example, let us follow these steps and set up VSCode for this purpose. Follow these steps to set it up − Download and install VSCode. Open your Electron project in VSCode. Add a file .vscode/launch.json with the following configuration − Note − For Windows, use “${workspaceRoot}/node_modules/.bin/electron.cmd” for runtimeExecutable. Set some breakpoints in main.js, and start debugging in the Debug View. When you hit the breakpoints, the screen will look something like this − The VSCode debugger is very powerful and will help you rectify errors quickly. You also have other options like node-inspector for debugging electron apps.

August 19, 2024 / 0 Comments
read more

Posts pagination

Previous 1 … 433 434 435 … 445 Next