/
DarkTheme.js
65 lines (56 loc) · 1.65 KB
/
DarkTheme.js
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
'use strict';
var css_dark = [
'./css/dark-theme.css',
];
var DarkTheme = {
configEnabled: undefined,
};
DarkTheme.isDarkThemeEnabled = function (callback) {
if (this.configEnabled === 0) {
callback(true);
} else if (this.configEnabled === 2) {
if (GUI.isCordova()) {
cordova.plugins.ThemeDetection.isDarkModeEnabled(function(success) {
callback(success.value);
}, function(error) {
console.log(`cordova-plugin-theme-detection: ${error}`);
callback(false);
});
} else {
const isEnabled = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
callback(isEnabled);
}
} else {
callback(false);
}
};
DarkTheme.apply = function() {
const self = this;
this.isDarkThemeEnabled(function(isEnabled) {
if (isEnabled) {
self.applyDark();
} else {
self.applyNormal();
}
if (chrome.app.window !== undefined) {
windowWatcherUtil.passValue(chrome.app.window.get("receiver_msp"), 'darkTheme', isEnabled);
}
});
};
DarkTheme.autoSet = function() {
if (this.configEnabled === 2) {
this.apply();
}
};
DarkTheme.setConfig = function (result) {
if (this.configEnabled !== result) {
this.configEnabled = result;
this.apply();
}
};
DarkTheme.applyDark = function () {
css_dark.forEach((el) => $('link[href="' + el + '"]').prop('disabled', false));
};
DarkTheme.applyNormal = function () {
css_dark.forEach((el) => $('link[href="' + el + '"]').prop('disabled', true));
};