mirror of
https://github.com/Kuingsmile/PicList.git
synced 2026-06-08 01:01:13 +08:00
⚡ Perf(custom): add memory monitor and optimiz memory usage
This commit is contained in:
@@ -62,8 +62,8 @@ const trayWindowOptions = {
|
||||
preload: preloadPath,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
nodeIntegrationInWorker: true,
|
||||
backgroundThrottling: false,
|
||||
nodeIntegrationInWorker: false,
|
||||
backgroundThrottling: true,
|
||||
webSecurity: false
|
||||
}
|
||||
}
|
||||
@@ -83,11 +83,11 @@ const settingWindowOptions = {
|
||||
webPreferences: {
|
||||
sandbox: false,
|
||||
webviewTag: true,
|
||||
backgroundThrottling: false,
|
||||
backgroundThrottling: true,
|
||||
preload: preloadPath,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
nodeIntegrationInWorker: true,
|
||||
nodeIntegrationInWorker: false,
|
||||
webSecurity: false
|
||||
}
|
||||
} as IBrowserWindowOptions
|
||||
@@ -112,8 +112,8 @@ const miniWindowOptions = {
|
||||
preload: preloadPath,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
backgroundThrottling: false,
|
||||
nodeIntegrationInWorker: true
|
||||
backgroundThrottling: true,
|
||||
nodeIntegrationInWorker: false
|
||||
}
|
||||
} as IBrowserWindowOptions
|
||||
|
||||
@@ -133,7 +133,7 @@ const renameWindowOptions = {
|
||||
preload: preloadPath,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
nodeIntegrationInWorker: true,
|
||||
nodeIntegrationInWorker: false,
|
||||
backgroundThrottling: false
|
||||
}
|
||||
} as IBrowserWindowOptions
|
||||
@@ -158,11 +158,11 @@ const toolboxWindowOptions = {
|
||||
icon: logo,
|
||||
webPreferences: {
|
||||
sandbox: false,
|
||||
backgroundThrottling: false,
|
||||
backgroundThrottling: true,
|
||||
preload: preloadPath,
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
nodeIntegrationInWorker: true,
|
||||
nodeIntegrationInWorker: false,
|
||||
webSecurity: false
|
||||
}
|
||||
} as IBrowserWindowOptions
|
||||
|
||||
@@ -1,5 +1,31 @@
|
||||
import { EventEmitter } from 'node:events'
|
||||
|
||||
const bus = new EventEmitter()
|
||||
|
||||
export default bus
|
||||
import { EventEmitter } from 'node:events'
|
||||
|
||||
class OptimizedBus extends EventEmitter {
|
||||
constructor () {
|
||||
super()
|
||||
this.setMaxListeners(50)
|
||||
}
|
||||
|
||||
once (event: string | symbol, listener: (...args: any[]) => void): this {
|
||||
const wrappedListener = (...args: any[]) => {
|
||||
try {
|
||||
listener(...args)
|
||||
} finally {
|
||||
this.removeListener(event, wrappedListener)
|
||||
}
|
||||
}
|
||||
return super.once(event, wrappedListener)
|
||||
}
|
||||
|
||||
cleanupListeners () {
|
||||
const events = this.eventNames()
|
||||
events.forEach(event => {
|
||||
const listenerCount = this.listenerCount(event)
|
||||
console.log(` listener count (${listenerCount}) for event: ${String(event)}`)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const bus = new OptimizedBus()
|
||||
|
||||
export default bus
|
||||
|
||||
Reference in New Issue
Block a user