diff --git a/main.js b/main.js index a1d46cd..f460aab 100644 --- a/main.js +++ b/main.js @@ -11,6 +11,7 @@ const { crashReporter, desktopCapturer, powerSaveBlocker, + net } = require('electron'); const path = require('node:path') const updateJs = require('./src/utils/package/update') @@ -70,6 +71,15 @@ function quit() { app.quit() } let tray; +// 检查网络状态 +function checkNetworkStatus() { + if (!net.isOnline()) { + dialog.showErrorBox('网络连接错误', '当前无网络连接,请检查您的网络设置。'); + app.quit(); + return false; + } + return true; +} function createTray() { const iconPath = `${__dirname}/src/assets/${updateJs.getIcon(env)}.png`; const trayIcon = nativeImage.createFromPath(iconPath); @@ -93,6 +103,10 @@ function createWindow() { } const additionalData = { myKey: 'myValue' } app.on('ready', () => { + // 检查网络状态 + if (!checkNetworkStatus()) { + return; + } // const gotTheLock = true const gotTheLock = app.requestSingleInstanceLock(additionalData) if (gotTheLock) {