diff options
author | 2021-09-14 10:34:04 +0200 | |
---|---|---|
committer | 2021-09-14 10:34:04 +0200 | |
commit | 979ec02c9a1019152be08705986337e470eabb57 (patch) | |
tree | 6021179ad8649112717a499780f475275af487f2 /src/stores/UIStore.js | |
parent | refactor: defensive programming to avoid javascript error for unread badges (diff) | |
download | ferdium-app-979ec02c9a1019152be08705986337e470eabb57.tar.gz ferdium-app-979ec02c9a1019152be08705986337e470eabb57.tar.zst ferdium-app-979ec02c9a1019152be08705986337e470eabb57.zip |
chore: codebase improvements (#1930)
Diffstat (limited to 'src/stores/UIStore.js')
-rw-r--r-- | src/stores/UIStore.js | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/src/stores/UIStore.js b/src/stores/UIStore.js deleted file mode 100644 index be675d5ed..000000000 --- a/src/stores/UIStore.js +++ /dev/null | |||
@@ -1,110 +0,0 @@ | |||
1 | import { | ||
2 | action, observable, computed, reaction, | ||
3 | } from 'mobx'; | ||
4 | import { theme } from '@meetfranz/theme'; | ||
5 | import { nativeTheme, systemPreferences } from '@electron/remote'; | ||
6 | |||
7 | import Store from './lib/Store'; | ||
8 | import { isMac, isWindows } from '../environment'; | ||
9 | |||
10 | export default class UIStore extends Store { | ||
11 | @observable showServicesUpdatedInfoBar = false; | ||
12 | |||
13 | @observable isOsDarkThemeActive = nativeTheme.shouldUseDarkColors; | ||
14 | |||
15 | constructor(...args) { | ||
16 | super(...args); | ||
17 | |||
18 | // Register action handlers | ||
19 | this.actions.ui.openSettings.listen(this._openSettings.bind(this)); | ||
20 | this.actions.ui.closeSettings.listen(this._closeSettings.bind(this)); | ||
21 | this.actions.ui.toggleServiceUpdatedInfoBar.listen( | ||
22 | this._toggleServiceUpdatedInfoBar.bind(this), | ||
23 | ); | ||
24 | |||
25 | // Listen for theme change on MacOS | ||
26 | if (isMac) { | ||
27 | systemPreferences.subscribeNotification( | ||
28 | 'AppleInterfaceThemeChangedNotification', | ||
29 | () => { | ||
30 | this.isOsDarkThemeActive = nativeTheme.shouldUseDarkColors; | ||
31 | this.actions.service.shareSettingsWithServiceProcess(); | ||
32 | }, | ||
33 | ); | ||
34 | } | ||
35 | |||
36 | if (isWindows) { | ||
37 | nativeTheme.on('updated', () => { | ||
38 | this.isOsDarkThemeActive = nativeTheme.shouldUseDarkColors; | ||
39 | this.actions.service.shareSettingsWithServiceProcess(); | ||
40 | }); | ||
41 | } | ||
42 | } | ||
43 | |||
44 | setup() { | ||
45 | reaction( | ||
46 | () => ( | ||
47 | this.isDarkThemeActive | ||
48 | ), | ||
49 | () => { | ||
50 | this._setupThemeInDOM(); | ||
51 | }, | ||
52 | { fireImmediately: true }, | ||
53 | ); | ||
54 | } | ||
55 | |||
56 | @computed get showMessageBadgesEvenWhenMuted() { | ||
57 | const settings = this.stores.settings.all; | ||
58 | |||
59 | return ( | ||
60 | (settings.app.isAppMuted && settings.app.showMessageBadgeWhenMuted) | ||
61 | || !settings.app.isAppMuted | ||
62 | ); | ||
63 | } | ||
64 | |||
65 | @computed get isDarkThemeActive() { | ||
66 | const isWithAdaptableInDarkMode = this.stores.settings.all.app.adaptableDarkMode | ||
67 | && this.isOsDarkThemeActive; | ||
68 | const isWithoutAdaptableInDarkMode = this.stores.settings.all.app.darkMode | ||
69 | && !this.stores.settings.all.app.adaptableDarkMode; | ||
70 | const isInDarkMode = this.stores.settings.all.app.darkMode; | ||
71 | return !!(isWithAdaptableInDarkMode | ||
72 | || isWithoutAdaptableInDarkMode | ||
73 | || isInDarkMode); | ||
74 | } | ||
75 | |||
76 | @computed get theme() { | ||
77 | const themeId = (this.isDarkThemeActive || this.stores.settings.app.darkMode) ? 'dark' : 'default'; | ||
78 | const { accentColor } = this.stores.settings.app; | ||
79 | return theme(themeId, accentColor); | ||
80 | } | ||
81 | |||
82 | // Actions | ||
83 | @action _openSettings({ path = '/settings' }) { | ||
84 | const settingsPath = path !== '/settings' ? `/settings/${path}` : path; | ||
85 | this.stores.router.push(settingsPath); | ||
86 | } | ||
87 | |||
88 | @action _closeSettings() { | ||
89 | this.stores.router.push('/'); | ||
90 | } | ||
91 | |||
92 | @action _toggleServiceUpdatedInfoBar({ visible }) { | ||
93 | let visibility = visible; | ||
94 | if (visibility === null) { | ||
95 | visibility = !this.showServicesUpdatedInfoBar; | ||
96 | } | ||
97 | this.showServicesUpdatedInfoBar = visibility; | ||
98 | } | ||
99 | |||
100 | // Reactions | ||
101 | _setupThemeInDOM() { | ||
102 | const body = document.querySelector('body'); | ||
103 | |||
104 | if (!this.isDarkThemeActive) { | ||
105 | body.classList.remove('theme__dark'); | ||
106 | } else { | ||
107 | body.classList.add('theme__dark'); | ||
108 | } | ||
109 | } | ||
110 | } | ||