Skip to content

Commit 83707a4

Browse files
committed
fix: theme to take effect on change to penpot
1 parent 7fd510f commit 83707a4

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/base/scripts/electron-tabs.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,7 @@ function tabReadyHandler(tab) {
8686
const webview = /** @type {WebviewTag} */ (tab.webview);
8787

8888
tab.once("webview-dom-ready", () => {
89-
tab.on("active", () => {
90-
webview.send(THEME_TAB_EVENTS.REQUEST_UPDATE);
91-
});
89+
tab.on("active", () => requestTabTheme(tab));
9290
});
9391
tab.element.addEventListener("contextmenu", (event) => {
9492
event.preventDefault();
@@ -108,6 +106,26 @@ function tabReadyHandler(tab) {
108106
});
109107
}
110108

109+
/**
110+
* Calls a tab and requests a theme update send-out.
111+
* If no tab is provided, calls the active tab.
112+
*
113+
* @param {Tab =} tab
114+
*/
115+
async function requestTabTheme(tab) {
116+
tab = tab || (await getActiveTab());
117+
118+
if (tab) {
119+
const webview = /** @type {WebviewTag} */ (tab.webview);
120+
webview?.send(THEME_TAB_EVENTS.REQUEST_UPDATE);
121+
}
122+
}
123+
124+
async function getActiveTab() {
125+
const tabGroup = await getTabGroup();
126+
return tabGroup?.getActiveTab();
127+
}
128+
111129
async function getTabGroup() {
112130
return /** @type {TabGroup | null} */ (
113131
await getIncludedElement("tab-group", "#include-tabs")

src/base/scripts/theme.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,16 @@ async function prepareForm(themeSetting) {
4040
const value = target instanceof HTMLSelectElement && target.value;
4141

4242
if (isThemeSetting(value)) {
43-
currentThemeSetting = value;
43+
const isTabTheme = value === "tab";
4444

45+
currentThemeSetting = value;
4546
localStorage.setItem(THEME_STORE_KEY, value);
47+
48+
if (isTabTheme) {
49+
requestTabTheme();
50+
return;
51+
}
52+
4653
setTheme(value);
4754
} else {
4855
currentThemeSetting = null;

0 commit comments

Comments
 (0)