Signal-Desktop/ts/windows/applyTheme.ts

34 lines
858 B
TypeScript
Raw Normal View History

2021-09-17 22:24:21 +00:00
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
async function applyTheme() {
const theme = await window.SignalContext.Settings.themeSetting.getValue();
2021-09-17 22:24:21 +00:00
document.body.classList.remove('light-theme');
document.body.classList.remove('dark-theme');
document.body.classList.add(
`${
theme === 'system'
? window.SignalContext.nativeThemeListener.getSystemTheme()
2021-09-17 22:24:21 +00:00
: theme
}-theme`
);
}
2021-09-29 18:37:30 +00:00
async function applyThemeLoop() {
// eslint-disable-next-line no-constant-condition
while (true) {
// eslint-disable-next-line no-await-in-loop
await window.SignalContext.Settings.waitForChange();
2021-09-29 18:37:30 +00:00
// eslint-disable-next-line no-await-in-loop
await applyTheme();
}
}
2021-09-17 22:24:21 +00:00
applyTheme();
2021-09-29 18:37:30 +00:00
applyThemeLoop();
2021-09-17 22:24:21 +00:00
window.SignalContext.nativeThemeListener.subscribe(() => {
2021-09-17 22:24:21 +00:00
applyTheme();
});