diff options
Diffstat (limited to 'apps/theming/src/helpers/refreshStyles.js')
-rw-r--r-- | apps/theming/src/helpers/refreshStyles.js | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/apps/theming/src/helpers/refreshStyles.js b/apps/theming/src/helpers/refreshStyles.js new file mode 100644 index 00000000000..ba198be0a00 --- /dev/null +++ b/apps/theming/src/helpers/refreshStyles.js @@ -0,0 +1,26 @@ +/** + * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +/** + * Refresh server-side generated theming CSS + * This resolves when all themes are reloaded + */ +export async function refreshStyles() { + const themes = [...document.head.querySelectorAll('link.theme')] + const promises = themes.map((theme) => new Promise((resolve) => { + const url = new URL(theme.href) + url.searchParams.set('v', Date.now()) + const newTheme = theme.cloneNode() + newTheme.href = url.toString() + newTheme.onload = () => { + theme.remove() + resolve() + } + document.head.append(newTheme) + })) + + // Wait until all themes are loaded + await Promise.allSettled(promises) +} |