perf: 优化客户端升级

This commit is contained in:
kuaifan 2024-11-15 11:58:47 +08:00
parent fbb74e09e8
commit a09f2038ee

39
electron/electron.js vendored
View File

@ -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',