fix: update preferences saving method in preferences utility (#5617)

* fix: update preferences saving method in preferences utility

* fix: make markAsLaunched asynchronous and improve error handling in onboarding process

* fix: lint errors

---------

Co-authored-by: Bijin Bruno <bijin@usebruno.com>
This commit is contained in:
sanish chirayath
2025-09-24 19:28:30 +05:30
committed by GitHub
parent daf6a6d5d6
commit 9c9cfdf0b2
2 changed files with 13 additions and 7 deletions

View File

@@ -77,11 +77,12 @@ async function onboardUser(mainWindow, lastOpenedCollections) {
}
if (process.env.DISABLE_SAMPLE_COLLECTION_IMPORT !== 'true') {
// Onboarding was added later;
// if a collection already exists, user is old skip onboarding
// Check if user already has collections (indicates they're an existing user)
// Onboarding was added in a later version, so for existing users we should skip it
// to avoid creating sample collections
const collections = await lastOpenedCollections.getAll();
if (collections.length > 0) {
preferencesUtil.markAsLaunched();
await preferencesUtil.markAsLaunched();
return;
}
@@ -89,11 +90,11 @@ async function onboardUser(mainWindow, lastOpenedCollections) {
await importSampleCollection(collectionLocation, mainWindow, lastOpenedCollections);
}
preferencesUtil.markAsLaunched();
await preferencesUtil.markAsLaunched();
} catch (error) {
console.error('Failed to handle onboarding:', error);
// Still mark as launched to prevent retry on next startup
preferencesUtil.markAsLaunched();
await preferencesUtil.markAsLaunched();
}
}

View File

@@ -186,10 +186,15 @@ const preferencesUtil = {
hasLaunchedBefore: () => {
return get(getPreferences(), 'onboarding.hasLaunchedBefore', false);
},
markAsLaunched: () => {
markAsLaunched: async () => {
const preferences = getPreferences();
preferences.onboarding.hasLaunchedBefore = true;
preferencesStore.savePreferences(preferences);
try {
await savePreferences(preferences);
} catch (err) {
console.error('Failed to save preferences in markAsLaunched:', err);
}
}
};