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 for MM only on app update #1249

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions src/backend/api/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,5 @@ export const isClientUpdating = async () =>
ipcRenderer.invoke('isClientUpdating')

export const restartClient = () => ipcRenderer.send('restartClient')

export const reloadForMM = () => ipcRenderer.send('reloadForMM')
14 changes: 10 additions & 4 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,6 @@ ipcMain.once('loadingScreenReady', () => {

ipcMain.once('frontendReady', async () => {
logInfo('Frontend Ready', LogPrefix.Backend)
await initExtension(hpApi)
// wait for mm SW to initialize
await wait(5000)
ipcMain.emit('reloadApp')
handleProtocol([openUrlArgument, ...process.argv])
setTimeout(() => {
logInfo('Starting the Download Queue', LogPrefix.Backend)
Expand All @@ -719,6 +715,16 @@ ipcMain.once('frontendReady', async () => {
watchLibraryChanges()
})

ipcMain.once('reloadForMM', async () => {
logInfo('Initializing Extensions', LogPrefix.Backend)
await initExtension(hpApi)
// wait for mm SW to initialize
logInfo('Waiting for SW to initialize', LogPrefix.Backend)
await wait(5000)
logInfo('Reloading the app to apply changes...', LogPrefix.Backend)
ipcMain.emit('reloadApp')
})

// Maybe this can help with white screens
process.on('uncaughtException', async (err) => {
logError(
Expand Down
1 change: 1 addition & 0 deletions src/common/typedefs/ipcBridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ interface SyncIPCFunctions extends HyperPlaySyncIPCFunctions {
focusMainWindow: () => void
openOnboarding: () => void
restartClient: () => void
reloadForMM: () => void
}

interface RequestArguments {
Expand Down
13 changes: 9 additions & 4 deletions src/frontend/components/UI/AppVersion/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import React, { useEffect, useState } from 'react'

const storage = window.localStorage
let lastVersion = storage.getItem('last_version')?.replaceAll('"', '')
if (lastVersion === undefined) {
lastVersion = ''
}
const lastVersion = storage.getItem('last_version')?.replaceAll('"', '')

export default function AppVersion() {
const [appVersion, setAppVersion] = useState(lastVersion)

useEffect(() => {
window.api.getAppVersion().then((version) => {
if (version !== lastVersion) {
window.api.logInfo(
`Updated to a new version, reloading the MetaMask extension. Old version: ${lastVersion}, new version: ${version}`
)
window.api.reloadForMM()
} else {
window.api.logInfo('No new version detected. Wont reload the app')
}
storage.setItem('last_version', JSON.stringify(version))
setAppVersion(version)
})
Expand Down
Loading