experiments in a post-browser web
10
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(client): initialize profiles in entry.ts

- Initialize profiles database on app startup
- Migrate existing profile directories to profiles.db
- Use active profile from profiles.db instead of env var
- Fallback to PROFILE env var for dev/testing
- Ensure default profile always exists

+43 -8
+43 -8
backend/electron/entry.ts
··· 62 62 63 63 import { startHotReload, stopHotReload } from './hotreload.js'; 64 64 import { checkAndRunDailyBackup } from './backup.js'; 65 + import { 66 + initProfilesDb, 67 + migrateExistingProfiles, 68 + ensureDefaultProfile, 69 + getActiveProfile, 70 + } from './profiles.js'; 65 71 66 72 // Catch unhandled errors and promise rejections without showing alert dialogs 67 73 unhandled({ ··· 123 129 return execPath.includes('/out/') || execPath.includes('\\out\\'); 124 130 }; 125 131 132 + // Initialize profiles database and migrate existing profiles FIRST 133 + // This must happen before we determine the PROFILE to use 134 + const defaultUserDataPath = app.getPath('userData'); 135 + 136 + try { 137 + initProfilesDb(defaultUserDataPath); 138 + migrateExistingProfiles(); 139 + ensureDefaultProfile(); 140 + DEBUG && console.log('[profiles] Profiles database initialized'); 141 + } catch (error) { 142 + console.error('[profiles] Failed to initialize profiles:', error); 143 + // Continue with fallback behavior 144 + } 145 + 126 146 // Profile selection: 127 - // 1. Explicit PROFILE env var takes precedence 128 - // 2. Packaged app in /Applications uses 'default' (production) 129 - // 3. Packaged app in out/ directory uses 'dev' (dev packaged build) 130 - // 4. Running from source uses 'dev' (development) 131 - const PROFILE = profileIsLegit(process.env.PROFILE) 132 - ? process.env.PROFILE 133 - : (app.isPackaged && !isDevPackagedBuild() ? 'default' : 'dev'); 147 + // 1. Explicit PROFILE env var takes precedence (for dev/testing) 148 + // 2. Active profile from profiles.db (normal operation) 149 + // 3. Packaged app in /Applications uses 'default' (production fallback) 150 + // 4. Packaged app in out/ directory uses 'dev' (dev packaged build fallback) 151 + // 5. Running from source uses 'dev' (development fallback) 152 + let PROFILE: string; 153 + 154 + if (profileIsLegit(process.env.PROFILE)) { 155 + // Explicit env var takes precedence 156 + PROFILE = process.env.PROFILE; 157 + DEBUG && console.log('[profiles] Using PROFILE env var:', PROFILE); 158 + } else { 159 + // Try to get active profile from profiles.db 160 + try { 161 + const activeProfile = getActiveProfile(); 162 + PROFILE = activeProfile.slug; 163 + DEBUG && console.log('[profiles] Using active profile from profiles.db:', PROFILE); 164 + } catch (error) { 165 + // Fallback to default behavior if profiles.db fails 166 + PROFILE = app.isPackaged && !isDevPackagedBuild() ? 'default' : 'dev'; 167 + DEBUG && console.log('[profiles] Fallback to default PROFILE:', PROFILE); 168 + } 169 + } 134 170 135 171 DEBUG && console.log('PROFILE', PROFILE, app.isPackaged ? (isDevPackagedBuild() ? '(dev-packaged)' : '(packaged)') : '(source)'); 136 172 ··· 143 179 // {home} / {appData} / {userData} / {profileDir} / {sessionData} 144 180 145 181 // specify various app data paths and make if not exist 146 - const defaultUserDataPath = app.getPath('userData'); 147 182 const profileDataPath = path.join(defaultUserDataPath, PROFILE); 148 183 const sessionDataPath = path.join(profileDataPath, 'chromium'); 149 184