From 49272212bcfb134cd347dd449fc15fd87e76ada7 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Fri, 27 Jan 2023 17:07:44 +0500 Subject: [PATCH] desktop: don't emit event when user changes theme --- apps/web/desktop/config/theme.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/web/desktop/config/theme.js b/apps/web/desktop/config/theme.js index 8251d537d..12de6c881 100644 --- a/apps/web/desktop/config/theme.js +++ b/apps/web/desktop/config/theme.js @@ -25,7 +25,7 @@ function getTheme() { } function setTheme(theme) { - nativeTheme.themeSource = theme; + changeTheme(theme); if (globalThis.window) globalThis.window.setBackgroundColor(getBackgroundColor(theme)); return JSONStorage.set("theme", theme); @@ -35,4 +35,15 @@ function getBackgroundColor() { return nativeTheme.shouldUseDarkColors ? "#0f0f0f" : "#ffffff"; } -export { getTheme, setTheme, getBackgroundColor }; + +function changeTheme(theme) { + const listeners = nativeTheme.rawListeners("updated"); + nativeTheme.removeAllListeners("updated"); + + nativeTheme.themeSource = theme; + + setTimeout( + () => listeners.forEach((a) => nativeTheme.addListener("updated", a)), + 1000 + ); +}