Skip to content

A full-featured download manager.

refactor: app theme constant

Dr_rOot4d7acb7c0ae1
diff --git a/src/main/core/ConfigManager.js b/src/main/core/ConfigManager.js
index 5aeacf91..b4565178 100644
--- a/src/main/core/ConfigManager.js
+++ b/src/main/core/ConfigManager.js
@@ -15,6 +15,7 @@ import {
NGOSANG_TRACKERS_ALL_IP_URL
} from '@shared/constants'
import { separateConfig } from '@shared/utils'
+import { APP_THEME } from '@shared/constants'
export default class ConfigManager {
constructor () {
@@ -96,7 +97,7 @@ export default class ConfigManager {
'keep-window-state': false,
'session-path': getSessionPath(),
'task-notification': true,
- 'theme': 'auto',
+ 'theme': APP_THEME.AUTO,
'auto-hide-window': false,
'tracker-source': [
NGOSANG_TRACKERS_ALL_IP_URL,
diff --git a/src/main/ui/ThemeManager.js b/src/main/ui/ThemeManager.js
index c8ca3f52..cd1ff4f6 100644
--- a/src/main/ui/ThemeManager.js
+++ b/src/main/ui/ThemeManager.js
@@ -1,7 +1,7 @@
import { EventEmitter } from 'events'
import { nativeTheme, systemPreferences } from 'electron'
import is from 'electron-is'
-import { LIGHT_THEME, DARK_THEME } from '@shared/constants'
+import { APP_THEME } from '@shared/constants'
export default class ThemeManager extends EventEmitter {
constructor (options = {}) {
@@ -15,11 +15,11 @@ export default class ThemeManager extends EventEmitter {
}
getSystemTheme () {
- let result = LIGHT_THEME
+ let result = APP_THEME.LIGHT
if (!is.macOS()) {
return result
}
- result = nativeTheme.shouldUseDarkColors ? DARK_THEME : LIGHT_THEME
+ result = nativeTheme.shouldUseDarkColors ? APP_THEME.DARK : APP_THEME.LIGHT
return result
}
@@ -36,7 +36,7 @@ export default class ThemeManager extends EventEmitter {
}
updateAppAppearance (theme) {
- if (!is.macOS() || theme !== LIGHT_THEME || theme !== DARK_THEME) {
+ if (!is.macOS() || theme !== APP_THEME.LIGHT || theme !== APP_THEME.DARK) {
return
}
systemPreferences.setAppLevelAppearance(theme)
diff --git a/src/main/ui/TrayManager.js b/src/main/ui/TrayManager.js
index a5ee3917..ec4008a3 100644
--- a/src/main/ui/TrayManager.js
+++ b/src/main/ui/TrayManager.js
@@ -8,7 +8,7 @@ import {
updateStates
} from '../utils/menu'
import { getI18n } from '@/ui/Locale'
-import { LIGHT_THEME, DARK_THEME } from '@shared/constants'
+import { APP_THEME } from '@shared/constants'
let tray = null
@@ -28,7 +28,7 @@ export default class TrayManager extends EventEmitter {
load () {
this.template = require(`../menus/tray.json`)
- const theme = nativeTheme.shouldUseDarkColors ? DARK_THEME : LIGHT_THEME
+ const theme = nativeTheme.shouldUseDarkColors ? APP_THEME.DARK : APP_THEME.LIGHT
if (is.macOS()) {
this.normalIcon = join(__static, `./mo-tray-${theme}-normal.png`)
@@ -107,7 +107,7 @@ export default class TrayManager extends EventEmitter {
tray.setImage(icon)
}
- changeIconTheme (theme = LIGHT_THEME) {
+ changeIconTheme (theme = APP_THEME.LIGHT) {
if (!is.macOS()) {
return
}
diff --git a/src/renderer/components/Native/utils.js b/src/renderer/components/Native/utils.js
index 76baf490..f2c260a8 100644
--- a/src/renderer/components/Native/utils.js
+++ b/src/renderer/components/Native/utils.js
@@ -6,7 +6,7 @@ import {
getTaskFullPath,
bytesToSize
} from '@shared/utils'
-import { LIGHT_THEME, DARK_THEME } from '@shared/constants'
+import { APP_THEME } from '@shared/constants'
const remote = is.renderer() ? require('electron').remote : {}
@@ -148,10 +148,10 @@ export function clearRecentTasks () {
}
export function getSystemTheme () {
- let result = LIGHT_THEME
+ let result = APP_THEME.LIGHT
if (!is.macOS()) {
return result
}
- result = remote.nativeTheme.shouldUseDarkColors ? DARK_THEME : LIGHT_THEME
+ result = remote.nativeTheme.shouldUseDarkColors ? APP_THEME.DARK : APP_THEME.LIGHT
return result
}
diff --git a/src/renderer/components/Preference/ThemeSwitcher.vue b/src/renderer/components/Preference/ThemeSwitcher.vue
index e9f5c6d2..18be2df0 100644
--- a/src/renderer/components/Preference/ThemeSwitcher.vue
+++ b/src/renderer/components/Preference/ThemeSwitcher.vue
@@ -2,34 +2,21 @@
<div>
<ul class="theme-switcher">
<li
- class="theme-item theme-item-auto"
- :class="{ active: currentValue === 'auto' }"
- @click.prevent="() => handleChange('auto')"
+ v-for="item in themeOptions"
+ :class="['theme-item', item.className, { active: currentValue === item.value }]"
+ :key="item.value"
+ @click.prevent="() => handleChange(item.value)"
>
<div class="theme-thumb"></div>
- <span>{{ $t('preferences.theme-auto') }}</span>
- </li>
- <li
- class="theme-item theme-item-light"
- :class="{ active: currentValue === 'light' }"
- @click.prevent="() => handleChange('light')"
- >
- <div class="theme-thumb"></div>
- <span>{{ $t('preferences.theme-light') }}</span>
- </li>
- <li
- class="theme-item theme-item-dark"
- :class="{ active: currentValue === 'dark' }"
- @click.prevent="() => handleChange('dark')"
- >
- <div class="theme-thumb"></div>
- <span>{{ $t('preferences.theme-dark') }}</span>
+ <span>{{ item.text }}</span>
</li>
</ul>
</div>
</template>
<script>
+ import { APP_THEME } from '@shared/constants'
+
export default {
name: 'mo-theme-switcher',
components: {
@@ -37,7 +24,7 @@
props: {
value: {
type: String,
- default: 'auto'
+ default: APP_THEME.AUTO
}
},
data: function () {
@@ -45,6 +32,27 @@
currentValue: this.value
}
},
+ computed: {
+ themeOptions () {
+ return [
+ {
+ className: 'theme-item-auto',
+ value: APP_THEME.AUTO,
+ text: this.$t('preferences.theme-auto')
+ },
+ {
+ className: 'theme-item-light',
+ value: APP_THEME.LIGHT,
+ text: this.$t('preferences.theme-light')
+ },
+ {
+ className: 'theme-item-dark',
+ value: APP_THEME.DARK,
+ text: this.$t('preferences.theme-dark')
+ }
+ ]
+ }
+ },
watch: {
currentValue: function (val) {
this.$emit('change', val)
diff --git a/src/shared/constants.js b/src/shared/constants.js
index 84146071..416f8e32 100644
--- a/src/shared/constants.js
+++ b/src/shared/constants.js
@@ -1,7 +1,10 @@
export const EMPTY_STRING = ''
-export const LIGHT_THEME = 'light'
-export const DARK_THEME = 'dark'
+export const APP_THEME = {
+ AUTO: 'auto',
+ LIGHT: 'light',
+ DARK: 'dark'
+}
export const APP_RUN_MODE = {
STANDARD: 1,