Working with the shell

The shell module provides functionalities that are related to the native desktop integrations. You can use this module to manage the files and URLs using the default application. For example, if you want to open a file using its default application, you can use this module. You can also open the URL in the default browser. This gives a deep integration with the operating system. The API is available both in the main process and the renderer process.

For example, you can open a file in native file explorer using the showItemInFolder method of the shell:

const { shell } = require('electron');
// Open the file explorer
shell.showItemInFolder('/Users/Guest/Downloads');

This opens the Downloads folder inside the file explorer or finder on Mac. To open a file with the default application that your file is associated with, you can use openItem method of the shell:

shell.openItem('/Users/Guest/Downloads/file.txt');

To open a link in the system default browser, use the openExternal method:

shell.openExternal('http://www.google.com', {
activate: true // brings the application to the foreground, only available on the mac OS
}, function() {
console.log('Browser opened successfully');
});

A file can be moved to the trash using the moveItemToTrash method, as follows:

let deleted = shell.moveItemToTrash('/Users/Guest/Downloads/file.txt');
if(deleted) {
console.log('File deleted successfully');
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.168.203