@ -54,11 +54,6 @@ export async function updateDidSpecificSettings(
accountDid : string ,
settingsChanges : Settings ,
) : Promise < boolean > {
console . log ( "🔧 DEBUG: updateDidSpecificSettings called with:" , {
accountDid ,
settingsChanges ,
} ) ;
settingsChanges . accountDid = accountDid ;
delete settingsChanges . id ; // key off account, not ID
@ -69,13 +64,11 @@ export async function updateDidSpecificSettings(
"SELECT * FROM settings WHERE accountDid = ?" ,
[ accountDid ] ,
) ;
console . log ( "🔧 DEBUG: Pre-update database check:" , checkResult ) ;
// Get the current values for comparison
const currentRecord = checkResult ? . values ? . length
? mapColumnsToValues ( checkResult . columns , checkResult . values ) [ 0 ]
: null ;
console . log ( "🔧 DEBUG: Current record:" , currentRecord ) ;
// First try to update existing record
const { sql : updateSql , params : updateParams } = generateUpdateStatement (
@ -85,11 +78,7 @@ export async function updateDidSpecificSettings(
[ accountDid ] ,
) ;
console . log ( "🔧 DEBUG: Generated SQL:" , updateSql ) ;
console . log ( "🔧 DEBUG: Generated params:" , updateParams ) ;
const updateResult = await platform . dbExec ( updateSql , updateParams ) ;
console . log ( "🔧 DEBUG: Update result:" , updateResult ) ;
await platform . dbExec ( updateSql , updateParams ) ;
// **WORKAROUND**: AbsurdSQL doesn't return changes count correctly
// Instead, check if the record was actually updated
@ -101,46 +90,35 @@ export async function updateDidSpecificSettings(
const updatedRecord = postUpdateResult ? . values ? . length
? mapColumnsToValues ( postUpdateResult . columns , postUpdateResult . values ) [ 0 ]
: null ;
console . log ( "🔧 DEBUG: Updated record:" , updatedRecord ) ;
// Check if any of the target fields were actually changed
let actuallyUpdated = false ;
if ( currentRecord && updatedRecord ) {
for ( const key of Object . keys ( settingsChanges ) ) {
if ( key !== "accountDid" && currentRecord [ key ] !== updatedRecord [ key ] ) {
console . log (
` 🔧 DEBUG: Field ' ${ key } ' changed from ' ${ currentRecord [ key ] } ' to ' ${ updatedRecord [ key ] } ' ` ,
) ;
actuallyUpdated = true ;
}
}
}
console . log ( "🔧 DEBUG: Actually updated:" , actuallyUpdated ) ;
// If the standard update didn't work, try a different approach
if (
! actuallyUpdated &&
settingsChanges . firstName &&
settingsChanges . isRegistered !== undefined
) {
console . log (
"🔧 DEBUG: Standard update failed, trying individual field updates..." ,
) ;
// Update firstName
const firstNameResult = await platform . dbExec (
await platform . dbExec (
"UPDATE settings SET firstName = ? WHERE accountDid = ?" ,
[ settingsChanges . firstName , accountDid ] ,
) ;
console . log ( "🔧 DEBUG: firstName update result:" , firstNameResult ) ;
// Update isRegistered
const isRegisteredResult = await platform . dbExec (
await platform . dbExec (
"UPDATE settings SET isRegistered = ? WHERE accountDid = ?" ,
[ settingsChanges . isRegistered ? 1 : 0 , accountDid ] ,
) ;
console . log ( "🔧 DEBUG: isRegistered update result:" , isRegisteredResult ) ;
// Check if the individual updates worked
const finalCheckResult = await platform . dbQuery (
@ -151,10 +129,6 @@ export async function updateDidSpecificSettings(
const finalRecord = finalCheckResult ? . values ? . length
? mapColumnsToValues ( finalCheckResult . columns , finalCheckResult . values ) [ 0 ]
: null ;
console . log (
"🔧 DEBUG: Final record after individual updates:" ,
finalRecord ,
) ;
if ( finalRecord ) {
actuallyUpdated =
@ -163,7 +137,6 @@ export async function updateDidSpecificSettings(
}
}
console . log ( "🔧 DEBUG: Final success status:" , actuallyUpdated ) ;
return actuallyUpdated ;
}
@ -200,21 +173,15 @@ export async function retrieveSettingsForDefaultAccount(): Promise<Settings> {
* @throws Will log specific errors for debugging but returns default settings on failure
* /
export async function retrieveSettingsForActiveAccount ( ) : Promise < Settings > {
console . log ( "🔍 DEBUG: retrieveSettingsForActiveAccount called" ) ;
try {
// Get default settings first
const defaultSettings = await retrieveSettingsForDefaultAccount ( ) ;
console . log ( "🔍 DEBUG: Default settings loaded:" , defaultSettings ) ;
// If no active DID, return defaults
if ( ! defaultSettings . activeDid ) {
console . log ( "🔍 DEBUG: No active DID, returning defaults" ) ;
return defaultSettings ;
}
console . log ( "🔍 DEBUG: Active DID found:" , defaultSettings . activeDid ) ;
// Get account-specific settings
try {
const platform = PlatformServiceFactory . getInstance ( ) ;
@ -223,12 +190,7 @@ export async function retrieveSettingsForActiveAccount(): Promise<Settings> {
[ defaultSettings . activeDid ] ,
) ;
console . log ( "🔍 DEBUG: Account-specific query result:" , result ) ;
if ( ! result ? . values ? . length ) {
console . log (
"🔍 DEBUG: No account-specific settings found, returning defaults" ,
) ;
// we created DID-specific settings when generated or imported, so this shouldn't happen
return defaultSettings ;
}
@ -239,22 +201,13 @@ export async function retrieveSettingsForActiveAccount(): Promise<Settings> {
result . values ,
) [ 0 ] as Settings ;
console . log ( "🔍 DEBUG: Raw override settings:" , overrideSettings ) ;
const overrideSettingsFiltered = Object . fromEntries (
Object . entries ( overrideSettings ) . filter ( ( [ _ , v ] ) = > v !== null ) ,
) ;
console . log (
"🔍 DEBUG: Filtered override settings:" ,
overrideSettingsFiltered ,
) ;
// Merge settings
let settings = { . . . defaultSettings , . . . overrideSettingsFiltered } ;
console . log ( "🔍 DEBUG: Merged settings before platform fix:" , settings ) ;
// **ELECTRON-SPECIFIC FIX**: Force production API endpoints for Electron
// This ensures Electron doesn't use localhost development servers that might be saved in user settings
if ( process . env . VITE_PLATFORM === "electron" ) {
@ -279,10 +232,8 @@ export async function retrieveSettingsForActiveAccount(): Promise<Settings> {
settings . searchBoxes = parseJsonField ( settings . searchBoxes , [ ] ) ;
}
console . log ( "🔍 DEBUG: Final merged settings:" , settings ) ;
return settings ;
} catch ( error ) {
console . log ( "🔍 DEBUG: Error in account settings retrieval:" , error ) ;
logConsoleAndDb (
` [databaseUtil] Failed to retrieve account settings for ${ defaultSettings . activeDid } : ${ error } ` ,
true ,
@ -291,7 +242,6 @@ export async function retrieveSettingsForActiveAccount(): Promise<Settings> {
return defaultSettings ;
}
} catch ( error ) {
console . log ( "🔍 DEBUG: Error in default settings retrieval:" , error ) ;
logConsoleAndDb (
` [databaseUtil] Failed to retrieve default settings: ${ error } ` ,
true ,