@@ -470,6 +470,17 @@ if (!gotTheLock) {
470
470
471
471
createInjectedProviderWindow ( )
472
472
473
+ const currentStoredVersion = configStore . get ( 'appVersion' , '' )
474
+ const currentVersion = app . getVersion ( )
475
+
476
+ if ( currentStoredVersion !== currentVersion ) {
477
+ logInfo (
478
+ `App version changed from ${ currentStoredVersion } to ${ app . getVersion ( ) } ` ,
479
+ LogPrefix . Backend
480
+ )
481
+ configStore . set ( 'appVersion' , currentVersion )
482
+ }
483
+
473
484
const providerPreloadPath = path . join (
474
485
__dirname ,
475
486
'../preload/providerPreload.js'
@@ -706,10 +717,32 @@ ipcMain.once('loadingScreenReady', () => {
706
717
707
718
ipcMain . once ( 'frontendReady' , async ( ) => {
708
719
logInfo ( 'Frontend Ready' , LogPrefix . Backend )
709
- await initExtension ( hpApi )
710
- // wait for mm SW to initialize
711
- await wait ( 5000 )
712
- ipcMain . emit ( 'reloadApp' )
720
+ const currentVersion = app . getVersion ( )
721
+ const lastVersion = configStore . get ( 'appVersion' , '' )
722
+
723
+ if ( ! lastVersion || lastVersion !== currentVersion ) {
724
+ // Only initialize extension and reload if a wallet is connected
725
+ const walletStateIsConnected = configStore . get (
726
+ 'walletState.isConnected' ,
727
+ false
728
+ )
729
+ if ( walletStateIsConnected ) {
730
+ logInfo (
731
+ 'App version changed and wallet connected, reloading to update MM' ,
732
+ LogPrefix . Backend
733
+ )
734
+ await initExtension ( hpApi )
735
+ // wait for mm SW to initialize
736
+ await wait ( 5000 )
737
+ ipcMain . emit ( 'reloadApp' )
738
+ } else {
739
+ logInfo (
740
+ 'App version changed but no wallet connected, skipping MM update' ,
741
+ LogPrefix . Backend
742
+ )
743
+ }
744
+ }
745
+
713
746
handleProtocol ( [ openUrlArgument , ...process . argv ] )
714
747
setTimeout ( ( ) => {
715
748
logInfo ( 'Starting the Download Queue' , LogPrefix . Backend )
@@ -2026,6 +2059,44 @@ ipcMain.handle(
2026
2059
*/
2027
2060
2028
2061
// sends messages to renderer process through preload.ts callbacks
2062
+ backendEvents . on ( 'walletConnected' , function ( accounts : string [ ] ) {
2063
+ getMainWindow ( ) ?. webContents . send ( 'walletConnected' , accounts )
2064
+ // Store wallet connection state
2065
+ configStore . set ( 'walletState.isConnected' , true )
2066
+ if ( accounts && accounts . length > 0 ) {
2067
+ configStore . set ( 'walletState.address' , accounts [ 0 ] )
2068
+ }
2069
+ } )
2070
+
2071
+ backendEvents . on ( 'walletDisconnected' , function ( code : number , reason : string ) {
2072
+ getMainWindow ( ) ?. webContents . send ( 'walletDisconnected' , code , reason )
2073
+ // Update wallet connection state
2074
+ configStore . set ( 'walletState.isConnected' , false )
2075
+ } )
2076
+
2077
+ backendEvents . on ( 'connectionRequestRejected' , function ( ) {
2078
+ getMainWindow ( ) ?. webContents . send ( 'connectionRequestRejected' )
2079
+ } )
2080
+
2081
+ backendEvents . on ( 'chainChanged' , function ( chainId : number ) {
2082
+ getMainWindow ( ) ?. webContents . send ( 'chainChanged' , chainId )
2083
+ } )
2084
+
2085
+ backendEvents . on (
2086
+ 'accountsChanged' ,
2087
+ function ( accounts : string [ ] , provider : PROVIDERS ) {
2088
+ getMainWindow ( ) ?. webContents . send ( 'accountChanged' , accounts , provider )
2089
+ // Update wallet details in configStore
2090
+ if ( accounts && accounts . length > 0 ) {
2091
+ configStore . set ( 'walletState.address' , accounts [ 0 ] )
2092
+ configStore . set ( 'walletState.provider' , provider )
2093
+ configStore . set ( 'walletState.isConnected' , true )
2094
+ } else {
2095
+ configStore . set ( 'walletState.isConnected' , false )
2096
+ }
2097
+ }
2098
+ )
2099
+
2029
2100
backendEvents . on ( 'walletConnected' , function ( accounts : string [ ] ) {
2030
2101
getMainWindow ( ) ?. webContents . send ( 'walletConnected' , accounts )
2031
2102
} )
0 commit comments