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
1 changed files with 18 additions and 4 deletions

View File

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