Skip to content

Commit 05d9bb0

Browse files
committed
no-bug: Make macOS app icon changes available from settings
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
1 parent 18c15ac commit 05d9bb0

17 files changed

Lines changed: 262 additions & 5 deletions

File tree

locales/en-US/browser/browser/preferences/zen-preferences.ftl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ zen-look-and-feel-compact-view-top-toolbar =
4848
zen-look-and-feel-compact-toolbar-flash-popup =
4949
.label = Briefly make the toolbar popup when switching or opening new tabs in compact mode
5050
51+
zen-look-and-feel-app-icon-header = App Icon
52+
zen-look-and-feel-app-icon-description = Change the icon used by the running app on macOS
53+
zen-look-and-feel-app-icon-label = Variant
54+
zen-look-and-feel-app-icon-default =
55+
.label = Default
56+
zen-look-and-feel-app-icon-alternate =
57+
.label = Alternative
58+
5159
pane-zen-tabs-title = Tab Management
5260
category-zen-workspaces =
5361
.tooltiptext = { pane-zen-tabs-title }
@@ -357,4 +365,4 @@ zen-devtools-toggle-dom-shortcut = Toggle DOM
357365
zen-devtools-toggle-accessibility-shortcut = Toggle Accessibility
358366
zen-close-all-unpinned-tabs-shortcut = Close All Unpinned Tabs
359367
zen-new-unsynced-window-shortcut = New Blank Window
360-
zen-duplicate-tab-shortcut = Duplicate Tab
368+
zen-duplicate-tab-shortcut = Duplicate Tab

src/browser/components/preferences/zen-settings.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,11 @@ var gZenMarketplaceManager = {
644644

645645
const kZenExtendedSidebar = "zen.view.sidebar-expanded";
646646
const kZenSingleToolbar = "zen.view.use-single-toolbar";
647+
const kZenMacOSAppIconVariant = "zen.widget.macos.app-icon-variant";
648+
const kZenMacOSAppIconPreviewSrcByVariant = {
649+
default: "chrome://branding/content/icon48.png",
650+
alternate: "chrome://browser/content/zen-images/app-icons/alternate-preview.png",
651+
};
647652

648653
var gZenLooksAndFeel = {
649654
init() {
@@ -652,18 +657,24 @@ var gZenLooksAndFeel = {
652657
}
653658
this.__hasInitialized = true;
654659
gZenMarketplaceManager.init();
655-
for (const pref of [kZenExtendedSidebar, kZenSingleToolbar]) {
660+
for (const pref of [kZenExtendedSidebar, kZenSingleToolbar, kZenMacOSAppIconVariant]) {
656661
Services.prefs.addObserver(pref, this);
657662
}
658663
window.addEventListener("unload", () => {
659-
for (const pref of [kZenExtendedSidebar, kZenSingleToolbar]) {
664+
for (const pref of [kZenExtendedSidebar, kZenSingleToolbar, kZenMacOSAppIconVariant]) {
660665
Services.prefs.removeObserver(pref, this);
661666
}
662667
});
663668
this.applySidebarLayout();
669+
this.applyMacOSAppIconPreview();
664670
},
665671

666-
observe() {
672+
observe(_subject, _topic, data) {
673+
if (data == kZenMacOSAppIconVariant) {
674+
this.applyMacOSAppIconPreview();
675+
return;
676+
}
677+
667678
this.applySidebarLayout();
668679
},
669680

@@ -708,6 +719,19 @@ var gZenLooksAndFeel = {
708719
});
709720
}
710721
},
722+
723+
applyMacOSAppIconPreview() {
724+
const preview = document.getElementById("zenLooksAndFeelMacOSAppIconPreview");
725+
if (!preview) {
726+
return;
727+
}
728+
729+
const variant = Services.prefs.getStringPref(kZenMacOSAppIconVariant, "default");
730+
const variantPreviewSrc = kZenMacOSAppIconPreviewSrcByVariant[variant];
731+
const defaultPreviewSrc = kZenMacOSAppIconPreviewSrcByVariant.default;
732+
const previewSrc = variantPreviewSrc ?? defaultPreviewSrc;
733+
preview.setAttribute("src", previewSrc);
734+
},
711735
};
712736

713737
var gZenWorkspacesSettings = {
@@ -1135,6 +1159,11 @@ Preferences.addAll([
11351159
type: "bool",
11361160
default: true,
11371161
},
1162+
{
1163+
id: "zen.widget.macos.app-icon-variant",
1164+
type: "string",
1165+
default: "default",
1166+
},
11381167
{
11391168
id: "zen.workspaces.hide-default-container-indicator",
11401169
type: "bool",

src/browser/components/preferences/zenLooksAndFeel.inc.xhtml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,31 @@
6161
data-l10n-id="zen-look-and-feel-compact-toolbar-flash-popup"
6262
preference="zen.view.compact.toolbar-flash-popup"/>
6363
</vbox>
64+
65+
#ifdef XP_MACOSX
66+
<label><html:h2 data-l10n-id="zen-look-and-feel-app-icon-header"/></label>
67+
<description class="description-deemphasized" data-l10n-id="zen-look-and-feel-app-icon-description" />
68+
69+
<hbox id="zenMacOSAppIconSetting" align="center">
70+
<html:div class="zenAppIconPreviewFrame">
71+
<html:img id="zenLooksAndFeelMacOSAppIconPreview"
72+
src="chrome://branding/content/icon48.png" />
73+
</html:div>
74+
75+
<vbox flex="1">
76+
<label data-l10n-id="zen-look-and-feel-app-icon-label"/>
77+
<menulist id="zenLooksAndFeelMacOSAppIconVariant"
78+
preference="zen.widget.macos.app-icon-variant">
79+
<menupopup>
80+
<menuitem data-l10n-id="zen-look-and-feel-app-icon-default"
81+
value="default"/>
82+
<menuitem data-l10n-id="zen-look-and-feel-app-icon-alternate"
83+
value="alternate"/>
84+
</menupopup>
85+
</menulist>
86+
</vbox>
87+
</hbox>
88+
#endif
6489
</groupbox>
6590

6691
<hbox id="zenGlanceCategory"

src/browser/themes/shared/preferences/zen-preferences.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,30 @@ groupbox h2 {
9797
margin-top: 15px;
9898
}
9999

100+
#zenMacOSAppIconSetting {
101+
gap: 16px;
102+
margin-block: 10px 14px;
103+
104+
& .zenAppIconPreviewFrame {
105+
display: flex;
106+
align-items: center;
107+
justify-content: center;
108+
width: 80px;
109+
min-width: 80px;
110+
height: 80px;
111+
border: 1px solid var(--zen-colors-border);
112+
border-radius: 18px;
113+
background: color-mix(in srgb, var(--zen-colors-tertiary) 70%, transparent);
114+
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
115+
}
116+
117+
& #zenLooksAndFeelMacOSAppIconPreview {
118+
width: 64px;
119+
height: 64px;
120+
border-radius: 18px;
121+
}
122+
}
123+
100124
.zen-compact-mode-styles-browser-wrapper {
101125
width: 55%;
102126
height: 60px;

src/zen/@types/lib.gecko.xpcom.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19519,6 +19519,7 @@ declare global {
1951919519
): void;
1952019520
canShare(): boolean;
1952119521
playHapticFeedback(): void;
19522+
setMacOSAppIcon(iconBundlePath: string, iconName: string): void;
1952219523
}
1952319524

1952419525
// https://searchfox.org/mozilla-central/source/zen/drag-and-drop/nsIZenDragAndDrop.idl

src/zen/common/Components.manifest

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44

55
category browser-before-ui-startup resource:///modules/ZenActorsManager.sys.mjs gZenActorsManager.init
6+
category browser-before-ui-startup resource:///modules/ZenAppIcon.sys.mjs ZenAppIcon.init
7+
category browser-quit-application-granted resource:///modules/ZenAppIcon.sys.mjs ZenAppIcon.uninit

src/zen/common/moz.build

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
EXTRA_JS_MODULES += [
66
"sys/ZenActorsManager.sys.mjs",
7+
"sys/ZenAppIcon.sys.mjs",
78
"sys/ZenCustomizableUI.sys.mjs",
89
"sys/ZenUIMigration.sys.mjs",
910
]
@@ -12,3 +13,11 @@ EXTRA_JS_MODULES.zen.ui += [
1213
"sys/ui/ZenProgressBar.sys.mjs",
1314
"sys/ui/ZenUIComponent.sys.mjs",
1415
]
16+
17+
FINAL_TARGET_FILES["zen-app-icons"]["alternate.bundle"]["Contents"] += [
18+
"../images/app-icons/alternate.bundle/Contents/Info.plist",
19+
]
20+
21+
FINAL_TARGET_FILES["zen-app-icons"]["alternate.bundle"]["Contents"]["Resources"] += [
22+
"../images/app-icons/alternate.bundle/Contents/Resources/Assets.car",
23+
]
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
const ZEN_MACOS_APP_ICON_VARIANT_PREF = "zen.widget.macos.app-icon-variant";
6+
const ZEN_MACOS_APP_ICON_RESOURCES = {
7+
alternate: {
8+
bundlePath: "browser/zen-app-icons/alternate.bundle",
9+
iconName: "AppIcon",
10+
},
11+
};
12+
13+
class nsZenAppIcon {
14+
#initialized = false;
15+
16+
init() {
17+
if (this.#initialized || Services.appinfo.OS != "Darwin") {
18+
return;
19+
}
20+
21+
this.#initialized = true;
22+
Services.prefs.addObserver(ZEN_MACOS_APP_ICON_VARIANT_PREF, this);
23+
void this.#applyMacOSAppIconVariant();
24+
}
25+
26+
uninit() {
27+
if (!this.#initialized) {
28+
return;
29+
}
30+
31+
this.#initialized = false;
32+
Services.prefs.removeObserver(ZEN_MACOS_APP_ICON_VARIANT_PREF, this);
33+
}
34+
35+
observe(_subject, topic, data) {
36+
if (topic == "nsPref:changed" && data == ZEN_MACOS_APP_ICON_VARIANT_PREF) {
37+
void this.#applyMacOSAppIconVariant();
38+
}
39+
}
40+
41+
#applyMacOSAppIconVariant() {
42+
const variant = Services.prefs.getStringPref(
43+
ZEN_MACOS_APP_ICON_VARIANT_PREF,
44+
"default"
45+
);
46+
const iconResource = ZEN_MACOS_APP_ICON_RESOURCES[variant];
47+
48+
Services.zen.setMacOSAppIcon(
49+
iconResource?.bundlePath ?? "",
50+
iconResource?.iconName ?? ""
51+
);
52+
}
53+
}
54+
55+
export const ZenAppIcon = new nsZenAppIcon();
48.3 KB
Loading
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleIdentifier</key>
6+
<string>app.zen-browser.icons.alternate</string>
7+
<key>CFBundlePackageType</key>
8+
<string>BNDL</string>
9+
</dict>
10+
</plist>

0 commit comments

Comments
 (0)