Skip to content

Commit

Permalink
bugfix: 修复 MacOS 启动报错 `Error: Cannot found module '@natmri/platform…
Browse files Browse the repository at this point in the history
…-napi-darwin-x64'` 的问题
  • Loading branch information
wangliang181230 committed Nov 7, 2024
1 parent 7f06be0 commit 2710f20
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@docmirror/dev-sidecar": "^1.8.9",
"@docmirror/mitmproxy": "^1.8.9",
"@mihomo-party/sysproxy": "^2.0.4",
"@natmri/platform-napi": "0.0.7",
"@natmri/platform-napi": "^0.0.7",
"adm-zip": "^0.5.5",
"ant-design-vue": "^1.6.5",
"compressing": "^1.5.1",
Expand Down
10 changes: 6 additions & 4 deletions packages/gui/src/background.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict'
/* global __static */
import path from 'path'
import { app, protocol, BrowserWindow, Menu, Tray, ipcMain, dialog, nativeImage, nativeTheme, globalShortcut } from 'electron'
import { powerMonitor } from './background/powerMonitor'
import { app, protocol, BrowserWindow, Menu, Tray, ipcMain, dialog, powerMonitor, nativeImage, nativeTheme, globalShortcut } from 'electron'
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
import backend from './bridge/backend'
import DevSidecar from '@docmirror/dev-sidecar'
Expand All @@ -15,6 +14,9 @@ const isMac = process.platform === 'darwin'
// import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
const isDevelopment = process.env.NODE_ENV !== 'production'

// 避免其他系统出现异常,只有 Windows 使用 './background/powerMonitor'
const _powerMonitor = isWindows ? require('./background/powerMonitor').powerMonitor : powerMonitor

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
Expand Down Expand Up @@ -192,7 +194,7 @@ function createWindow (startHideWindow) {

// !!IMPORTANT
if (isWindows) {
powerMonitor.setupMainWindow(win)
_powerMonitor.setupMainWindow(win)
}

if (process.env.WEBPACK_DEV_SERVER_URL) {
Expand Down Expand Up @@ -450,7 +452,7 @@ if (!isFirstInstance) {
log.info('error:', err)
}

powerMonitor.on('shutdown', async (e) => {
_powerMonitor.on('shutdown', async (e) => {
if (e) {
e.preventDefault()
}
Expand Down
20 changes: 10 additions & 10 deletions packages/gui/vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ module.exports = {
'@mihomo-party/sysproxy-darwin-x64',
'@mihomo-party/sysproxy-darwin-arm64',
'@natmri/platform-napi',
"@natmri/platform-napi-win32-x64-msvc",
"@natmri/platform-napi-darwin-x64",
"@natmri/platform-napi-linux-x64-gnu",
"@natmri/platform-napi-darwin-arm64",
"@natmri/platform-napi-linux-arm64-gnu",
"@natmri/platform-napi-linux-arm64-musl",
"@natmri/platform-napi-win32-arm64-msvc",
"@natmri/platform-napi-linux-arm-gnueabihf",
"@natmri/platform-napi-linux-x64-musl",
"@natmri/platform-napi-win32-ia32-msvc"
'@natmri/platform-napi-win32-ia32-msvc',
'@natmri/platform-napi-win32-x64-msvc',
'@natmri/platform-napi-win32-arm64-msvc',
'@natmri/platform-napi-linux-x64-gnu',
'@natmri/platform-napi-linux-x64-musl',
'@natmri/platform-napi-linux-arm64-gnu',
'@natmri/platform-napi-linux-arm64-musl',
'@natmri/platform-napi-linux-arm-gnueabihf',
'@natmri/platform-napi-darwin-x64',
'@natmri/platform-napi-darwin-arm64'
],
nodeIntegration: true,
// Provide an array of files that, when changed, will recompile the main process and restart Electron
Expand Down

0 comments on commit 2710f20

Please sign in to comment.