A full-featured download manager.
fix: stop engine failed when app quit
Dr_rOot003e9ffccba0
diff --git a/src/main/Application.js b/src/main/Application.jsindex 27b3ead4..556c7ca8 100644--- a/src/main/Application.js+++ b/src/main/Application.js@@ -151,8 +151,10 @@ export default class Application extends EventEmitter {}async stopEngine () {+ logger.info('[Motrix] stopEngine===>')try {await this.engineClient.shutdown({ force: true })+ logger.info('[Motrix] stopEngine.setImmediate===>')setImmediate(() => {this.engine.stop()})@@ -509,22 +511,27 @@ export default class Application extends EventEmitter {this.windowManager.destroyWindow(page)}- async stop () {+ stop () {try {- await this.shutdownUPnPManager()-- this.energyManager.stopPowerSaveBlocker()-- await this.stopEngine()-- this.trayManager.destroy()+ const promises = [+ this.stopEngine(),+ this.shutdownUPnPManager(),+ this.energyManager.stopPowerSaveBlocker(),+ this.trayManager.destroy()+ ]++ return promises} catch (err) {logger.warn('[Motrix] stop error: ', err.message)}}+ async stopAllSettled () {+ await Promise.allSettled(this.stop())+ }+async quit () {- await this.stop()+ await this.stopAllSettled()app.exit()}@@ -644,7 +651,7 @@ export default class Application extends EventEmitter {this.updateManager.on('will-updated', async (event) => {this.windowManager.setWillQuit(true)- await this.stop()+ await this.stopAllSettled()})this.updateManager.on('update-error', (event) => {@@ -654,7 +661,7 @@ export default class Application extends EventEmitter {}async relaunch () {- await this.stop()+ await this.stopAllSettled()app.relaunch()app.exit()}diff --git a/src/main/Launcher.js b/src/main/Launcher.jsindex b2cc33d4..45c4378f 100644--- a/src/main/Launcher.js+++ b/src/main/Launcher.js@@ -183,6 +183,7 @@ export default class Launcher extends EventEmitter {app.on('will-quit', () => {logger.info('[Motrix] will-quit')if (global.application) {+ logger.info('[Motrix] will-quit.application.stop')global.application.stop()}})diff --git a/src/main/core/EnergyManager.js b/src/main/core/EnergyManager.jsindex e954cf69..ea57ff17 100644--- a/src/main/core/EnergyManager.js+++ b/src/main/core/EnergyManager.js@@ -5,6 +5,7 @@ import logger from './Logger'let psbIdexport default class EnergyManager {startPowerSaveBlocker () {+ logger.info('[Motrix] EnergyManager.startPowerSaveBlocker', psbId)if (psbId && powerSaveBlocker.isStarted(psbId)) {return}@@ -14,6 +15,7 @@ export default class EnergyManager {}stopPowerSaveBlocker () {+ logger.info('[Motrix] EnergyManager.stopPowerSaveBlocker', psbId)if (typeof psbId === 'undefined' || !powerSaveBlocker.isStarted(psbId)) {return}diff --git a/src/main/core/Engine.js b/src/main/core/Engine.jsindex 95008da7..7c409dda 100644--- a/src/main/core/Engine.js+++ b/src/main/core/Engine.js@@ -67,6 +67,7 @@ export default class Engine {}stop () {+ logger.info('[Motrix] engine.stop.instance')if (this.instance) {this.instance.kill()this.instance = nulldiff --git a/src/main/ui/TrayManager.js b/src/main/ui/TrayManager.jsindex b592ac0b..dc2543cd 100644--- a/src/main/ui/TrayManager.js+++ b/src/main/ui/TrayManager.js@@ -5,6 +5,7 @@ import is from 'electron-is'import { APP_RUN_MODE, APP_THEME } from '@shared/constants'import { getInverseTheme } from '@shared/utils'+import logger from '../core/Logger'import { getI18n } from './Locale'import {translateTemplate,@@ -12,7 +13,6 @@ import {updateStates} from '../utils/menu'import { convertArrayBufferToBuffer } from '../utils/index'-// import logger from '../core/Logger'let tray = nullconst { platform } = process@@ -357,6 +357,7 @@ export default class TrayManager extends EventEmitter {}destroy () {+ logger.info('[Motrix] TrayManager.destroy')if (tray) {this.unbindEvents()}