🐛 Fix(custom): remove listener before unmount

This commit is contained in:
Kuingsmile 2024-05-25 21:06:27 +08:00
parent c102ac5158
commit 8b21e8407c
5 changed files with 8 additions and 9 deletions

View File

@ -180,8 +180,8 @@ class LifeCycle {
shortKeyHandler.init() shortKeyHandler.init()
}) })
server.startup() server.startup()
startFileServer()
webServer.start() webServer.start()
startFileServer()
if (process.env.NODE_ENV !== 'development') { if (process.env.NODE_ENV !== 'development') {
handleStartUpFiles(process.argv, process.cwd()) handleStartUpFiles(process.argv, process.cwd())
} }
@ -229,7 +229,7 @@ class LifeCycle {
} }
#onRunning () { #onRunning () {
app.on('second-instance', (event, commandLine, workingDirectory) => { app.on('second-instance', (_, commandLine, workingDirectory) => {
logger.info('detect second instance') logger.info('detect second instance')
const result = handleStartUpFiles(commandLine, workingDirectory) const result = handleStartUpFiles(commandLine, workingDirectory)
if (!result) { if (!result) {

View File

@ -11,8 +11,7 @@ class ManageDB {
this.#db = new JSONStore(this.#ctx.configPath) this.#db = new JSONStore(this.#ctx.configPath)
let initParams: IStringKeyMap = { let initParams: IStringKeyMap = {
picBed: {}, picBed: {},
settings: {}, settings: {}
currentPicBed: 'placeholder'
} }
for (let key in initParams) { for (let key in initParams) {
if (!this.#db.has(key)) { if (!this.#db.has(key)) {

View File

@ -31,7 +31,7 @@ export class ManageApi extends EventEmitter implements ManageApiType {
constructor (currentPicBed: string = '') { constructor (currentPicBed: string = '') {
super() super()
this.currentPicBed = currentPicBed || (this.getConfig('currentPicBed') ?? 'placeholder') this.currentPicBed = currentPicBed || 'placeholder'
this.configPath = managePathChecker() this.configPath = managePathChecker()
this.initConfigPath() this.initConfigPath()
this.logger = new ManageLogger(this) this.logger = new ManageLogger(this)

View File

@ -192,14 +192,14 @@ function uploadClipboardFiles () {
onBeforeMount(() => { onBeforeMount(() => {
disableDragFile() disableDragFile()
getData() getData()
ipcRenderer.on('dragFiles', async (event: Event, _files: string[]) => { ipcRenderer.on('dragFiles', async (_: Event, _files: string[]) => {
for (let i = 0; i < _files.length; i++) { for (let i = 0; i < _files.length; i++) {
const item = _files[i] const item = _files[i]
await $$db.insert(item) await $$db.insert(item)
} }
files.value = (await $$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 })).data files.value = (await $$db.get<ImgInfo>({ orderBy: 'desc', limit: 5 })).data
}) })
ipcRenderer.on('clipboardFiles', (event: Event, files: ImgInfo[]) => { ipcRenderer.on('clipboardFiles', (_: Event, files: ImgInfo[]) => {
clipboardFiles.value = files clipboardFiles.value = files
}) })
ipcRenderer.on('uploadFiles', async () => { ipcRenderer.on('uploadFiles', async () => {
@ -214,7 +214,7 @@ onBeforeMount(() => {
onBeforeUnmount(() => { onBeforeUnmount(() => {
ipcRenderer.removeAllListeners('dragFiles') ipcRenderer.removeAllListeners('dragFiles')
ipcRenderer.removeAllListeners('clipboardFiles') ipcRenderer.removeAllListeners('clipboardFiles')
ipcRenderer.removeAllListeners('uploadClipboardFiles') ipcRenderer.removeAllListeners('uploadFiles')
ipcRenderer.removeAllListeners('updateFiles') ipcRenderer.removeAllListeners('updateFiles')
}) })
</script> </script>

View File

@ -57,7 +57,7 @@ export class GalleryDB implements IGalleryDB {
#msgHandler<T> (method: string, ...args: any[]): Promise<T> { #msgHandler<T> (method: string, ...args: any[]): Promise<T> {
return new Promise((resolve) => { return new Promise((resolve) => {
const callbackId = uuid() const callbackId = uuid()
const callback = (event: IpcRendererEvent, data: T, returnCallbackId: string) => { const callback = (_: IpcRendererEvent, data: T, returnCallbackId: string) => {
if (returnCallbackId === callbackId) { if (returnCallbackId === callbackId) {
resolve(data) resolve(data)
ipcRenderer.removeListener(method, callback) ipcRenderer.removeListener(method, callback)