Skip to content

A full-featured download manager.

refactor: save preference use ipc message

Dr_rOote47816e27347
diff --git a/src/main/Application.js b/src/main/Application.js
index 5574fbfe..0989fd09 100644
--- a/src/main/Application.js
+++ b/src/main/Application.js
@@ -3,6 +3,7 @@ import { app, shell, dialog, ipcMain } from 'electron'
import is from 'electron-is'
import { readFile } from 'fs'
import { extname, basename } from 'path'
+import { isEmpty } from 'lodash'
import logger from './core/Logger'
import ConfigManager from './core/ConfigManager'
@@ -48,12 +49,13 @@ export default class Application extends EventEmitter {
this.trayManager = new TrayManager()
- this.autoLaunchManager = new AutoLaunchManager()
- this.initThemeManager()
+ this.autoLaunchManager = new AutoLaunchManager()
this.energyManager = new EnergyManager()
+ this.initThemeManager()
+
this.initUpdaterManager()
this.initProtocolManager()
@@ -304,6 +306,20 @@ export default class Application extends EventEmitter {
}
handleCommands () {
+ this.on('application:save-preference', (config) => {
+ console.log('application:save-preference.config====>', config)
+ const { system, user } = config
+ if (!isEmpty(system)) {
+ console.info('[Motrix] main save system config: ', system)
+ this.configManager.setSystemConfig(system)
+ }
+
+ if (!isEmpty(user)) {
+ console.info('[Motrix] main save user config: ', user)
+ this.configManager.setUserConfig(user)
+ }
+ })
+
this.on('application:relaunch', () => {
this.relaunch()
})
diff --git a/src/renderer/api/Api.js b/src/renderer/api/Api.js
index 3fcd2575..ada00330 100644
--- a/src/renderer/api/Api.js
+++ b/src/renderer/api/Api.js
@@ -1,4 +1,4 @@
-import { remote } from 'electron'
+import { ipcRenderer, remote } from 'electron'
import is from 'electron-is'
import { isEmpty } from 'lodash'
import Aria2 from 'aria2'
@@ -98,17 +98,21 @@ export default class Api {
const { user, system, others } = separateConfig(params)
if (!isEmpty(system)) {
console.info('[Motrix] save system config: ', system)
- application.configManager.setSystemConfig(system)
+ ipcRenderer.send('command', 'application:save-preference', {
+ system
+ })
this.changeGlobalOption(system)
}
if (!isEmpty(user)) {
console.info('[Motrix] save user config: ', user)
- application.configManager.setUserConfig(user)
+ ipcRenderer.send('command', 'application:save-preference', {
+ user
+ })
}
if (!isEmpty(others)) {
- console.info('[Motrix] save config found iillegal key: ', others)
+ console.info('[Motrix] save config found illegal key: ', others)
}
}