Add "system" theme setting for MacOS
This commit is contained in:
parent
089a232a60
commit
fd36720079
13 changed files with 174 additions and 35 deletions
20
preload.js
20
preload.js
|
@ -7,6 +7,7 @@ const semver = require('semver');
|
|||
const { deferredToPromise } = require('./js/modules/deferred_to_promise');
|
||||
|
||||
const { app } = electron.remote;
|
||||
const { systemPreferences } = electron.remote.require('electron');
|
||||
|
||||
window.PROTO_ROOT = 'protos';
|
||||
const config = require('url').parse(window.location.toString(), true).query;
|
||||
|
@ -31,6 +32,25 @@ window.getHostName = () => config.hostname;
|
|||
window.getServerTrustRoot = () => config.serverTrustRoot;
|
||||
window.isBehindProxy = () => Boolean(config.proxyUrl);
|
||||
|
||||
function setSystemTheme() {
|
||||
window.systemTheme = systemPreferences.isDarkMode() ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
setSystemTheme();
|
||||
|
||||
window.subscribeToSystemThemeChange = fn => {
|
||||
if (!systemPreferences.subscribeNotification) {
|
||||
return;
|
||||
}
|
||||
systemPreferences.subscribeNotification(
|
||||
'AppleInterfaceThemeChangedNotification',
|
||||
() => {
|
||||
setSystemTheme();
|
||||
fn();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
window.isBeforeVersion = (toCheck, baseVersion) => {
|
||||
try {
|
||||
return semver.lt(toCheck, baseVersion);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue