From cfe54b36628c772df7ce151175af300da00dac5d Mon Sep 17 00:00:00 2001 From: NguyenAnhQuan Date: Fri, 14 Nov 2025 15:23:46 +0700 Subject: [PATCH] fix: 141125/fix_bug_module_wasm_not_found --- electron/ipcHandlers.ts | 61 +++++++++++++++++++++++++++- electron/main.ts | 12 ------ forge.config.ts | 19 ++++++++- index.html | 8 ---- package-lock.json | 17 ++++---- package.json | 2 + packages/neptune-native/package.json | 2 +- src/lang/en/notFound.ts | 4 ++ src/lang/index.ts | 6 +-- src/router/index.ts | 4 +- src/views/NotFound/NotFoundView.vue | 4 +- vite.config.ts | 7 +++- 12 files changed, 102 insertions(+), 44 deletions(-) create mode 100644 src/lang/en/notFound.ts diff --git a/electron/ipcHandlers.ts b/electron/ipcHandlers.ts index 517c77c..f7606ca 100644 --- a/electron/ipcHandlers.ts +++ b/electron/ipcHandlers.ts @@ -4,7 +4,66 @@ import path from 'path' import { encrypt, fromEncryptedJson } from './utils/keystore' import logger from './logger' -const neptuneNative = require('@neptune/native') +let neptuneNative: any = null + +function loadNativeModule() { + try { + // Try normal require first (works in dev) + neptuneNative = require('@neptune/native') + logger.info('[Native] Loaded native module') + return + } catch (err) { + logger.error('[Native] Failed to load native module') + } + + // Fallback: load from Resources in packaged app + try { + const platform = process.platform + const arch = process.arch + + // Determine the correct .node file + let nodeFileName = '' + if (platform === 'win32' && arch === 'x64') { + nodeFileName = 'neptune-native.win32-x64-msvc.node' + } else if (platform === 'linux' && arch === 'x64') { + nodeFileName = 'neptune-native.linux-x64-gnu.node' + } else if (platform === 'darwin' && arch === 'arm64') { + nodeFileName = 'neptune-native.darwin-arm64.node' + } else { + throw new Error(`Unsupported platform: ${platform}-${arch}`) + } + + // Try multiple possible locations + const possiblePaths = [ + path.join(process.resourcesPath, 'packages', 'neptune-native', nodeFileName), + path.join(process.resourcesPath, 'neptune-native', nodeFileName), + path.join(process.resourcesPath, nodeFileName), + path.join(process.resourcesPath, 'app.asar.unpacked', 'packages', 'neptune-native', nodeFileName), + path.join(process.resourcesPath, 'app.asar.unpacked', 'node_modules', '@neptune', 'native', nodeFileName), + ] + + let nativeBinding: any = null + for (const nodePath of possiblePaths) { + if (fs.existsSync(nodePath)) { + nativeBinding = require(nodePath) + break + } + } + + if (!nativeBinding) { + throw new Error(`Native module not found`) + } + + neptuneNative = nativeBinding + logger.info('[Native] Successfully loaded native module') + } catch (error) { + logger.error('[Native] Failed to load native module:') + throw error + } +} + +// Initialize the native module +loadNativeModule() const WALLETS_DIR = path.resolve(app.getPath('userData'), 'wallets') fs.mkdirSync(WALLETS_DIR, { recursive: true }) diff --git a/electron/main.ts b/electron/main.ts index 942458e..a24424a 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -85,18 +85,6 @@ const createWindow = () => { } }) }) - - if (!isDev) { - mainWindow.removeMenu() - mainWindow.webContents.on('before-input-event', (event, input) => { - if (input.control && input.shift && input.key.toLowerCase() === 'i') { - event.preventDefault() - } - }) - } - mainWindow.webContents.on('devtools-opened', () => { - if (!isDev) mainWindow.webContents.closeDevTools() - }) } // This method will be called when Electron has finished diff --git a/forge.config.ts b/forge.config.ts index 49f5115..bd399d7 100644 --- a/forge.config.ts +++ b/forge.config.ts @@ -6,14 +6,26 @@ import { MakerRpm } from '@electron-forge/maker-rpm'; import { VitePlugin } from '@electron-forge/plugin-vite'; import { FusesPlugin } from '@electron-forge/plugin-fuses'; import { FuseV1Options, FuseVersion } from '@electron/fuses'; +import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-natives'; const config: ForgeConfig = { packagerConfig: { asar: true, + extraResource: [ + './packages/neptune-native', + './packages/neptune-wasm', + ] + }, + rebuildConfig: { + onlyModules: ['@neptune/native'], + force: true, }, - rebuildConfig: {}, makers: [ - new MakerSquirrel({}), + new MakerSquirrel({ + name: 'neptune-web-wallet', + authors: 'Neptune Team', + description: 'Neptune Blockchain Wallet - Secure cryptocurrency wallet for Neptune network', + }), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({}), @@ -53,6 +65,9 @@ const config: ForgeConfig = { [FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true, [FuseV1Options.OnlyLoadAppFromAsar]: true, }), + new AutoUnpackNativesPlugin({ + packageJsonPropNames: ['@neptune/native'], + }), ], }; diff --git a/index.html b/index.html index b26720e..7639732 100644 --- a/index.html +++ b/index.html @@ -4,14 +4,6 @@ - Neptune Web Wallet diff --git a/package-lock.json b/package-lock.json index 1ce09b1..653b005 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4401,9 +4401,9 @@ "license": "MIT" }, "node_modules/baseline-browser-mapping": { - "version": "2.8.27", - "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.27.tgz", - "integrity": "sha512-2CXFpkjVnY2FT+B6GrSYxzYf65BJWEqz5tIRHCvNsZZ2F3CmsCB37h8SpYgKG7y9C4YAeTipIPWG7EmFmhAeXA==", + "version": "2.8.28", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.28.tgz", + "integrity": "sha512-gYjt7OIqdM0PcttNYP2aVrr2G0bMALkBaoehD4BuRGjAOtipg0b6wHg1yNL+s5zSnLZZrGHOw4IrND8CD+3oIQ==", "dev": true, "license": "Apache-2.0", "bin": { @@ -8763,10 +8763,6 @@ "dev": true, "license": "MIT" }, - "node_modules/neptune-native": { - "resolved": "packages/neptune-native", - "link": true - }, "node_modules/nice-try": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", @@ -8775,9 +8771,9 @@ "license": "MIT" }, "node_modules/node-abi": { - "version": "3.80.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.80.0.tgz", - "integrity": "sha512-LyPuZJcI9HVwzXK1GPxWNzrr+vr8Hp/3UqlmWxxh8p54U1ZbclOqbSog9lWHaCX+dBaiGi6n/hIX+mKu74GmPA==", + "version": "3.82.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.82.0.tgz", + "integrity": "sha512-aQuSU0xnqUUNU7rVmEB8M8pAJ/1SA/DL0tdAtr+X63+x61UJMo1Ulsp/3liX33EuA4kM8GG762/pyHtgag5PmQ==", "dev": true, "license": "MIT", "dependencies": { @@ -12326,6 +12322,7 @@ } }, "packages/neptune-native": { + "name": "@neptune/native", "version": "0.1.0", "license": "Apache-2.0", "devDependencies": { diff --git a/package.json b/package.json index f13da4f..31c1297 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,8 @@ { "name": "neptune-web-wallet", "version": "0.0.0", + "description": "Neptune Blockchain Wallet - Secure cryptocurrency wallet for Neptune network", + "author": "Neptune Team", "private": true, "type": "module", "workspaces": [ diff --git a/packages/neptune-native/package.json b/packages/neptune-native/package.json index 02770a4..ccb4c16 100644 --- a/packages/neptune-native/package.json +++ b/packages/neptune-native/package.json @@ -1,5 +1,5 @@ { - "name": "neptune-native", + "name": "@neptune/native", "version": "0.1.0", "description": "Native Node.js addon for Neptune transaction building", "main": "index.js", diff --git a/src/lang/en/notFound.ts b/src/lang/en/notFound.ts new file mode 100644 index 0000000..c2ae669 --- /dev/null +++ b/src/lang/en/notFound.ts @@ -0,0 +1,4 @@ +export default { + title: 'The page you requested was not found.', + back: 'Back to Home', +} diff --git a/src/lang/index.ts b/src/lang/index.ts index a7f4a4c..1fc5ffd 100644 --- a/src/lang/index.ts +++ b/src/lang/index.ts @@ -1,15 +1,13 @@ import { createI18n } from 'vue3-i18n' import { en } from './en' -import { jp } from './jp' const messages = { en: en, - jp: jp, } const i18n = createI18n({ - locale: 'jp', - fallbackLocale: 'jp', + locale: 'en', + fallbackLocale: 'en', messages, } as any) diff --git a/src/router/index.ts b/src/router/index.ts index ff54da1..5e21181 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,8 +1,8 @@ -import { createRouter, createWebHistory } from 'vue-router' +import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router' import { routes } from './route' const router = createRouter({ - history: createWebHistory(), + history: import.meta.env.DEV ? createWebHistory() : createWebHashHistory(), routes, }) diff --git a/src/views/NotFound/NotFoundView.vue b/src/views/NotFound/NotFoundView.vue index af2c076..97a8645 100644 --- a/src/views/NotFound/NotFoundView.vue +++ b/src/views/NotFound/NotFoundView.vue @@ -17,9 +17,9 @@ const { t } = useI18n()

{{ t('notFound.title') }}

- + {{ t('notFound.back') }} - + diff --git a/vite.config.ts b/vite.config.ts index 2428e14..7096b8f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -22,11 +22,14 @@ export default defineConfig({ }), ], optimizeDeps: { - exclude: ['@neptune/wasm', '@neptune/native'], + exclude: ['@neptune/native'], }, build: { rollupOptions: { - external: ['@neptune/wasm', '@neptune/native'], + external: ['@neptune/native'], + output: { + format: 'es', + }, }, }, css: {