A full-featured download manager.
feat: app ui respond to system theme changed
Dr_rOot5067ad7306f0
diff --git a/src/renderer/components/Command/index.js b/src/renderer/components/Command/index.jsindex 18880a61..638e9fd4 100644--- a/src/renderer/components/Command/index.js+++ b/src/renderer/components/Command/index.js@@ -9,6 +9,10 @@ import { buildFileList } from '@shared/utils'const commands = new CommandManager()const i18n = getLocaleManager().getI18n()+function updateSystemTheme (theme) {+ store.dispatch('app/updateSystemTheme', theme)+}+function showAboutPanel () {store.dispatch('app/showAboutPanel')}@@ -67,6 +71,7 @@ function resumeAllTask () {store.dispatch('task/resumeAllTask')}+commands.register('application:theme', updateSystemTheme)commands.register('application:about', showAboutPanel)commands.register('application:new-task', showAddTask)commands.register('application:new-bt-task', showAddTask)diff --git a/src/renderer/components/Native/utils.js b/src/renderer/components/Native/utils.jsindex ab12a3e2..a260f1c5 100644--- a/src/renderer/components/Native/utils.js+++ b/src/renderer/components/Native/utils.js@@ -6,6 +6,7 @@ import {getTaskFullPath,bytesToSize} from '@shared/utils'+import { LIGHT_THEME, DARK_THEME } from '@shared/constants'const remote = is.renderer() ? require('electron').remote : {}@@ -122,3 +123,12 @@ export function clearRecentTasks () {}remote.app.clearRecentDocuments()}++export function getSystemTheme () {+ let result = LIGHT_THEME+ if (!is.macOS()) {+ return result+ }+ result = remote.systemPreferences.isDarkMode() ? DARK_THEME : LIGHT_THEME+ return result+}diff --git a/src/renderer/pages/index/App.vue b/src/renderer/pages/index/App.vueindex 73a63604..d5a2a6f6 100644--- a/src/renderer/pages/index/App.vue+++ b/src/renderer/pages/index/App.vue@@ -27,15 +27,45 @@[Ipc.name]: Ipc},computed: {+ ...mapState('app', {+ systemTheme: state => state.systemTheme+ }),...mapState('preference', {showWindowActions: state => {return (is.windows() || is.linux()) && state.config.hideAppMenu},- rpcSecret: state => state.config.rpcSecret- })+ rpcSecret: state => state.config.rpcSecret,+ theme: state => state.config.theme,+ locale: state => state.config.locale+ }),+ themeClass: function () {+ if (this.theme === 'auto') {+ return `theme-${this.systemTheme}`+ } else {+ return `theme-${this.theme}`+ }+ },+ i18nClass: function () {+ return `i18n-${this.locale}`+ }},methods: {- isRenderer: is.renderer+ isRenderer: is.renderer,+ updateRootClassName: function () {+ const { themeClass = '', i18nClass = '' } = this+ document.documentElement.className = `${themeClass} ${i18nClass}`+ }+ },+ beforeMount: function () {+ this.updateRootClassName()+ },+ watch: {+ themeClass: function (val, oldVal) {+ this.updateRootClassName()+ },+ i18nClass: function (val, oldVal) {+ this.updateRootClassName()+ }}}</script>diff --git a/src/renderer/store/modules/app.js b/src/renderer/store/modules/app.jsindex 128f9684..def6214d 100644--- a/src/renderer/store/modules/app.js+++ b/src/renderer/store/modules/app.js@@ -1,5 +1,6 @@import is from 'electron-is'import api from '@/api'+import { getSystemTheme } from '@/components/Native/utils'const BASE_INTERVAL = 1000const PER_INTERVAL = 100@@ -7,6 +8,7 @@ const MIN_INTERVAL = 500const MAX_INTERVAL = 6000const state = {+ systemTheme: getSystemTheme(),aboutPanelVisible: false,engineInfo: {version: '',@@ -30,6 +32,9 @@ const getters = {}const mutations = {+ CHANGE_SYSTEM_THEME (state, theme) {+ state.systemTheme = theme+ },CHANGE_ABOUT_PANEL_VISIBLE (state, visible) {state.aboutPanelVisible = visible},@@ -77,6 +82,9 @@ const mutations = {}const actions = {+ updateSystemTheme ({ commit }, theme) {+ commit('CHANGE_SYSTEM_THEME', theme)+ },showAboutPanel ({ commit }) {commit('CHANGE_ABOUT_PANEL_VISIBLE', true)},