From a09f2038ee3fb063aec242309af9987cc07a69ff Mon Sep 17 00:00:00 2001 From: kuaifan Date: Fri, 15 Nov 2024 11:58:47 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E5=8D=87=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/electron.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/electron/electron.js b/electron/electron.js index 9785026c1..0d385845c 100644 --- a/electron/electron.js +++ b/electron/electron.js @@ -201,25 +201,6 @@ function createUpdaterWindow(loadingTip) { } else { updaterPath = path.join(process.resourcesPath, 'updater', 'updater'); } - - // 检查文件权限 - try { - fs.accessSync(updaterPath, fs.constants.X_OK); - } catch (e) { - if (process.platform === 'darwin') { - try { - spawn('chmod', ['+x', updaterPath], {stdio: 'inherit'}); - } catch (e) { - console.log('Failed to set executable permission:', e); - } - } else if (process.platform === 'win32') { - try { - spawn('icacls', [updaterPath, '/set', 'everyone:F'], {stdio: 'inherit'}); - } catch (e) { - console.log('Failed to set executable permission:', e); - } - } - } // 检查updater应用是否存在 if (!fs.existsSync(updaterPath)) { @@ -227,6 +208,25 @@ function createUpdaterWindow(loadingTip) { return; } + // 检查文件权限 + try { + fs.accessSync(updaterPath, fs.constants.X_OK); + } catch (e) { + if (isWin) { + try { + spawn('icacls', [updaterPath, '/grant', 'everyone:F'], { stdio: 'inherit', shell: true }); + } catch (e) { + console.log('Failed to set executable permission:', e); + } + } else if (process.platform === 'darwin') { + try { + spawn('chmod', ['+x', updaterPath], {stdio: 'inherit'}); + } catch (e) { + console.log('Failed to set executable permission:', e); + } + } + } + // 创建锁文件 fs.writeFileSync(updaterLockFile, loadingTip || ''); @@ -234,6 +234,7 @@ function createUpdaterWindow(loadingTip) { const child = spawn(updaterPath, [updaterLockFile], { detached: true, stdio: 'ignore', + shell: isWin, env: { ...process.env, ELECTRON_RUN_AS_NODE: '1',