A full-featured download manager.
refactor: save preference config
Dr_rOotcdc196c2b05a
diff --git a/src/main/Application.js b/src/main/Application.jsindex f91b3ea4..f3be50d4 100644--- a/src/main/Application.js+++ b/src/main/Application.js@@ -317,20 +317,23 @@ export default class Application extends EventEmitter {// }, 500)}- 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)- }+ savePreference (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)+ this.engineClient.changeGlobalOption(system)+ }- if (!isEmpty(user)) {- console.info('[Motrix] main save user config: ', user)- this.configManager.setUserConfig(user)- }- })+ if (!isEmpty(user)) {+ console.info('[Motrix] main save user config: ', user)+ this.configManager.setUserConfig(user)+ }+ }++ handleCommands () {+ this.on('application:save-preference', this.savePreference)this.on('application:relaunch', () => {this.relaunch()diff --git a/src/renderer/api/Api.js b/src/renderer/api/Api.jsindex db6b2fbe..0c7866c3 100644--- a/src/renderer/api/Api.js+++ b/src/renderer/api/Api.js@@ -96,24 +96,24 @@ export default class Api {savePreferenceToNativeStore (params = {}) {const { user, system, others } = separateConfig(params)- if (!isEmpty(system)) {- console.info('[Motrix] save system config: ', system)- ipcRenderer.send('command', 'application:save-preference', {- system- })- this.changeGlobalOption(system)- }+ let config = {}if (!isEmpty(user)) {console.info('[Motrix] save user config: ', user)- ipcRenderer.send('command', 'application:save-preference', {- user- })+ config.user = user+ }++ if (!isEmpty(system)) {+ console.info('[Motrix] save system config: ', system)+ config.system = system+ this.updateActiveTaskOption(system)}if (!isEmpty(others)) {console.info('[Motrix] save config found illegal key: ', others)}++ ipcRenderer.send('command', 'application:save-preference', config)}getVersion () {@@ -147,6 +147,18 @@ export default class Api {})}+ updateActiveTaskOption (options) {+ this.fetchTaskList({ type: 'active' })+ .then((data) => {+ if (isEmpty(data)) {+ return+ }++ const gids = data.map((task) => task.gid)+ this.batchChangeOption({ gids, options })+ })+ }+changeOption (params = {}) {let { gid, options = {} } = paramsoptions = formatOptionsForEngine(options)@@ -157,6 +169,18 @@ export default class Api {return this.client.call('changeOption', ...args)}+ batchChangeOption (params = {}) {+ let { gids, options = {} } = params+ options = formatOptionsForEngine(options)++ const data = gids.map((gid, index) => {+ const kebabOptions = changeKeysToKebabCase(options)+ const args = compactUndefined([gid, kebabOptions])+ return [ 'aria2.changeOption', ...args ]+ })+ return this.client.multicall(data)+ }+getGlobalStat () {return this.client.call('getGlobalStat')}diff --git a/src/shared/configKeys.js b/src/shared/configKeys.jsindex 24267bd6..ec554320 100644--- a/src/shared/configKeys.js+++ b/src/shared/configKeys.js@@ -1,11 +1,13 @@const userKeys = ['all-proxy-backup','auto-check-update',+ 'auto-sync-tracker','cookie','enable-egg-features','hide-app-menu','keep-window-state','last-check-update-time',+ 'last-sync-tracker-time','locale','log-path','new-task-show-downloading',@@ -68,6 +70,7 @@ const systemKeys = ['follow-metalink','follow-torrent','force-save',+ 'force-sequential','ftp-passwd','ftp-pasv','ftp-proxy-passwd',