Skip to content

Commit 8029ce8

Browse files
committed
[FIX] Fix reload app on every launch
1 parent 4b9bfaf commit 8029ce8

File tree

2 files changed

+81
-4
lines changed

2 files changed

+81
-4
lines changed

src/backend/main.ts

+75-4
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,17 @@ if (!gotTheLock) {
470470

471471
createInjectedProviderWindow()
472472

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+
473484
const providerPreloadPath = path.join(
474485
__dirname,
475486
'../preload/providerPreload.js'
@@ -706,10 +717,32 @@ ipcMain.once('loadingScreenReady', () => {
706717

707718
ipcMain.once('frontendReady', async () => {
708719
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+
713746
handleProtocol([openUrlArgument, ...process.argv])
714747
setTimeout(() => {
715748
logInfo('Starting the Download Queue', LogPrefix.Backend)
@@ -2026,6 +2059,44 @@ ipcMain.handle(
20262059
*/
20272060

20282061
// 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+
20292100
backendEvents.on('walletConnected', function (accounts: string[]) {
20302101
getMainWindow()?.webContents.send('walletConnected', accounts)
20312102
})

src/common/types/electron_store.ts

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { UserData } from 'common/types/gog'
2121

2222
export interface StoreStructure {
2323
configStore: {
24+
appVersion: string
2425
userHome: string
2526
userInfo: UserInfo
2627
games: {
@@ -43,6 +44,11 @@ export interface StoreStructure {
4344
'window-props': Electron.Rectangle
4445
settings: AppSettings
4546
skipVcRuntime: boolean
47+
walletState: {
48+
isConnected: boolean
49+
address: string
50+
provider: PROVIDERS
51+
}
4652
}
4753
wineDownloaderInfoStore: {
4854
'wine-releases': WineVersionInfo[]

0 commit comments

Comments
 (0)