From 3d08dc8aa35071221678edc5f37893f03096fdc1 Mon Sep 17 00:00:00 2001 From: mingpepe Date: Tue, 16 Jan 2024 21:14:44 +0800 Subject: [PATCH] fix: simplify retry mechanism to get system version --- app/electron/main.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/electron/main.js b/app/electron/main.js index cc07200a97b..368f1f3be91 100644 --- a/app/electron/main.js +++ b/app/electron/main.js @@ -540,36 +540,30 @@ const initKernel = (workspace, port, lang) => { }); } - let gotVersion = false; let apiData; let count = 0; writeLog("checking kernel version"); - while (!gotVersion && count < 15) { + while (true) { try { const apiResult = await net.fetch(getServer() + "/api/system/version"); apiData = await apiResult.json(); - gotVersion = true; bootWindow.setResizable(false); bootWindow.loadURL(getServer() + "/appearance/boot/index.html"); bootWindow.show(); + break; } catch (e) { writeLog("get kernel version failed: " + e.message); - await sleep(200); - } finally { - count++; - if (14 < count) { + if (14 < ++count) { writeLog("get kernel ver failed"); showErrorWindow("⚠️ 获取内核服务端口失败 Failed to get kernel serve port", "
获取内核服务端口失败,请确保程序拥有网络权限并不受防火墙和杀毒软件阻止。
Failed to get kernel serve port, please make sure the program has network permissions and is not blocked by firewalls and antivirus software.
"); bootWindow.destroy(); resolve(false); + return; } + await sleep(200); } } - if (!gotVersion) { - return; - } - if (0 === apiData.code) { writeLog("got kernel version [" + apiData.data + "]"); if (!isDevEnv && apiData.data !== appVer) {