From 9c9cfdf0b2483c9d2b090f485a85b3e7bebe2130 Mon Sep 17 00:00:00 2001 From: sanish chirayath Date: Wed, 24 Sep 2025 19:28:30 +0530 Subject: [PATCH] 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 --- packages/bruno-electron/src/app/onboarding.js | 11 ++++++----- packages/bruno-electron/src/store/preferences.js | 9 +++++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/bruno-electron/src/app/onboarding.js b/packages/bruno-electron/src/app/onboarding.js index 5c9e4a492..de7b575e2 100644 --- a/packages/bruno-electron/src/app/onboarding.js +++ b/packages/bruno-electron/src/app/onboarding.js @@ -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(); } } diff --git a/packages/bruno-electron/src/store/preferences.js b/packages/bruno-electron/src/store/preferences.js index 44600907a..004d0e860 100644 --- a/packages/bruno-electron/src/store/preferences.js +++ b/packages/bruno-electron/src/store/preferences.js @@ -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); + } } };