fix: 141125/fix_bug_module_wasm_not_found

This commit is contained in:
NguyenAnhQuan 2025-11-14 15:23:46 +07:00
parent 264b138f1c
commit cfe54b3662
12 changed files with 102 additions and 44 deletions

View File

@ -4,7 +4,66 @@ import path from 'path'
import { encrypt, fromEncryptedJson } from './utils/keystore' import { encrypt, fromEncryptedJson } from './utils/keystore'
import logger from './logger' 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') const WALLETS_DIR = path.resolve(app.getPath('userData'), 'wallets')
fs.mkdirSync(WALLETS_DIR, { recursive: true }) fs.mkdirSync(WALLETS_DIR, { recursive: true })

View File

@ -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 // This method will be called when Electron has finished

View File

@ -6,14 +6,26 @@ import { MakerRpm } from '@electron-forge/maker-rpm';
import { VitePlugin } from '@electron-forge/plugin-vite'; import { VitePlugin } from '@electron-forge/plugin-vite';
import { FusesPlugin } from '@electron-forge/plugin-fuses'; import { FusesPlugin } from '@electron-forge/plugin-fuses';
import { FuseV1Options, FuseVersion } from '@electron/fuses'; import { FuseV1Options, FuseVersion } from '@electron/fuses';
import { AutoUnpackNativesPlugin } from '@electron-forge/plugin-auto-unpack-natives';
const config: ForgeConfig = { const config: ForgeConfig = {
packagerConfig: { packagerConfig: {
asar: true, asar: true,
extraResource: [
'./packages/neptune-native',
'./packages/neptune-wasm',
]
},
rebuildConfig: {
onlyModules: ['@neptune/native'],
force: true,
}, },
rebuildConfig: {},
makers: [ 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 MakerZIP({}, ['darwin']),
new MakerRpm({}), new MakerRpm({}),
new MakerDeb({}), new MakerDeb({}),
@ -53,6 +65,9 @@ const config: ForgeConfig = {
[FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true, [FuseV1Options.EnableEmbeddedAsarIntegrityValidation]: true,
[FuseV1Options.OnlyLoadAppFromAsar]: true, [FuseV1Options.OnlyLoadAppFromAsar]: true,
}), }),
new AutoUnpackNativesPlugin({
packageJsonPropNames: ['@neptune/native'],
}),
], ],
}; };

View File

@ -4,14 +4,6 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.png" /> <link rel="icon" type="image/svg+xml" href="/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self';
script-src 'self';
style-src 'self';
connect-src 'self' ;
img-src 'self' data:;"
/>
<title>Neptune Web Wallet</title> <title>Neptune Web Wallet</title>
</head> </head>

17
package-lock.json generated
View File

@ -4401,9 +4401,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/baseline-browser-mapping": { "node_modules/baseline-browser-mapping": {
"version": "2.8.27", "version": "2.8.28",
"resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.27.tgz", "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.28.tgz",
"integrity": "sha512-2CXFpkjVnY2FT+B6GrSYxzYf65BJWEqz5tIRHCvNsZZ2F3CmsCB37h8SpYgKG7y9C4YAeTipIPWG7EmFmhAeXA==", "integrity": "sha512-gYjt7OIqdM0PcttNYP2aVrr2G0bMALkBaoehD4BuRGjAOtipg0b6wHg1yNL+s5zSnLZZrGHOw4IrND8CD+3oIQ==",
"dev": true, "dev": true,
"license": "Apache-2.0", "license": "Apache-2.0",
"bin": { "bin": {
@ -8763,10 +8763,6 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/neptune-native": {
"resolved": "packages/neptune-native",
"link": true
},
"node_modules/nice-try": { "node_modules/nice-try": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz",
@ -8775,9 +8771,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/node-abi": { "node_modules/node-abi": {
"version": "3.80.0", "version": "3.82.0",
"resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.80.0.tgz", "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.82.0.tgz",
"integrity": "sha512-LyPuZJcI9HVwzXK1GPxWNzrr+vr8Hp/3UqlmWxxh8p54U1ZbclOqbSog9lWHaCX+dBaiGi6n/hIX+mKu74GmPA==", "integrity": "sha512-aQuSU0xnqUUNU7rVmEB8M8pAJ/1SA/DL0tdAtr+X63+x61UJMo1Ulsp/3liX33EuA4kM8GG762/pyHtgag5PmQ==",
"dev": true, "dev": true,
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
@ -12326,6 +12322,7 @@
} }
}, },
"packages/neptune-native": { "packages/neptune-native": {
"name": "@neptune/native",
"version": "0.1.0", "version": "0.1.0",
"license": "Apache-2.0", "license": "Apache-2.0",
"devDependencies": { "devDependencies": {

View File

@ -1,6 +1,8 @@
{ {
"name": "neptune-web-wallet", "name": "neptune-web-wallet",
"version": "0.0.0", "version": "0.0.0",
"description": "Neptune Blockchain Wallet - Secure cryptocurrency wallet for Neptune network",
"author": "Neptune Team",
"private": true, "private": true,
"type": "module", "type": "module",
"workspaces": [ "workspaces": [

View File

@ -1,5 +1,5 @@
{ {
"name": "neptune-native", "name": "@neptune/native",
"version": "0.1.0", "version": "0.1.0",
"description": "Native Node.js addon for Neptune transaction building", "description": "Native Node.js addon for Neptune transaction building",
"main": "index.js", "main": "index.js",

4
src/lang/en/notFound.ts Normal file
View File

@ -0,0 +1,4 @@
export default {
title: 'The page you requested was not found.',
back: 'Back to Home',
}

View File

@ -1,15 +1,13 @@
import { createI18n } from 'vue3-i18n' import { createI18n } from 'vue3-i18n'
import { en } from './en' import { en } from './en'
import { jp } from './jp'
const messages = { const messages = {
en: en, en: en,
jp: jp,
} }
const i18n = createI18n({ const i18n = createI18n({
locale: 'jp', locale: 'en',
fallbackLocale: 'jp', fallbackLocale: 'en',
messages, messages,
} as any) } as any)

View File

@ -1,8 +1,8 @@
import { createRouter, createWebHistory } from 'vue-router' import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router'
import { routes } from './route' import { routes } from './route'
const router = createRouter({ const router = createRouter({
history: createWebHistory(), history: import.meta.env.DEV ? createWebHistory() : createWebHashHistory(),
routes, routes,
}) })

View File

@ -17,9 +17,9 @@ const { t } = useI18n()
<h3 class="h2"> <h3 class="h2">
{{ t('notFound.title') }} {{ t('notFound.title') }}
</h3> </h3>
<a href="/reservations" class="link_404"> <router-link to="/auth" class="link_404">
{{ t('notFound.back') }} {{ t('notFound.back') }}
</a> </router-link>
</div> </div>
</div> </div>
</div> </div>

View File

@ -22,11 +22,14 @@ export default defineConfig({
}), }),
], ],
optimizeDeps: { optimizeDeps: {
exclude: ['@neptune/wasm', '@neptune/native'], exclude: ['@neptune/native'],
}, },
build: { build: {
rollupOptions: { rollupOptions: {
external: ['@neptune/wasm', '@neptune/native'], external: ['@neptune/native'],
output: {
format: 'es',
},
}, },
}, },
css: { css: {