From 5d4c0cbfb900c240f464c30a05742596d4537a85 Mon Sep 17 00:00:00 2001 From: Daniel Bates Date: Tue, 17 Mar 2026 20:12:19 -0700 Subject: [PATCH] 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 Co-authored-by: Claude Haiku 4.5 --- src/main/config/profile.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/config/profile.ts b/src/main/config/profile.ts index a199686..5761359 100644 --- a/src/main/config/profile.ts +++ b/src/main/config/profile.ts @@ -107,6 +107,7 @@ export async function updateProfileItem(item: IProfileItem): Promise { export async function addProfileItem(item: Partial): Promise { 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): Promise } 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) }