@ -106,6 +106,8 @@ export const PlatformServiceMixin = {
return {
// Cache the platform service instance at component level
_platformService : null as PlatformService | null ,
// Track the current activeDid for change detection
_currentActiveDid : null as string | null ,
} ;
} ,
@ -122,6 +124,14 @@ export const PlatformServiceMixin = {
return ( this as unknown as VueComponentWithMixin ) . _platformService ! ;
} ,
/ * *
* Current active DID from settings
* Used for change detection and component updates
* /
currentActiveDid ( ) : string | null {
return ( this as any ) . _currentActiveDid ;
} ,
/ * *
* Access to in - memory logs array
* Provides direct access to memoryLogs without requiring databaseUtil import
@ -157,11 +167,43 @@ export const PlatformServiceMixin = {
} ,
} ,
watch : {
/ * *
* Watch for changes in the current activeDid
* Triggers component updates when user switches identities
* /
currentActiveDid : {
handler ( newDid : string | null , oldDid : string | null ) {
if ( newDid !== oldDid ) {
logger . debug ( ` [PlatformServiceMixin] ActiveDid changed from ${ oldDid } to ${ newDid } ` ) ;
// Clear caches that might be affected by the change
( this as any ) . $clearAllCaches ( ) ;
}
} ,
immediate : true
}
} ,
methods : {
// =================================================
// SELF-CONTAINED UTILITY METHODS (no databaseUtil dependency)
// =================================================
/ * *
* Update the current activeDid and trigger change detection
* This method should be called when the user switches identities
* /
async $updateActiveDid ( newDid : string | null ) : Promise < void > {
const oldDid = ( this as any ) . _currentActiveDid ;
( this as any ) . _currentActiveDid = newDid ;
if ( newDid !== oldDid ) {
logger . debug ( ` [PlatformServiceMixin] ActiveDid updated from ${ oldDid } to ${ newDid } ` ) ;
// Clear caches that might be affected by the change
this . $clearAllCaches ( ) ;
}
} ,
/ * *
* Self - contained implementation of mapColumnsToValues
* Maps database query results to objects with column names as keys
@ -711,6 +753,12 @@ export const PlatformServiceMixin = {
` UPDATE settings SET ${ setParts . join ( ", " ) } WHERE id = ? ` ,
params ,
) ;
// Update activeDid tracking if it changed
if ( changes . activeDid !== undefined ) {
await this . $updateActiveDid ( changes . activeDid ) ;
}
return true ;
} catch ( error ) {
logger . error ( "[PlatformServiceMixin] Error saving settings:" , error ) ;
@ -730,12 +778,17 @@ export const PlatformServiceMixin = {
changes : Partial < Settings > ,
) : Promise < boolean > {
try {
console . log ( '[DEBUG] $saveUserSettings - did:' , did ) ;
console . log ( '[DEBUG] $saveUserSettings - changes:' , changes ) ;
// Remove fields that shouldn't be updated
const { id , . . . safeChanges } = changes ;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
void id ;
safeChanges . accountDid = did ;
console . log ( '[DEBUG] $saveUserSettings - safeChanges:' , safeChanges ) ;
if ( Object . keys ( safeChanges ) . length === 0 ) return true ;
const setParts : string [ ] = [ ] ;
@ -748,15 +801,21 @@ export const PlatformServiceMixin = {
}
} ) ;
console . log ( '[DEBUG] $saveUserSettings - setParts:' , setParts ) ;
console . log ( '[DEBUG] $saveUserSettings - params:' , params ) ;
if ( setParts . length === 0 ) return true ;
params . push ( did ) ;
await this . $dbExec (
` UPDATE settings SET ${ setParts . join ( ", " ) } WHERE accountDid = ? ` ,
params ,
) ;
const sql = ` UPDATE settings SET ${ setParts . join ( ", " ) } WHERE accountDid = ? ` ;
console . log ( '[DEBUG] $saveUserSettings - SQL:' , sql ) ;
console . log ( '[DEBUG] $saveUserSettings - Final params:' , params ) ;
await this . $dbExec ( sql , params ) ;
console . log ( '[DEBUG] $saveUserSettings - Database update successful' ) ;
return true ;
} catch ( error ) {
console . log ( '[DEBUG] $saveUserSettings - Error:' , error ) ;
logger . error (
"[PlatformServiceMixin] Error saving user settings:" ,
error ,
@ -774,9 +833,14 @@ export const PlatformServiceMixin = {
async $saveMySettings ( changes : Partial < Settings > ) : Promise < boolean > {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const currentDid = ( this as any ) . activeDid ;
console . log ( '[DEBUG] $saveMySettings - changes:' , changes ) ;
console . log ( '[DEBUG] $saveMySettings - currentDid:' , currentDid ) ;
if ( ! currentDid ) {
console . log ( '[DEBUG] $saveMySettings - No DID, using $saveSettings' ) ;
return await this . $saveSettings ( changes ) ;
}
console . log ( '[DEBUG] $saveMySettings - Using $saveUserSettings for DID:' , currentDid ) ;
return await this . $saveUserSettings ( currentDid , changes ) ;
} ,
@ -1433,6 +1497,10 @@ declare module "@vue/runtime-core" {
isElectron : boolean ;
capabilities : PlatformCapabilities ;
// ActiveDid tracking
currentActiveDid : string | null ;
$updateActiveDid ( newDid : string | null ) : Promise < void > ;
// Ultra-concise database methods (shortest possible names)
$db ( sql : string , params? : unknown [ ] ) : Promise < QueryExecResult | undefined > ;
$exec ( sql : string , params? : unknown [ ] ) : Promise < DatabaseExecResult > ;