2021-09-17 22:24:21 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
async function applyTheme() {
|
2021-10-07 23:28:47 +00:00
|
|
|
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'
|
2021-10-07 23:28:47 +00:00
|
|
|
? 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
|
2021-10-07 23:28:47 +00:00
|
|
|
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
|
|
|
|
2021-10-07 23:28:47 +00:00
|
|
|
window.SignalContext.nativeThemeListener.subscribe(() => {
|
2021-09-17 22:24:21 +00:00
|
|
|
applyTheme();
|
|
|
|
});
|