DEV: Fix updating header background in webview (#29668)

This regressed in https://github.com/discourse/discourse/pull/28912 for media query changes.
This commit is contained in:
Penar Musaraj 2024-11-08 22:18:09 -05:00 committed by GitHub
parent 6912a1e3ca
commit 20effebd51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -5,13 +5,19 @@ import discourseLater from "discourse-common/lib/later";
export default { export default {
after: "inject-objects", after: "inject-objects",
retryCount: 0, retryCount: 0,
isAppWebview: undefined,
mediaQuery: "(prefers-color-scheme: dark)",
initialize(owner) { initialize(owner) {
const caps = owner.lookup("service:capabilities"); if (this.isAppWebview === undefined) {
if (caps.isAppWebview) { const caps = owner.lookup("service:capabilities");
this.isAppWebview = caps.isAppWebview;
}
if (this.isAppWebview) {
window window
.matchMedia("(prefers-color-scheme: dark)") .matchMedia(this.mediaQuery)
.addEventListener("change", this.updateAppBackground); .addEventListener("change", this.updateAppBackground.bind(this));
this.updateAppBackground(); this.updateAppBackground();
} }
}, },
@ -39,4 +45,12 @@ export default {
this.updateAppBackground(1000); this.updateAppBackground(1000);
} }
}, },
teardown() {
if (this.isAppWebview) {
window
.matchMedia(this.mediaQuery)
.removeEventListener("change", this.updateAppBackground.bind(this));
}
},
}; };