mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-10 11:40:28 +08:00
fix: prevent profile switch queue from breaking after failed switch
This commit is contained in:
parent
56e328191f
commit
3c148f2c01
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -263,7 +263,7 @@ jobs:
|
|||||||
arch:
|
arch:
|
||||||
- x64
|
- x64
|
||||||
- arm64
|
- arm64
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-20.04
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v6
|
||||||
|
|||||||
@ -65,26 +65,33 @@ export async function getProfileItem(id: string | undefined): Promise<IProfileIt
|
|||||||
|
|
||||||
export async function changeCurrentProfile(id: string): Promise<void> {
|
export async function changeCurrentProfile(id: string): Promise<void> {
|
||||||
// 使用队列确保 profile 切换串行执行,避免竞态条件
|
// 使用队列确保 profile 切换串行执行,避免竞态条件
|
||||||
changeProfileQueue = changeProfileQueue.then(async () => {
|
let taskError: unknown = null
|
||||||
const { current } = await getProfileConfig()
|
changeProfileQueue = changeProfileQueue
|
||||||
if (current === id) return
|
.catch(() => {
|
||||||
|
})
|
||||||
|
.then(async () => {
|
||||||
|
const { current } = await getProfileConfig()
|
||||||
|
if (current === id) return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await updateProfileConfig((config) => {
|
await updateProfileConfig((config) => {
|
||||||
config.current = id
|
config.current = id
|
||||||
return config
|
return config
|
||||||
})
|
})
|
||||||
await restartCore()
|
await restartCore()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// 回滚配置
|
// 回滚配置
|
||||||
await updateProfileConfig((config) => {
|
await updateProfileConfig((config) => {
|
||||||
config.current = current
|
config.current = current
|
||||||
return config
|
return config
|
||||||
})
|
})
|
||||||
throw e
|
taskError = e
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
await changeProfileQueue
|
await changeProfileQueue
|
||||||
|
if (taskError) {
|
||||||
|
throw taskError
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateProfileItem(item: IProfileItem): Promise<void> {
|
export async function updateProfileItem(item: IProfileItem): Promise<void> {
|
||||||
@ -249,6 +256,14 @@ export async function createProfile(item: Partial<IProfileItem>): Promise<IProfi
|
|||||||
useProxy: true,
|
useProxy: true,
|
||||||
timeout: subscriptionTimeout
|
timeout: subscriptionTimeout
|
||||||
})
|
})
|
||||||
|
} else if (newItem.substore) {
|
||||||
|
// SubStore requests (especially collections) need more time as they fetch and merge multiple subscriptions
|
||||||
|
// Use the full subscriptionTimeout since SubStore is a local server and doesn't need smart fallback
|
||||||
|
result = await fetchAndValidateSubscription({
|
||||||
|
...baseOptions,
|
||||||
|
useProxy: false,
|
||||||
|
timeout: subscriptionTimeout
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
const smartTimeout = 5000
|
const smartTimeout = 5000
|
||||||
try {
|
try {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user