From 4e5c5aec6d36f6090e7934a41fbd89a97e5e519f Mon Sep 17 00:00:00 2001 From: shixh4 Date: Thu, 2 Nov 2023 10:31:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 14 +++++++++++++- preload.js | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/main.js b/main.js index 4155c51..3cf6fcc 100644 --- a/main.js +++ b/main.js @@ -4,22 +4,34 @@ const path = require('path') // electorn const createWindow = () => { + // Create the browser window. const win = new BrowserWindow({ width: 800, height: 600, webPreferences: { preload: path.join(__dirname, 'preload.js') - } + } }) + // 加载 index.html win.loadFile('index.html') + // 打开开发工具 + // mainWindow.webContents.openDevTools() } +// 这段程序将会在 Electron 结束初始化 +// 和创建浏览器窗口的时候调用 +// 部分 API 在 ready 事件触发后才能使用。 app.whenReady().then(() => { createWindow() + // 在 macOS 系统内, 如果没有已开启的应用窗口 + // 点击托盘图标时通常会重新创建一个新窗口 app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow() }) }) +// 除了 macOS 外,当所有窗口都被关闭的时候退出程序。 因此, 通常 +// 对应用程序和它们的菜单栏来说应该时刻保持激活状态, +// 直到用户使用 Cmd + Q 明确退出 app.on('window-all-closed', () => { if (process.platform !== 'darwin') app.quit() }) \ No newline at end of file diff --git a/preload.js b/preload.js index d5614df..a7bd987 100644 --- a/preload.js +++ b/preload.js @@ -1,3 +1,5 @@ +// 所有的 Node.js API接口 都可以在 preload 进程中被调用. +// 它拥有与Chrome扩展一样的沙盒。 window.addEventListener('DOMContentLoaded', () => { const replaceText = (selector, text) => { const element = document.getElementById(selector)