From b031c05af7a870a05d7dd2b2b4f5f5fd4fdc3428 Mon Sep 17 00:00:00 2001 From: "583641232@qq.com" <583641232@qq.com> Date: Tue, 9 Jul 2024 09:09:08 +0800 Subject: [PATCH] :sparkles: go --- main.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 9ac2c55..96480aa 100644 --- a/main.js +++ b/main.js @@ -1,13 +1,14 @@ // Modules to control application life and create native browser window -const { app, BrowserWindow } = require('electron') +const { app, BrowserWindow ,dialog} = require('electron') const { execSync } = require('child_process'); const path = require('node:path') function createWindow () { // Create the browser window. const mainWindow = new BrowserWindow({ - width: 1600, - height: 1000, + width: 1300, + height: 800, + // frame: false, icon: path.join(__dirname, 'icon.ico'), webPreferences: { preload: path.join(__dirname, 'preload.js'), @@ -18,18 +19,40 @@ function createWindow () { mainWindow.setMenu(null); // and load the index.html of the app. //mainWindow.loadFile('index.html') + // window.isElectron = true; mainWindow.loadFile('./dist/index.html') + // Open the DevTools. + // mainWindow.webContents.openDevTools() + mainWindow.on('close', e => { + const choice = dialog.showMessageBoxSync(mainWindow, { + type: 'info', + buttons: ['取消', '确认'], + title: '提示', + message: '确定要退出系统吗?', + defaultId: 0, // 默认选中“取消”按钮 + cancelId: 1, // 按下 Esc 键时的默认行为是“取消” + }) + const leave = choice === 0; + if (!leave) { - // Open the DevTools. - //mainWindow.webContents.openDevTools() + } else { + // 点击取消按钮 + e.preventDefault(); + } + }) + + mainWindow.on('closed', () => { + app.quit() // 关闭应用程序 + }) } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.whenReady().then(() => { + createWindow() app.on('activate', function () { @@ -71,5 +94,6 @@ app.on('before-quit', () => { + // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here.