fix: package
parent
10de2465dd
commit
7a7fd046c4
|
@ -44,7 +44,7 @@
|
||||||
"vue": "^2.6.11",
|
"vue": "^2.6.11",
|
||||||
"vue-json-editor-fix-cn": "^1.4.3",
|
"vue-json-editor-fix-cn": "^1.4.3",
|
||||||
"vue-router": "^3.4.8",
|
"vue-router": "^3.4.8",
|
||||||
"@natmri/platform-napi": "0.0.8"
|
"@natmri/platform-napi": "0.0.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vue/cli-plugin-babel": "^4.5.0",
|
"@vue/cli-plugin-babel": "^4.5.0",
|
||||||
|
|
|
@ -187,6 +187,10 @@ function createWindow (startHideWindow) {
|
||||||
|
|
||||||
Menu.setApplicationMenu(null)
|
Menu.setApplicationMenu(null)
|
||||||
win.setMenu(null)
|
win.setMenu(null)
|
||||||
|
// !!IMPORTANT
|
||||||
|
if(process.platform === 'win32') {
|
||||||
|
powerMonitor.setupMainWindow(win)
|
||||||
|
}
|
||||||
|
|
||||||
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
||||||
// Load the url of the dev server if in development mode
|
// Load the url of the dev server if in development mode
|
||||||
|
@ -444,7 +448,8 @@ if (!isFirstInstance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
powerMonitor.on('shutdown', async (e) => {
|
powerMonitor.on('shutdown', async (e) => {
|
||||||
e.preventDefault()
|
if(process.platform !== 'win32')
|
||||||
|
e.preventDefault()
|
||||||
log.info('系统关机,恢复代理设置')
|
log.info('系统关机,恢复代理设置')
|
||||||
await quit()
|
await quit()
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,9 +1,23 @@
|
||||||
import { powerMonitor as _powerMonitor } from 'electron/main'
|
import { powerMonitor as _powerMonitor, BrowserWindow } from 'electron'
|
||||||
import { createShutdownBlocker, destroyShutdownBlocker } from '@natmri/platform-napi'
|
import { setMainWindowHandle, insertWndProcHook, removeWndProcHook, acquireShutdownBlock, releaseShutdownBlock } from '@natmri/platform-napi'
|
||||||
|
|
||||||
class PowerMonitor {
|
class PowerMonitor {
|
||||||
_listeners = []
|
constructor() {
|
||||||
_shutdownCallback = null
|
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) {
|
addListener(event, listener) {
|
||||||
return this.on(event, listener)
|
return this.on(event, listener)
|
||||||
|
@ -17,7 +31,8 @@ class PowerMonitor {
|
||||||
if(event === 'shutdown' && process.platform === 'win32') {
|
if(event === 'shutdown' && process.platform === 'win32') {
|
||||||
this._listeners = []
|
this._listeners = []
|
||||||
if(this._shutdownCallback) {
|
if(this._shutdownCallback) {
|
||||||
destroyShutdownBlocker()
|
removeWndProcHook()
|
||||||
|
releaseShutdownBlock()
|
||||||
this._shutdownCallback = null
|
this._shutdownCallback = null
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -30,9 +45,10 @@ class PowerMonitor {
|
||||||
if(!this._shutdownCallback) {
|
if(!this._shutdownCallback) {
|
||||||
this._shutdownCallback = async () => {
|
this._shutdownCallback = async () => {
|
||||||
await Promise.all(this._listeners.map((fn) => fn()))
|
await Promise.all(this._listeners.map((fn) => fn()))
|
||||||
destroyShutdownBlocker()
|
releaseShutdownBlock()
|
||||||
}
|
}
|
||||||
createShutdownBlocker("正在停止 DevSidecar 代理", this._shutdownCallback)
|
insertWndProcHook(this._shutdownCallback)
|
||||||
|
acquireShutdownBlock("正在停止 DevSidecar 代理")
|
||||||
}
|
}
|
||||||
this._listeners.push(listener)
|
this._listeners.push(listener)
|
||||||
} else {
|
} else {
|
||||||
|
@ -50,7 +66,7 @@ class PowerMonitor {
|
||||||
|
|
||||||
once(event, listener) {
|
once(event, listener) {
|
||||||
if(event === 'shutdown' && process.platform === 'win32') {
|
if(event === 'shutdown' && process.platform === 'win32') {
|
||||||
|
return this.on(event, listener)
|
||||||
} else {
|
} else {
|
||||||
return _powerMonitor.once(event, listener)
|
return _powerMonitor.once(event, listener)
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,19 @@ module.exports = {
|
||||||
},
|
},
|
||||||
pluginOptions: {
|
pluginOptions: {
|
||||||
electronBuilder: {
|
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,
|
nodeIntegration: true,
|
||||||
// Provide an array of files that, when changed, will recompile the main process and restart Electron
|
// 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
|
// Your main process file will be added by default
|
||||||
|
|
Loading…
Reference in New Issue