@@ -1180,57 +1180,57 @@ async function createWindow() {
11801180
11811181 // Handle localStorage based on installation state
11821182 if ( needsInstallation ) {
1183- log . info ( 'Installation needed - clearing auth storage to force carousel state' ) ;
1184-
1185- // Clear the persisted auth storage file to force fresh initialization with carousel
1186- // Main window uses partition 'persist:main_window', so data is in Partitions/main_window
1187- const partitionPath = path . join ( app . getPath ( 'userData' ) , 'Partitions' , 'main_window' ) ;
1188- const localStoragePath = path . join ( partitionPath , 'Local Storage' ) ;
1189- const leveldbPath = path . join ( localStoragePath , 'leveldb' ) ;
1190-
1191- try {
1192- // Delete the localStorage database to force fresh init
1193- if ( fs . existsSync ( leveldbPath ) ) {
1194- log . info ( 'Removing localStorage database to force fresh state...' ) ;
1195- fs . rmSync ( leveldbPath , { recursive : true , force : true } ) ;
1196- log . info ( 'Successfully cleared localStorage' ) ;
1197- }
1198- } catch ( error ) {
1199- log . error ( 'Error clearing localStorage:' , error ) ;
1200- }
1183+ log . info ( 'Installation needed - resetting initState to carousel while preserving auth data' ) ;
12011184
1185+ // Instead of deleting the entire localStorage, we'll update only the initState
1186+ // This preserves login information while resetting the initialization flow
12021187 // Set up the injection for when page loads
12031188 win . webContents . once ( 'dom-ready' , ( ) => {
12041189 if ( ! win || win . isDestroyed ( ) ) {
12051190 log . warn ( 'Window destroyed before DOM ready - skipping localStorage injection' ) ;
12061191 return ;
12071192 }
1208- log . info ( 'DOM ready - creating auth-storage with carousel state ' ) ;
1193+ log . info ( 'DOM ready - updating initState to carousel while preserving auth data ' ) ;
12091194 win . webContents . executeJavaScript ( `
12101195 (function() {
12111196 try {
1212- // Create fresh auth storage with carousel state
1213- const newAuthStorage = {
1214- state: {
1215- token: null,
1216- username: null,
1217- email: null,
1218- user_id: null,
1219- appearance: 'light',
1220- language: 'system',
1221- isFirstLaunch: true,
1222- modelType: 'cloud',
1223- cloud_model_type: 'gpt-4.1',
1224- initState: 'carousel',
1225- share_token: null,
1226- workerListData: {}
1227- },
1228- version: 0
1229- };
1230- localStorage.setItem('auth-storage', JSON.stringify(newAuthStorage));
1231- console.log('[ELECTRON PRE-INJECT] Created fresh auth-storage with carousel state');
1197+ const authStorage = localStorage.getItem('auth-storage');
1198+ if (authStorage) {
1199+ // Preserve existing auth data, only update initState
1200+ const parsed = JSON.parse(authStorage);
1201+ const updatedStorage = {
1202+ ...parsed,
1203+ state: {
1204+ ...parsed.state,
1205+ initState: 'carousel'
1206+ }
1207+ };
1208+ localStorage.setItem('auth-storage', JSON.stringify(updatedStorage));
1209+ console.log('[ELECTRON PRE-INJECT] Updated initState to carousel, preserved auth data');
1210+ } else {
1211+ // No existing storage, create new one with carousel state
1212+ const newAuthStorage = {
1213+ state: {
1214+ token: null,
1215+ username: null,
1216+ email: null,
1217+ user_id: null,
1218+ appearance: 'light',
1219+ language: 'system',
1220+ isFirstLaunch: true,
1221+ modelType: 'cloud',
1222+ cloud_model_type: 'gpt-4.1',
1223+ initState: 'carousel',
1224+ share_token: null,
1225+ workerListData: {}
1226+ },
1227+ version: 0
1228+ };
1229+ localStorage.setItem('auth-storage', JSON.stringify(newAuthStorage));
1230+ console.log('[ELECTRON PRE-INJECT] Created fresh auth-storage with carousel state');
1231+ }
12321232 } catch (e) {
1233- console.error('[ELECTRON PRE-INJECT] Failed to create storage:', e);
1233+ console.error('[ELECTRON PRE-INJECT] Failed to update storage:', e);
12341234 }
12351235 })();
12361236 ` ) . catch ( err => {
@@ -1282,9 +1282,9 @@ async function createWindow() {
12821282 }
12831283 })();
12841284 ` ) . then ( needsReload => {
1285- if ( needsReload ) {
1285+ if ( needsReload && win && ! win . isDestroyed ( ) ) {
12861286 log . info ( 'Reloading window after localStorage update' ) ;
1287- win ! . reload ( ) ;
1287+ win . reload ( ) ;
12881288 }
12891289 } ) . catch ( err => {
12901290 log . error ( 'Failed to inject script:' , err ) ;
0 commit comments