A full-featured download manager.
refactor: fn rename & format
Dr_rOot8303dd305b0e
diff --git a/src/main/Application.js b/src/main/Application.jsindex 05d7cd27..b924419c 100644--- a/src/main/Application.js+++ b/src/main/Application.js@@ -51,6 +51,8 @@ export default class Application extends EventEmitter {this.initTouchBarManager()+ this.initThemeManager()+this.initTrayManager()this.initDockManager()@@ -59,8 +61,6 @@ export default class Application extends EventEmitter {this.energyManager = new EnergyManager()- this.initThemeManager()-this.initUpdaterManager()this.initProtocolManager()@@ -387,8 +387,8 @@ export default class Application extends EventEmitter {initThemeManager () {this.themeManager = new ThemeManager()- this.themeManager.on('system-theme-changed', (theme) => {this.trayManager.changeIconTheme(theme)+ this.themeManager.on('system-theme-change', (theme) => {this.sendCommandToAll('application:update-system-theme', theme)})}@@ -561,8 +561,8 @@ export default class Application extends EventEmitter {this.on('application:change-locale', (locale) => {this.localeManager.changeLanguageByLocale(locale).then(() => {- this.menuManager.setup(locale)this.trayManager.setup(locale)+ this.menuManager.handleLocaleChange(locale)})})@@ -641,7 +641,7 @@ export default class Application extends EventEmitter {})}- handleConfigChanged (configName) {+ handleConfigChange (configName) {this.sendCommandToAll('application:update-preference-config', configName)}@@ -654,8 +654,8 @@ export default class Application extends EventEmitter {this.adjustMenu()})- this.configManager.userConfig.onDidAnyChange(() => this.handleConfigChanged('user'))- this.configManager.systemConfig.onDidAnyChange(() => this.handleConfigChanged('system'))+ this.configManager.userConfig.onDidAnyChange(() => this.handleConfigChange('user'))+ this.configManager.systemConfig.onDidAnyChange(() => this.handleConfigChange('system'))this.on('download-status-change', (downloading) => {this.trayManager.updateTrayByStatus(downloading)diff --git a/src/main/ui/MenuManager.js b/src/main/ui/MenuManager.jsindex 169e9454..73f3c772 100644--- a/src/main/ui/MenuManager.js+++ b/src/main/ui/MenuManager.js@@ -47,7 +47,7 @@ export default class MenuManager extends EventEmitter {this.items = flattenMenuItems(menu)}- rebuild () {+ handleLocaleChange (locale) {this.setup()}diff --git a/src/main/ui/ThemeManager.js b/src/main/ui/ThemeManager.jsindex 0ed020e0..0e27e4d2 100644--- a/src/main/ui/ThemeManager.js+++ b/src/main/ui/ThemeManager.js@@ -1,40 +1,46 @@import { EventEmitter } from 'events'import { nativeTheme, systemPreferences } from 'electron'-import is from 'electron-is'+import { APP_THEME } from '@shared/constants'+import { getSystemTheme } from '../utils'export default class ThemeManager extends EventEmitter {constructor (options = {}) {super()+ this.options = optionsthis.init()}init () {+ this.systemTheme = getSystemTheme()+this.handleEvents()}getSystemTheme () {- let result = APP_THEME.LIGHT- if (!is.macOS()) {- return result- }- result = nativeTheme.shouldUseDarkColors ? APP_THEME.DARK : APP_THEME.LIGHT- return result+ return this.systemTheme}handleEvents () {if (!is.macOS()) {return}+nativeTheme.on('updated', () => {- const theme = this.getSystemTheme()this.updateAppAppearance(theme)- this.emit('system-theme-changed', theme)+ const theme = getSystemTheme()+ this.systemTheme = theme+ console.log('nativeTheme updated===>', theme)+ this.emit('system-theme-change', theme)})}+ /**+ * deprecated+ * @see https://www.electronjs.org/docs/all#systempreferencessetapplevelappearanceappearance-macos-deprecated+ */updateAppAppearance (theme) {if (!is.macOS() || theme !== APP_THEME.LIGHT || theme !== APP_THEME.DARK) {returndiff --git a/src/main/utils/index.js b/src/main/utils/index.jsindex b321dcb8..652b6617 100644--- a/src/main/utils/index.js+++ b/src/main/utils/index.js@@ -1,12 +1,14 @@-import { app } from 'electron'+import { app, nativeTheme } from 'electron'import is from 'electron-is'import { resolve } from 'path'import { existsSync, lstatSync } from 'fs'import {+ APP_THEME,ENGINE_MAX_CONNECTION_PER_SERVER,IP_VERSION} from '@shared/constants'+import logger from '../core/Logger'import engineBinMap from '../configs/engine'@@ -133,3 +135,9 @@ export function parseArgvAsFile (argv) {export const getMaxConnectionPerServer = () => {return ENGINE_MAX_CONNECTION_PER_SERVER}++export const getSystemTheme = () => {+ let result = APP_THEME.LIGHT+ result = nativeTheme.shouldUseDarkColors ? APP_THEME.DARK : APP_THEME.LIGHT+ return result+}diff --git a/src/renderer/components/Native/EngineClient.vue b/src/renderer/components/Native/EngineClient.vueindex 5a7c4867..0ffb2553 100644--- a/src/renderer/components/Native/EngineClient.vue+++ b/src/renderer/components/Native/EngineClient.vue@@ -39,11 +39,11 @@})},watch: {- downloadSpeed (val, oldVal) {+ downloadSpeed (val) {const speed = val > 0 ? `${bytesToSize(val)}/s` : ''this.$electron.ipcRenderer.send('event', 'download-speed-change', speed)},- numActive (val, oldVal) {+ numActive (val) {this.downloading = val > 0},downloading (val, oldVal) {diff --git a/src/renderer/utils/native.js b/src/renderer/utils/native.jsindex 1691a13b..2c5ea1a3 100644--- a/src/renderer/utils/native.js+++ b/src/renderer/utils/native.js@@ -3,9 +3,9 @@ import { access, constants } from 'fs'import { Message } from 'element-ui'import {- isMagnetTask,+ bytesToSize,getTaskFullPath,- bytesToSize+ isMagnetTask} from '@shared/utils'import { APP_THEME, TASK_STATUS } from '@shared/constants'