Skip to content

Commit 94bf0ea

Browse files
[Tech] Add import wallet feature & set MetaMask dark mode as default (#81)
* Add import wallet feature * minor refactor * resolved database concurrency errors * added restartApp, refactored/modified ExtensionHandler * cleanup of Screens/Onboarding/index.tsx * Fixed app closing to tray after importing wallet * Fixed MM not connecting within first 2 seconds of app launch * Added chrome, edge & vivaldi logo * updated submodule * chore: corrected merge * fix: fixed ExtensionHandler logic * [Feature] Change Restart App on Import to Reload (#125) * import err handling, fix skip, change restart to reload * add create new mm wallet * improve error handling * point to import wallet ext helper branch --------- Co-authored-by: Brett <27568879+BrettCleary@users.noreply.github.com>
1 parent 68ebe96 commit 94bf0ea

23 files changed

+418
-35
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
"axios": "^0.26.1",
146146
"bn.js": "^5.2.1",
147147
"check-disk-space": "^3.3.1",
148+
"classic-level": "^1.2.0",
148149
"classnames": "^2.3.1",
149150
"crc": "^4.1.1",
150151
"discord-rich-presence-typescript": "^0.0.8",

src/backend/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export {
185185
configStore,
186186
configPath,
187187
appConfigFolder,
188+
configFolder,
188189
gamesConfigPath,
189190
githubURL,
190191
iconsFolder,

src/backend/main.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { setExtensionMetadata } from 'backend/hyperplay-extension-helper/ipcHandlers/index'
12
import { initImagesCache } from './images_cache'
23
import { downloadAntiCheatData } from './anticheat/utils'
34
import {
@@ -145,10 +146,7 @@ import {
145146
import { callAbortController } from './utils/aborthandler/aborthandler'
146147
import { getDefaultSavePath } from './save_sync'
147148
import si from 'systeminformation'
148-
import {
149-
initExtensionIpcHandlerWindow,
150-
initExtension
151-
} from './hyperplay-extension-helper/ipcHandlers'
149+
import { initExtensionIpcHandlerWindow } from './hyperplay-extension-helper/ipcHandlers'
152150
import { initTrayIcon } from './tray_icon/tray_icon'
153151

154152
app.commandLine.appendSwitch('remote-debugging-port', '9222')
@@ -195,8 +193,6 @@ async function createWindow(): Promise<BrowserWindow> {
195193
}
196194
}
197195

198-
await initExtension()
199-
200196
// Create the browser window.
201197
mainWindow = new BrowserWindow({
202198
...windowProps,
@@ -266,6 +262,12 @@ async function createWindow(): Promise<BrowserWindow> {
266262
// detectVCRedist(mainWindow)
267263
// }
268264

265+
loadMainWindowURL()
266+
267+
return mainWindow
268+
}
269+
270+
const loadMainWindowURL = function () {
269271
if (!app.isPackaged) {
270272
// if (!process.env.HEROIC_NO_REACT_DEVTOOLS) {
271273
// import('electron-devtools-installer').then((devtools) => {
@@ -288,7 +290,6 @@ async function createWindow(): Promise<BrowserWindow> {
288290
autoUpdater.checkForUpdates()
289291
}
290292
}
291-
return mainWindow
292293
}
293294

294295
// This method will be called when Electron has finished
@@ -325,6 +326,8 @@ if (!gotTheLock) {
325326
handleProtocol(mainWindow, argv)
326327
})
327328
app.whenReady().then(async () => {
329+
setExtensionMetadata()
330+
328331
initOnlineMonitor()
329332

330333
getSystemInfo().then((systemInfo) =>
@@ -1609,3 +1612,7 @@ ProviderHelper.passEventCallbacks(
16091612
)
16101613

16111614
ipcMain.on('openHyperplaySite', async () => openUrlOrFile(hyperplaySite))
1615+
1616+
ipcMain.on('reloadApp', async () => {
1617+
loadMainWindowURL()
1618+
})

src/common/typedefs/ipcBridge.d.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ExtensionStore } from './../../backend/hyperplay-extension-helper/store/index'
2+
import { MetaMaskImportOptions } from './../../backend/hyperplay-extension-helper/ipcHandlers/index'
13
import { EventEmitter } from 'node:events'
24
import { IpcMainEvent, OpenDialogOptions } from 'electron'
35
import { HowLongToBeatEntry } from 'howlongtobeat'
@@ -50,14 +52,16 @@ interface HyperPlaySyncIPCFunctions {
5052
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
5153
errorExtensionRequest: (requestId: number, error: any) => void
5254
chromeSetBadgeText: (text: string) => void
55+
loadingScreenReady: () => void
56+
reloadApp: () => void
57+
createNewMetaMaskWallet: () => void
5358
}
5459

5560
interface SyncIPCFunctions extends HyperPlaySyncIPCFunctions {
5661
setZoomFactor: (zoomFactor: string) => void
5762
changeLanguage: (language: string) => void
5863
notify: (args: { title: string; body: string }) => void
5964
frontendReady: () => void
60-
loadingScreenReady: () => void
6165
lock: () => void
6266
unlock: () => void
6367
quit: () => void
@@ -115,6 +119,11 @@ interface HyperPlayAsyncIPCFunctions {
115119
chromeTabsCreate: (
116120
options: chrome.tabs.CreateProperties
117121
) => Promise<chrome.tabs.Tab>
122+
importMetaMask: (dbPath: string | null | undefined) => Promise<boolean>
123+
getMetaMaskImportOptions: (
124+
configDbPath?: string
125+
) => Promise<MetaMaskImportOptions | null>
126+
getExtensionMetadata: () => Promise<ExtensionStore['extensionMetadata']>
118127
getTabUrl: () => Promise<string>
119128
getExtensionId: () => Promise<string>
120129
}

src/frontend/ExtensionHandler/index.tsx

+16-2
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,25 @@ const ExtensionHandler = function () {
5757
useEffect(() => {
5858
/* eslint-disable-next-line @typescript-eslint/no-empty-function */
5959
let rmListeners = () => {}
60+
61+
const bindListeners = (): boolean => {
62+
if (typeof window.ethereum !== 'undefined') {
63+
rmListeners = bindEthereumListeners()
64+
return true
65+
}
66+
return false
67+
}
68+
69+
if (bindListeners()) {
70+
return () => {
71+
rmListeners()
72+
}
73+
}
74+
6075
const interval = setInterval(() => {
6176
console.log('checking for metamask extension...')
6277
if (typeof window.ethereum !== 'undefined') {
63-
console.log('metamask extension found!')
64-
rmListeners = bindEthereumListeners()
78+
bindListeners()
6579
clearInterval(interval)
6680
}
6781
}, 2000)

src/frontend/assets/brave-logo.svg

+24
Loading

src/frontend/assets/chrome-logo.svg

+1
Loading

src/frontend/assets/chromium-logo.svg

+30
Loading

0 commit comments

Comments
 (0)