Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Reload app due to extension only on app update #1261

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 73 additions & 3 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
@@ -470,6 +470,17 @@ if (!gotTheLock) {

createInjectedProviderWindow()

const currentStoredVersion = configStore.get('appVersion', '')
const currentVersion = app.getVersion()

if (currentStoredVersion !== currentVersion) {
logInfo(
`App version changed from ${currentStoredVersion} to ${app.getVersion()}`,
LogPrefix.Backend
)
configStore.set('appVersion', currentVersion)
}

const providerPreloadPath = path.join(
__dirname,
'../preload/providerPreload.js'
@@ -706,10 +717,31 @@ ipcMain.once('loadingScreenReady', () => {

ipcMain.once('frontendReady', async () => {
logInfo('Frontend Ready', LogPrefix.Backend)
const currentVersion = app.getVersion()
const lastVersion = configStore.get('appVersion', '')
const walletStateIsConnected = configStore.get(
'walletState.isConnected',
false
)

await initExtension(hpApi)
// wait for mm SW to initialize
await wait(5000)
ipcMain.emit('reloadApp')

// Only reload the app if a wallet is not connected
// or the app version has changed
if (
!walletStateIsConnected ||
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which edge case does this address?

!lastVersion ||
lastVersion !== currentVersion
) {
logInfo(
'App version changed and wallet connected, reloading to update MM',
LogPrefix.Backend
)
// wait for mm SW to initialize
await wait(5000)
ipcMain.emit('reloadApp')
}

handleProtocol([openUrlArgument, ...process.argv])
setTimeout(() => {
logInfo('Starting the Download Queue', LogPrefix.Backend)
@@ -2026,6 +2058,44 @@ ipcMain.handle(
*/

// sends messages to renderer process through preload.ts callbacks
backendEvents.on('walletConnected', function (accounts: string[]) {
getMainWindow()?.webContents.send('walletConnected', accounts)
// Store wallet connection state
configStore.set('walletState.isConnected', true)
if (accounts && accounts.length > 0) {
configStore.set('walletState.address', accounts[0])
}
})

backendEvents.on('walletDisconnected', function (code: number, reason: string) {
getMainWindow()?.webContents.send('walletDisconnected', code, reason)
// Update wallet connection state
configStore.set('walletState.isConnected', false)
})

backendEvents.on('connectionRequestRejected', function () {
getMainWindow()?.webContents.send('connectionRequestRejected')
})

backendEvents.on('chainChanged', function (chainId: number) {
getMainWindow()?.webContents.send('chainChanged', chainId)
})

backendEvents.on(
'accountsChanged',
function (accounts: string[], provider: PROVIDERS) {
getMainWindow()?.webContents.send('accountChanged', accounts, provider)
// Update wallet details in configStore
if (accounts && accounts.length > 0) {
configStore.set('walletState.address', accounts[0])
configStore.set('walletState.provider', provider)
configStore.set('walletState.isConnected', true)
} else {
configStore.set('walletState.isConnected', false)
}
}
)

backendEvents.on('walletConnected', function (accounts: string[]) {
getMainWindow()?.webContents.send('walletConnected', accounts)
})
6 changes: 6 additions & 0 deletions src/common/types/electron_store.ts
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import { UserData } from 'common/types/gog'

export interface StoreStructure {
configStore: {
appVersion: string
userHome: string
userInfo: UserInfo
games: {
@@ -43,6 +44,11 @@ export interface StoreStructure {
'window-props': Electron.Rectangle
settings: AppSettings
skipVcRuntime: boolean
walletState: {
isConnected: boolean
address: string
provider: PROVIDERS
}
}
wineDownloaderInfoStore: {
'wine-releases': WineVersionInfo[]