The following modules in Electron are available to both the main process and the renderer process:

The module describe
clipboard Provides methods for copy and paste operations
crashReporter Enable sending app crash reports
nativeImage inelectronThe image can be obtained from the file path or usednativeImageobject
screen Retrieves information about screen size, display, mouse position, etc
shell Provides the ability to correlate with other desktop clients

The clipboard module

The Clipboard module provides methods for copy-and-paste operations.

Example:

For example, to write a string to Clipboard:

const clipboard = require('electron').clipboard;
clipboard.writeText('xkd');

The Clipboard module has the following methods:

methods describe
readText In plain text form fromclipboardReturns the content
readText In plain text form fromclipboardReturns the content
writeText In plain text toclipboardAdd content
readHtml returnclipboardTag content in the
readHtml returnclipboardTag content in the
writeHtml toclipboardaddmarkupcontent
writeHtml toclipboardaddmarkupcontent
readImage fromclipboardIn returnNativeImagecontent
writeImage toclipboardwritesimage
readRtf from clipboardIn returnRTFcontent
writeRtf toclipboardwritesRTFThe format oftext
clear emptyclipboardcontent
availableFormats returnclipboardAn array of supported formats
has returnclipboardSupport for specifyingdataThe format of the
read readclipboarddata
write toclipboardwritedata

CrashReporter module

The CrashReporter module is enabled to send application crash reports.

Example:

For example, auto-submit a crash report to the server:

const crashReporter = require('electron').crashReporter;

crashReporter.start({
  productName: 'my_electron',
  companyName: 'shushuo',
  submitURL: 'https://9xkd.com/url-to-submit',
  autoSubmit: true
});

The Crash-Reporter module has the following methods:

methods describe
start In use of otherscrashReporter APIsBefore using
getLastCrashReport Returns the date and date of the last crash reportIDIf no crash report has been sent, or if crash report collection has not started, it will be returnednull
getUploadedReports Returns all uploaded crash reports, each containing the upload date andID

NativeImage module

We can get an image in Electron either by the path to the file or by using a nativeImage object.

Example:

For example, when creating a tray or setting an icon for a window, you can use a string image path:

var appIcon = new Tray('/Users/somebody/images/icon.png');
var window = new BrowserWindow({icon: '/Users/somebody/images/window.png'});

Or read the image from the clipboard:

var image = clipboard.readImage();
var appIcon = new Tray(image);

PNG and JPEG image formats are currently supported. It is best to use the PNG format because it supports transparency and lossless compression. The ICO icon format is also available in Windows.

The NativeImage class has the following methods:

methods describe
createEmpty Create an empty onenativeImageThe instance
createFromPath From the specifiedpathCreate a new onenativeImageThe instance
createFromBuffer frombufferCreate a new onenativeImageInstance, defaultscaleFactorIs 1.0
CreateFromDataURL from dataURL Create a new onenativeImageThe instance

Screen module

Screen module is an EventEmitter that retrieves screen size, display, mouse position, etc. The app module cannot be used until its ready event is triggered.

Example:

For example, let’s create a window that fills the entire screen:

const electron = require('electron');
const app = electron.app;
const BrowserWindow = electron.BrowserWindow;

var mainWindow;

app.on('ready', function() {
  var electronScreen = electron.screen;
  var size = electronScreen.getPrimaryDisplay().workAreaSize;
  mainWindow = new BrowserWindow({ width: size.width, height: size.height });
});

The Screen module has the following events:

The event describe
display-added When adding thenewDisplayEmit event when
display-removed When moving outoldDisplayEmit event when
display-metrics-changed When adisplayOne or more of thesemetricsAn event is emitted when the change occurs

The Screen module has the following method:

methods describe
getCursorScreenPoint Returns the absolute path of the current mouse
getPrimaryDisplay Return to the primarydisplay
getAllDisplays Returns a currently availabledisplayAn array of
getDisplayMatching Returns the one most closely related to the provided boundary rangedisplay
getDisplayNearestPoint Returns the nearest to the specified pointdisplay

Shell module

The shell module provides the associated functionality to integrate with other desktop clients.

Example:

Open the URL in the user default browser:

var shell = require('shell');
shell.openExternal('https://www.9xkd.com/');

The shell module’s method looks like this:

methods describe
showItemInFolde Open the folder where the file resides, which is normally selected as well
openIte Open the file with default open mode
openExterna Turn on external protocols with system default Settings
moveItemToTra Deletes the specified path file and returns the status value of this operation (Boolean type)
beep Play BEEP sound