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:
parent
6912a1e3ca
commit
20effebd51
|
@ -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));
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue