From ee0a0b48674a4e80fd01fbbf548b887d484fc796 Mon Sep 17 00:00:00 2001 From: pompurin404 Date: Tue, 15 Oct 2024 14:00:12 +0800 Subject: [PATCH] fix portable update --- changelog.md | 1 + src/main/resolve/autoUpdater.ts | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index a9b3c41..f11d886 100644 --- a/changelog.md +++ b/changelog.md @@ -7,3 +7,4 @@ ### Bug Fixes - 修复下拉菜单组件样式异常 +- 修复便携版更新时文件占用的问题 diff --git a/src/main/resolve/autoUpdater.ts b/src/main/resolve/autoUpdater.ts index afcea33..1dfc6b7 100644 --- a/src/main/resolve/autoUpdater.ts +++ b/src/main/resolve/autoUpdater.ts @@ -3,7 +3,7 @@ import yaml from 'yaml' import { app, shell } from 'electron' import { getControledMihomoConfig } from '../config' import { dataDir, exeDir, exePath, isPortable, resourcesFilesDir } from '../utils/dirs' -import { rm, writeFile } from 'fs/promises' +import { copyFile, rm, writeFile } from 'fs/promises' import path from 'path' import { existsSync } from 'fs' import os from 'os' @@ -74,11 +74,12 @@ export async function downloadAndInstallUpdate(version: string): Promise { }).unref() } if (file.endsWith('.7z')) { + await copyFile(path.join(resourcesFilesDir(), '7za.exe'), path.join(dataDir(), '7za.exe')) spawn( 'cmd', [ '/C', - `""${path.join(resourcesFilesDir(), '7za.exe')}" x -o"${exeDir()}" -y "${path.join(dataDir(), file)}" & start "" "${exePath()}""` + `"timeout /t 2 /nobreak >nul && "${path.join(dataDir(), '7za.exe')}" x -o"${exeDir()}" -y "${path.join(dataDir(), file)}" & start "" "${exePath()}""` ], { shell: true,