fix: package

pull/377/head
starknt 2024-10-18 09:01:16 +08:00
parent 10de2465dd
commit 7a7fd046c4
4 changed files with 44 additions and 10 deletions

View File

@ -44,7 +44,7 @@
"vue": "^2.6.11",
"vue-json-editor-fix-cn": "^1.4.3",
"vue-router": "^3.4.8",
"@natmri/platform-napi": "0.0.8"
"@natmri/platform-napi": "0.0.7"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.5.0",

View File

@ -187,6 +187,10 @@ function createWindow (startHideWindow) {
Menu.setApplicationMenu(null)
win.setMenu(null)
// !!IMPORTANT
if(process.platform === 'win32') {
powerMonitor.setupMainWindow(win)
}
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
@ -444,6 +448,7 @@ if (!isFirstInstance) {
}
powerMonitor.on('shutdown', async (e) => {
if(process.platform !== 'win32')
e.preventDefault()
log.info('系统关机,恢复代理设置')
await quit()

View File

@ -1,9 +1,23 @@
import { powerMonitor as _powerMonitor } from 'electron/main'
import { createShutdownBlocker, destroyShutdownBlocker } from '@natmri/platform-napi'
import { powerMonitor as _powerMonitor, BrowserWindow } from 'electron'
import { setMainWindowHandle, insertWndProcHook, removeWndProcHook, acquireShutdownBlock, releaseShutdownBlock } from '@natmri/platform-napi'
class PowerMonitor {
_listeners = []
_shutdownCallback = null
constructor() {
this.setup = false
this._listeners = []
this._shutdownCallback = null
}
/**
*
* @param {BrowserWindow} window
*/
setupMainWindow(window) {
if(!this.setup) {
setMainWindowHandle(window.getNativeWindowHandle().readBigInt64LE())
this.setup = true
}
}
addListener(event, listener) {
return this.on(event, listener)
@ -17,7 +31,8 @@ class PowerMonitor {
if(event === 'shutdown' && process.platform === 'win32') {
this._listeners = []
if(this._shutdownCallback) {
destroyShutdownBlocker()
removeWndProcHook()
releaseShutdownBlock()
this._shutdownCallback = null
}
} else {
@ -30,9 +45,10 @@ class PowerMonitor {
if(!this._shutdownCallback) {
this._shutdownCallback = async () => {
await Promise.all(this._listeners.map((fn) => fn()))
destroyShutdownBlocker()
releaseShutdownBlock()
}
createShutdownBlocker("正在停止 DevSidecar 代理", this._shutdownCallback)
insertWndProcHook(this._shutdownCallback)
acquireShutdownBlock("正在停止 DevSidecar 代理")
}
this._listeners.push(listener)
} else {
@ -50,7 +66,7 @@ class PowerMonitor {
once(event, listener) {
if(event === 'shutdown' && process.platform === 'win32') {
return this.on(event, listener)
} else {
return _powerMonitor.once(event, listener)
}

View File

@ -32,6 +32,19 @@ module.exports = {
},
pluginOptions: {
electronBuilder: {
externals: [
'@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"
],
nodeIntegration: true,
// Provide an array of files that, when changed, will recompile the main process and restart Electron
// Your main process file will be added by default