The following are the modules that can be used by both the main process and the rendering process Electron
Module | description |
---|---|
clipboard | Provide methods for copy and paste operations |
crashReporter | Turn on sending app crash reports |
nativeImage | To electron , you can use the path of the file or use the nativeImage object |
screen | Retrieve information such as screen size, display, mouse position, etc. |
shell | Provides 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:
method | description |
---|---|
readText | Return content clipboard in plain text |
readText | Return content clipboard in plain text |
writeText | Add content clipboard in plain text |
readHtml | Back to content tagged in clipboard |
readHtml | Back to content tagged in clipboard |
writeHtml | Add markup content to clipboard |
writeHtml | Add markup content to clipboard |
readImage | Return NativeImage content from clipboard |
writeImage | To clipboard writing image |
readRtf | Return RTF content from clipboard |
writeRtf | To clipboard writing RTF format text |
clear | Clear clipboard content |
availableFormats | Returns the format array supported by clipboard |
has | Returns clipboard supports the format specified by data |
read | Read clipboard of data |
write | To 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:
method | description |
---|---|
start | Use before using crashReporter APIs |
getLastCrashReport | Return 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 |
getUploadedReports | Return 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:
method | description |
---|---|
createEmpty | Create an empty nativeImage instance |
createFromPath | Create a new instance nativeImage from the specified path |
createFromBuffer | Create a new nativeImage instance from buffer , the default scaleFactor is 1.0 |
createFromDataURL from dataURL | Create 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:
event | description |
---|---|
display-added | Emit event when newDisplay |
display-removed | Event is emitted when oldDisplay |
display-metrics-changed | display an event when one or more of metrics |
screen
module is as follows:
method | description |
---|---|
getCursorScreenPoint | Returns the absolute path of the current mouse |
getPrimaryDisplay | Return to the main display |
getAllDisplays | Returns an array of display |
getDisplayMatching | display is most closely related to the provided boundary range |
getDisplayNearestPoint | display 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:
method | description |
---|---|
showItemInFolde | Open the folder where the file is located, and generally select it |
openIte | Open the file with the default open method |
openExterna | Open the external protocol with the system default settings |
moveItemToTra | Delete the specified path file, and return the status value of this operation (boolean type) |
beep | Play beep sound |
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。