From d11f437e2d165ca3a1a7d1c8286ee9077db8b800 Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Tue, 25 Feb 2025 11:29:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E6=97=A0=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=89=93=E5=BC=80=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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) {