The following are the modules that can be used by both the main process and the rendering process Electron

Moduledescription
clipboardProvide methods for copy and paste operations
crashReporterTurn on sending app crash reports
nativeImageTo electron , you can use the path of the file or use the nativeImage object
screenRetrieve information such as screen size, display, mouse position, etc.
shellProvides associated functions that integrate with other desktop clients

clipboard module

clipboard module provides methods for copy and paste operations.

Example:

For example, write a string to clipboard :

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

clipboard module has the following methods:

methoddescription
readTextReturn content clipboard in plain text
readTextReturn content clipboard in plain text
writeTextAdd content clipboard in plain text
readHtmlBack to content tagged in clipboard
readHtmlBack to content tagged in clipboard
writeHtmlAdd markup content to clipboard
writeHtmlAdd markup content to clipboard
readImageReturn NativeImage content from clipboard
writeImageTo clipboard writing image
readRtfReturn RTF content from clipboard
writeRtfTo clipboard writing RTF format text
clearClear clipboard content
availableFormatsReturns the format array supported by clipboard
hasReturns clipboard supports the format specified by data
readRead clipboard of data
writeTo clipboard write data

crashReporter module

crashReporter module is enabled to send application crash reports.

Example:

For example, automatically 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
});

crash-reporter module has the following methods:

methoddescription
startUse before using crashReporter APIs
getLastCrashReportReturn the date of the last crash report and ID . If no crash report has been sent, or the collection of crash reports has not yet started, it will return null
getUploadedReportsReturn all uploaded crash reports, each report contains the upload date and ID

nativeImage module

electron can get pictures in 060dc9509570b1 through the file path or use the nativeImage object.

Example:

For example, when creating a tray or setting window icon, 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 picture from the clipboard:

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

Currently supports PNG and JPEG image formats, it is best to use PNG format, because it supports transparent and lossless compression. In Windows can also be used ICO format icons.

nativeImage class has the following methods:

methoddescription
createEmptyCreate an empty nativeImage instance
createFromPathCreate a new instance nativeImage from the specified path
createFromBufferCreate a new nativeImage instance from buffer , the default scaleFactor is 1.0
createFromDataURL from dataURLCreate a new instance nativeImage

screen module

screen module is a EventEmitter , used to retrieve the size screen, display, mouse position and other information. This module cannot be used before ready app module is triggered.

Example:

For example, we 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 });
});

screen module has the following events:

eventdescription
display-addedEmit event when newDisplay
display-removedEvent is emitted when oldDisplay
display-metrics-changeddisplay an event when one or more of metrics

screen module is as follows:

methoddescription
getCursorScreenPointReturns the absolute path of the current mouse
getPrimaryDisplayReturn to the main display
getAllDisplaysReturns an array of display
getDisplayMatchingdisplay is most closely related to the provided boundary range
getDisplayNearestPointdisplay to the specified point

shell module

shell module provides related functions for integrating other desktop clients.

Example:

URL in the user's default browser:

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

shell module is as follows:

methoddescription
showItemInFoldeOpen the folder where the file is located, and generally select it
openIteOpen the file with the default open method
openExternaOpen the external protocol with the system default settings
moveItemToTraDelete the specified path file, and return the status value of this operation (boolean type)
beepPlay beep sound

知否
221 声望177 粉丝

Skrike while the iron is hot.