共享API (Shared API)
本节重点讲解 process
、screen
、shell
、nativeImage
、clipboard
几个部分内容。
1、process (进程)
1.1 index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline'">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<!-- All of the Node.js APIs are available in this renderer process. -->
We are using Node.js <strong><script>document.write( process.versions.node)</script></strong>,
and Electron <strong><script>document.write( process.versions.electron )</script></strong>.
<br><button type="button" οnclick="process.hang()">Hang Renderer</button>
<br><button type="button" οnclick="process.crash()">Crash Renderer</button>
<script>
// let i = 1
// setInterval(() => {
// console.log(i)
// i++
// }, 500)
</script>
</body>
</html>
1.2 main.js
// Modules
const {app, BrowserWindow} = require('electron')
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let mainWindow
// Create a new BrowserWindow when `app` is ready
function createWindow () {
mainWindow = new BrowserWindow({
width: 1000, height: 800,
webPreferences: { nodeIntegration: true }
})
// Load index.html into the new BrowserWindow
mainWindow.loadFile('index.html')
// Open DevTools - Remove for PRODUCTION!
mainWindow.webContents.openDevTools();
mainWindow.webContents.on( 'crashed', mainWindow.reload )
// Listen for window b