Skip to content

Commit

Permalink
fix/clean-resource-on-exit (janhq#1290)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan authored Jan 2, 2024
1 parent 1d90256 commit 67aa136
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/src/node/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
export class ModuleManager {
public requiredModules: Record<string, any> = {}
public cleaningResource = false

public static instance: ModuleManager = new ModuleManager()

Expand Down
21 changes: 15 additions & 6 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { handleAppIPCs } from './handlers/app'
import { handleAppUpdates } from './handlers/update'
import { handleFsIPCs } from './handlers/fs'
import { migrateExtensions } from './utils/migration'
import { dispose } from './utils/disposable'

app
.whenReady()
Expand All @@ -37,14 +38,12 @@ app
})
})

app.on('window-all-closed', () => {
ModuleManager.instance.clearImportedModules()
app.quit()
app.once('window-all-closed', () => {
cleanUpAndQuit()
})

app.on('quit', () => {
ModuleManager.instance.clearImportedModules()
app.quit()
app.once('quit', () => {
cleanUpAndQuit()
})

function createMainWindow() {
Expand Down Expand Up @@ -83,3 +82,13 @@ function handleIPCs() {
handleAppIPCs()
handleFileMangerIPCs()
}

function cleanUpAndQuit() {
if (!ModuleManager.instance.cleaningResource) {
ModuleManager.instance.cleaningResource = true
WindowManager.instance.currentWindow?.destroy()
dispose(ModuleManager.instance.requiredModules)
ModuleManager.instance.clearImportedModules()
app.quit()
}
}

0 comments on commit 67aa136

Please sign in to comment.