blob: 6941cf0864f2b9e7b5fe3d7115cd0cadfb06eb7c (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
import {
action, observable, computed, reaction,
} from 'mobx';
import { theme } from '@meetfranz/theme';
import { remote } from 'electron';
import Store from './lib/Store';
import { isMac } from '../environment';
const { nativeTheme, systemPreferences } = remote;
export default class UIStore extends Store {
@observable showServicesUpdatedInfoBar = false;
@observable isOsDarkThemeActive = isMac
? nativeTheme.shouldUseDarkColors
: false;
constructor(...args) {
super(...args);
// Register action handlers
this.actions.ui.openSettings.listen(this._openSettings.bind(this));
this.actions.ui.closeSettings.listen(this._closeSettings.bind(this));
this.actions.ui.toggleServiceUpdatedInfoBar.listen(
this._toggleServiceUpdatedInfoBar.bind(this),
);
// Listen for theme change on MacOS
if (isMac) {
systemPreferences.subscribeNotification(
'AppleInterfaceThemeChangedNotification',
() => {
this.isOsDarkThemeActive = nativeTheme.shouldUseDarkColors;
this.actions.service.shareSettingsWithServiceProcess();
},
);
}
}
setup() {
reaction(
() => this.isDarkThemeActive,
() => this._setupThemeInDOM(),
{ fireImmediately: true },
);
}
@computed get showMessageBadgesEvenWhenMuted() {
const settings = this.stores.settings.all;
return (
(settings.app.isAppMuted && settings.app.showMessageBadgeWhenMuted)
|| !settings.app.isAppMuted
);
}
@computed get isDarkThemeActive() {
const isMacWithAdaptableInDarkMode = isMac
&& this.stores.settings.all.app.adaptableDarkMode
&& this.isOsDarkThemeActive;
const isMacWithoutAdaptableInDarkMode = isMac
&& this.stores.settings.all.app.darkMode
&& !this.stores.settings.all.app.adaptableDarkMode;
const isNotMacInDarkMode = !isMac && this.stores.settings.all.app.darkMode;
return !!(isMacWithAdaptableInDarkMode
|| isMacWithoutAdaptableInDarkMode
|| isNotMacInDarkMode);
}
@computed get theme() {
if (this.isDarkThemeActive || this.stores.settings.app.darkMode) return theme('dark');
return theme('default');
}
// Actions
@action _openSettings({ path = '/settings' }) {
const settingsPath = path !== '/settings' ? `/settings/${path}` : path;
this.stores.router.push(settingsPath);
}
@action _closeSettings() {
this.stores.router.push('/');
}
@action _toggleServiceUpdatedInfoBar({ visible }) {
let visibility = visible;
if (visibility === null) {
visibility = !this.showServicesUpdatedInfoBar;
}
this.showServicesUpdatedInfoBar = visibility;
}
// Reactions
_setupThemeInDOM() {
const body = document.querySelector('body');
if (!this.isDarkThemeActive) {
body.classList.remove('theme__dark');
} else {
body.classList.add('theme__dark');
}
}
}
|