-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathZenAppIcon.sys.mjs
More file actions
76 lines (65 loc) · 2.19 KB
/
Copy pathZenAppIcon.sys.mjs
File metadata and controls
76 lines (65 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
const ZEN_MACOS_APP_ICON_VARIANT_PREF = "zen.widget.macos.app-icon-variant";
const ZEN_MACOS_APP_ICON_RESOURCES = {
alternate: {
bundlePath: "zen-app-icons/alternate.bundle",
iconName: "AppIcon",
},
};
class nsZenAppIcon {
#initialized = false;
#hasAppliedAfterStartup = false;
#observingStartup = false;
init() {
if (this.#initialized || Services.appinfo.OS != "Darwin") {
return;
}
this.#initialized = true;
this.#hasAppliedAfterStartup = false;
Services.prefs.addObserver(ZEN_MACOS_APP_ICON_VARIANT_PREF, this);
Services.obs.addObserver(this, "browser-delayed-startup-finished");
this.#observingStartup = true;
void this.#applyMacOSAppIconVariant();
}
uninit() {
if (!this.#initialized) {
return;
}
this.#initialized = false;
Services.prefs.removeObserver(ZEN_MACOS_APP_ICON_VARIANT_PREF, this);
if (this.#observingStartup) {
Services.obs.removeObserver(this, "browser-delayed-startup-finished");
this.#observingStartup = false;
}
}
observe(_subject, topic, data) {
if (topic == "nsPref:changed" && data == ZEN_MACOS_APP_ICON_VARIANT_PREF) {
void this.#applyMacOSAppIconVariant();
return;
}
if (topic == "browser-delayed-startup-finished" && !this.#hasAppliedAfterStartup) {
this.#hasAppliedAfterStartup = true;
Services.obs.removeObserver(this, "browser-delayed-startup-finished");
this.#observingStartup = false;
void this.#applyMacOSAppIconVariant();
}
}
#applyMacOSAppIconVariant() {
const variant = Services.prefs.getStringPref(
ZEN_MACOS_APP_ICON_VARIANT_PREF,
"default"
);
const iconResource = ZEN_MACOS_APP_ICON_RESOURCES[variant];
try {
Services.zen.setMacOSAppIcon(
iconResource?.bundlePath ?? "",
iconResource?.iconName ?? ""
);
} catch (error) {
console.error("ZenAppIcon: failed to apply macOS app icon variant", error);
}
}
}
export const ZenAppIcon = new nsZenAppIcon();