From fee681fcca45bf6bfcaea0536836744e97d79690 Mon Sep 17 00:00:00 2001 From: Dong Xia Date: Mon, 30 Dec 2024 15:18:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{app.vue => App.vue} | 79 +++++++++++++++++++--------------------- src/background.js | 58 ++++++++++++++++------------- 2 files changed, 70 insertions(+), 67 deletions(-) rename src/{app.vue => App.vue} (81%) diff --git a/src/app.vue b/src/App.vue similarity index 81% rename from src/app.vue rename to src/App.vue index e92f45f..fb0a01f 100644 --- a/src/app.vue +++ b/src/App.vue @@ -1,42 +1,37 @@ - - - - - + + + + + diff --git a/src/background.js b/src/background.js index 8fe8996..5715d1f 100644 --- a/src/background.js +++ b/src/background.js @@ -4,14 +4,17 @@ import { app, protocol, BrowserWindow, Menu, globalShortcut } from 'electron' import { createProtocol } from 'vue-cli-plugin-electron-builder/lib' const isDevelopment = process.env.NODE_ENV !== 'production' -const path = require('path') +const path = require('path'); + +let mainWin = null let toOpenDevTools = null + protocol.registerSchemesAsPrivileged([ - { scheme: 'app', privileges: { secure: true, standard: true }} + { scheme: 'app', privileges: { secure: true, standard: true } } ]) -let mainWin = null + async function createWindow() { - try{ + try { mainWin = new BrowserWindow({ width: 1400, height: 1000, @@ -19,18 +22,18 @@ async function createWindow() { backgroundColor: '#2e2c29', title: '系统软件安装管理平台', webPreferences: { - nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION, - contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION, - webSecurity: false + nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION === 'true', + contextIsolation: process.env.ELECTRON_NODE_INTEGRATION !== 'true', + webSecurity: true } }) - const menuTemplate = Menu.buildFromTemplate([ + + // 设置菜单栏 + const menuTemplate = [ { label: '返回&(Ctrl+B)', accelerator: 'Ctrl+B', - click: () => { - mainWin.webContents.goBack() - } + click: () => mainWin.webContents.goBack() }, { label: '全屏&(Ctrl+F)', @@ -47,41 +50,46 @@ async function createWindow() { accelerator: 'Ctrl+S', role: 'reload' } - ]) - Menu.setApplicationMenu(menuTemplate) + ]; + Menu.setApplicationMenu(Menu.buildFromTemplate(menuTemplate)) + + // 显示窗口 mainWin.once('ready-to-show', () => { mainWin.maximize() mainWin.show() }) + + // 加载页面 createProtocol('app') mainWin.loadURL('app://./index.html') - toOpenDevTools = function() { - mainWin.webContents.openDevTools() - } - } catch(error) { - console.log(error) + + // 打开开发者工具 + toOpenDevTools = () => mainWin.webContents.openDevTools() + } catch (error) { + console.error('Failed to create window:', error) } } +// 监听应用事件 app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit() } }) + app.whenReady().then(() => { - globalShortcut.register('ctrl+shift+alt+d', () => { - toOpenDevTools() - }) + globalShortcut.register('ctrl+shift+alt+d', toOpenDevTools) }) app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) createWindow() + if (BrowserWindow.getAllWindows().length === 0) { + createWindow() + } }) -app.on('ready', async() => { - createWindow() -}) +app.on('ready', createWindow) +// 开发环境下的优雅退出 if (isDevelopment) { if (process.platform === 'win32') { process.on('message', (data) => { -- Gitee From 2fb30eaad96908315599aa6f351cc151818f089d Mon Sep 17 00:00:00 2001 From: Dong Xia Date: Mon, 30 Dec 2024 15:25:38 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8A=82=E7=82=B9?= =?UTF-8?q?=E8=BD=AF=E4=BB=B6=E6=BA=90=E9=85=8D=E7=BD=AE=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/node-source.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/store/modules/node-source.js b/src/store/modules/node-source.js index 4e354bb..b6049d9 100644 --- a/src/store/modules/node-source.js +++ b/src/store/modules/node-source.js @@ -2,27 +2,33 @@ const nodeSource = { state: { // 存放节点,检测源配置30秒后才能再次操作 - nodeCheckSetting: [] + nodeCheckSetting: new Map() }, getters: { }, mutations: { - // 倒计时30秒 SET_CHECK_SOURCE_INTERVAL(state, nodeId) { + console.log(`Setting check source interval for node ${nodeId}`) + + if (state.nodeCheckSetting.has(nodeId)) { + console.log(`Clearing existing interval for node ${nodeId}`) + clearTimeout(state.nodeCheckSetting.get(nodeId).timeout) + state.nodeCheckSetting.delete(nodeId) + } + const obj = { nodeId, time: 30 } - obj.interval = setInterval(() => { - obj.time-- - if (obj.time === 0 && obj.interval !== undefined) { - clearInterval(obj.interval) - const nodeIndex = state.nodeCheckSetting.findIndex(item => item.nodeId === nodeId) - state.nodeCheckSetting.splice(nodeIndex, 1) - } - }, 1000) - state.nodeCheckSetting.push(obj) + + obj.timeout = setTimeout(() => { + console.log(`Interval finished for node ${nodeId}`) + state.nodeCheckSetting.delete(nodeId) + }, 30000) + + state.nodeCheckSetting.set(nodeId, obj) + console.log(`Interval set for node ${nodeId}`) } }, actions: { -- Gitee