signal-desktop/ts/windows/applyTheme.ts
2021-10-07 19:28:47 -04:00

33 lines
858 B
TypeScript

// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
async function applyTheme() {
const theme = await window.SignalContext.Settings.themeSetting.getValue();
document.body.classList.remove('light-theme');
document.body.classList.remove('dark-theme');
document.body.classList.add(
`${
theme === 'system'
? window.SignalContext.nativeThemeListener.getSystemTheme()
: theme
}-theme`
);
}
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();
// eslint-disable-next-line no-await-in-loop
await applyTheme();
}
}
applyTheme();
applyThemeLoop();
window.SignalContext.nativeThemeListener.subscribe(() => {
applyTheme();
});