Skip to content

Commit

Permalink
Simplify retry mechanism to get system version (#10198)
Browse files Browse the repository at this point in the history
  • Loading branch information
mingpepe authored Jan 16, 2024
1 parent 52b400c commit 6a2cc1e
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions app/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", "<div>获取内核服务端口失败,请确保程序拥有网络权限并不受防火墙和杀毒软件阻止。</div><div>Failed to get kernel serve port, please make sure the program has network permissions and is not blocked by firewalls and antivirus software.</div>");
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) {
Expand Down

0 comments on commit 6a2cc1e

Please sign in to comment.