mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-04-13 08:00:30 +08:00
Fix #1555: Ensure working directory is prepared when adding new subscription
When adding a new subscription that becomes the current profile with 'diffWorkDir' enabled, 'generateProfile()' was not being called to prepare the profile's working directory before the core was restarted. This caused the working directory to be empty and missing necessary database files (geoip, geosite, etc.), leading to proxies appearing to work (showing green) but actually failing to function properly. The fix ensures that when a new profile is added and becomes current with 'diffWorkDir' enabled, 'generateProfile()' is explicitly called before 'changeCurrentProfile()' to prepare the working directory. Co-authored-by: Your Name <your-email@example.com> Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
34fc4d2d96
commit
5d4c0cbfb9
@ -107,6 +107,7 @@ export async function updateProfileItem(item: IProfileItem): Promise<void> {
|
||||
export async function addProfileItem(item: Partial<IProfileItem>): Promise<void> {
|
||||
const newItem = await createProfile(item)
|
||||
let shouldChangeCurrent = false
|
||||
let newProfileIsCurrentAfterUpdate = false
|
||||
await updateProfileConfig((config) => {
|
||||
const existingIndex = config.items.findIndex((i) => i.id === newItem.id)
|
||||
if (existingIndex !== -1) {
|
||||
@ -116,10 +117,25 @@ export async function addProfileItem(item: Partial<IProfileItem>): Promise<void>
|
||||
}
|
||||
if (!config.current) {
|
||||
shouldChangeCurrent = true
|
||||
newProfileIsCurrentAfterUpdate = true
|
||||
}
|
||||
return config
|
||||
})
|
||||
|
||||
// If the new profile will become the current profile, ensure generateProfile is called
|
||||
// to prepare working directory before restarting core
|
||||
if (newProfileIsCurrentAfterUpdate) {
|
||||
const { diffWorkDir } = await getAppConfig()
|
||||
if (diffWorkDir) {
|
||||
try {
|
||||
const { generateProfile } = await import('../core/factory')
|
||||
await generateProfile()
|
||||
} catch (error) {
|
||||
profileLogger.warn('Failed to generate profile for new subscription', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldChangeCurrent) {
|
||||
await changeCurrentProfile(newItem.id)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user