From 3c148f2c01374a3fccecf72b1d84f717e11070a3 Mon Sep 17 00:00:00 2001 From: xmk23333 Date: Mon, 19 Jan 2026 12:55:21 +0800 Subject: [PATCH] fix: prevent profile switch queue from breaking after failed switch --- .github/workflows/build.yml | 2 +- src/main/config/profile.ts | 51 ++++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c6abe13..1f7f475 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -263,7 +263,7 @@ jobs: arch: - x64 - arm64 - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - name: Checkout uses: actions/checkout@v6 diff --git a/src/main/config/profile.ts b/src/main/config/profile.ts index 32456bb..9dae81c 100644 --- a/src/main/config/profile.ts +++ b/src/main/config/profile.ts @@ -65,26 +65,33 @@ export async function getProfileItem(id: string | undefined): Promise { // 使用队列确保 profile 切换串行执行,避免竞态条件 - changeProfileQueue = changeProfileQueue.then(async () => { - const { current } = await getProfileConfig() - if (current === id) return + let taskError: unknown = null + changeProfileQueue = changeProfileQueue + .catch(() => { + }) + .then(async () => { + const { current } = await getProfileConfig() + if (current === id) return - try { - await updateProfileConfig((config) => { - config.current = id - return config - }) - await restartCore() - } catch (e) { - // 回滚配置 - await updateProfileConfig((config) => { - config.current = current - return config - }) - throw e - } - }) + try { + await updateProfileConfig((config) => { + config.current = id + return config + }) + await restartCore() + } catch (e) { + // 回滚配置 + await updateProfileConfig((config) => { + config.current = current + return config + }) + taskError = e + } + }) await changeProfileQueue + if (taskError) { + throw taskError + } } export async function updateProfileItem(item: IProfileItem): Promise { @@ -249,6 +256,14 @@ export async function createProfile(item: Partial): Promise