Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/desktop/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ sp-identity = { path = "../../crates/sp-identity", optional = true }
[target.'cfg(target_os = "macos")'.dependencies]
objc2 = "0.6"
block2 = "0.6"
objc2-foundation = { version = "0.3", features = ["NSString", "NSArray", "NSSet", "NSError", "NSNotification", "NSOperation", "NSDictionary", "NSObject", "NSValue", "NSUserDefaults", "NSDate", "NSBundle"] }
objc2-app-kit = { version = "0.3", features = ["NSApplication", "NSWorkspace", "NSRunningApplication", "NSResponder", "NSDockTile", "NSStatusItem", "NSStatusBarButton", "NSButton", "NSControl", "NSView", "NSCell", "NSButtonCell"] }
objc2-foundation = { version = "0.3", features = ["NSString", "NSArray", "NSSet", "NSError", "NSNotification", "NSOperation", "NSDictionary", "NSObject", "NSValue", "NSUserDefaults", "NSDate", "NSBundle", "NSData"] }
objc2-app-kit = { version = "0.3", features = ["NSApplication", "NSWorkspace", "NSRunningApplication", "NSResponder", "NSDockTile", "NSImage", "NSStatusItem", "NSStatusBarButton", "NSButton", "NSControl", "NSView", "NSCell", "NSButtonCell"] }
objc2-user-notifications = { version = "0.3", features = ["UNUserNotificationCenter", "UNNotification", "UNNotificationRequest", "UNNotificationContent", "UNNotificationAction", "UNNotificationCategory", "UNNotificationResponse", "UNNotificationSettings", "UNNotificationSound", "UNNotificationTrigger", "block2"] }
objc2-service-management = { version = "0.3", features = ["SMAppService"] }

Expand Down
Binary file added apps/desktop/src-tauri/icons/icon-silver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions apps/desktop/src-tauri/icons/src/app-icon-silver.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions apps/desktop/src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ pub fn apply_settings<R: Runtime>(
tauri::ActivationPolicy::Regular
});
}
if next.app_icon != prev.app_icon || (!next.menu_bar_only && prev.menu_bar_only) {
crate::window::apply_icon(app, next.app_icon);
}
{
// The shell's own fields are read again under the lock that writes: the launch's
// service check may have noted a version since `prev` was read.
Expand Down
3 changes: 3 additions & 0 deletions apps/desktop/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ pub fn run() {
if s.menu_bar_only {
app.set_activation_policy(tauri::ActivationPolicy::Accessory);
}
if s.app_icon != settings::AppIcon::Default {
window::apply_icon(app.handle(), s.app_icon);
}
menu::install(app.handle())?;
if s.menu_bar {
tray::install(app.handle())?;
Expand Down
31 changes: 31 additions & 0 deletions apps/desktop/src-tauri/src/macos/icon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//! The Dock and app-switcher icon through `NSApplication.setApplicationIconImage`.
//! Main thread only.

use crate::settings::AppIcon;
use objc2::AllocAnyThread;
use objc2_app_kit::{NSApplication, NSImage};
use objc2_foundation::NSData;

pub const SILVER_PNG: &[u8] = include_bytes!("../../icons/icon-silver.png");

pub fn set(icon: AppIcon) {
let Some(mtm) = objc2::MainThreadMarker::new() else {
log::warn!("app icon: not on the main thread");
return;
};
let ns = NSApplication::sharedApplication(mtm);
match icon {
AppIcon::Default => {
unsafe { ns.setApplicationIconImage(None) };
}
AppIcon::Silver => {
let data = NSData::with_bytes(SILVER_PNG);
if let Some(img) = NSImage::initWithData(NSImage::alloc(), &data) {
unsafe { ns.setApplicationIconImage(Some(&img)) };
} else {
log::warn!("app icon: could not decode silver PNG");
}
}
}
ns.dockTile().display();
}
1 change: 1 addition & 0 deletions apps/desktop/src-tauri/src/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! login item (SMAppService), the Dock badge with no window, small system reads.

pub mod badge;
pub mod icon;
pub mod login_item;
pub mod notify;

Expand Down
14 changes: 14 additions & 0 deletions apps/desktop/src-tauri/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ pub struct NotifySettings {
pub paused_until: Option<String>,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum AppIcon {
#[default]
Default,
Silver,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase", default)]
pub struct AppSettings {
Expand All @@ -41,6 +49,8 @@ pub struct AppSettings {
pub dock_badge: bool,
pub keep_running: bool,
pub menu_bar_only: bool,
/// Dock / taskbar app icon finish ("default" dark tile or "silver" machined chassis).
pub app_icon: AppIcon,
/// An accelerator such as "Control+Alt+N", or None (off, the default).
pub hotkey: Option<String>,
pub notifications: NotifySettings,
Expand All @@ -63,6 +73,7 @@ impl Default for AppSettings {
dock_badge: true,
keep_running: true,
menu_bar_only: false,
app_icon: AppIcon::Default,
hotkey: None,
notifications: NotifySettings::default(),
first_run_done: false,
Expand Down Expand Up @@ -126,6 +137,7 @@ mod tests {
let mut s = AppSettings {
hotkey: Some("Control+Alt+N".into()),
keep_running: false,
app_icon: AppIcon::Silver,
..Default::default()
};
s.notifications.enabled = true;
Expand All @@ -142,13 +154,15 @@ mod tests {
"dockBadge",
"keepRunning",
"menuBarOnly",
"appIcon",
"hotkey",
"notifications",
"autoUpdate",
"lastVersion",
] {
assert!(v.get(k).is_some(), "{k}");
}
assert_eq!(v["appIcon"], "silver");
assert_eq!(
v["notifications"]["pausedUntil"],
"2026-10-25T10:00:00.000Z"
Expand Down
34 changes: 33 additions & 1 deletion apps/desktop/src-tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn rx_base(id: &str) -> String {
}

pub fn features() -> Vec<&'static str> {
let mut f = vec!["tray", "hotkey", "deeplink", "updater"];
let mut f = vec!["tray", "hotkey", "deeplink", "updater", "appIcon"];
if cfg!(target_os = "macos") {
f.push("autostart");
// Only macOS has a notifier (macos/notify.rs). Elsewhere app_notify_* answer
Expand All @@ -79,6 +79,30 @@ pub fn features() -> Vec<&'static str> {
f
}

/// Applies the chosen app icon to the Dock / app switcher (macOS) or open windows (Windows/Linux).
pub fn apply_icon<R: Runtime>(app: &AppHandle<R>, icon: crate::settings::AppIcon) {
#[cfg(target_os = "macos")]
{
if objc2::MainThreadMarker::new().is_some() {
crate::macos::icon::set(icon);
} else {
let _ = app.run_on_main_thread(move || crate::macos::icon::set(icon));
}
}
#[cfg(not(target_os = "macos"))]
{
let bytes: &[u8] = match icon {
crate::settings::AppIcon::Default => include_bytes!("../icons/icon.png"),
crate::settings::AppIcon::Silver => include_bytes!("../icons/icon-silver.png"),
};
if let Ok(img) = tauri::image::Image::from_bytes(bytes) {
for w in app.webview_windows().values() {
let _ = w.set_icon(img.clone());
}
}
}
}

/// Sidebar vibrancy ships only if measured cheap (§3.1); until then it is opt-in for the
/// measurement: SP_VIBRANCY=1.
pub fn vibrancy() -> bool {
Expand Down Expand Up @@ -259,6 +283,13 @@ fn build_main<R: Runtime>(app: &AppHandle<R>, initial_path: Option<&str>) -> tau
builder
};
let w = builder.build()?;
#[cfg(not(target_os = "macos"))]
if handle.state::<Shell>().settings().app_icon == crate::settings::AppIcon::Silver {
if let Ok(img) = tauri::image::Image::from_bytes(include_bytes!("../icons/icon-silver.png"))
{
let _ = w.set_icon(img);
}
}
// Size and place come back through the window-state plugin's own hook (calling
// restore_state here as well deadlocked against that hook on a reopen).
let shell = handle.state::<Shell>();
Expand Down Expand Up @@ -362,6 +393,7 @@ mod tests {
cfg!(target_os = "macos")
);
assert!(features().contains(&"tray"));
assert!(features().contains(&"appIcon"));
}

#[test]
Expand Down
29 changes: 27 additions & 2 deletions test/e2e/native-shell.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface FakeOptions {
/** The shell's platform; "macos" unless a test plays another computer. */
platform?: string;
/** What the app's settings.json holds, over the defaults. */
settings?: Record<string, boolean>;
settings?: Record<string, boolean | string>;
/** Where the app's update is (app_update_status): checked a moment ago and up to date
* unless said. */
update?: UpdateOut;
Expand Down Expand Up @@ -104,7 +104,7 @@ function fakeShell() {
v: 1,
platform,
appVersion: "0.3.0",
features: features ?? ["tray", "notifications", "hotkey", "autostart", "deeplink", "updater"],
features: features ?? ["tray", "notifications", "hotkey", "autostart", "deeplink", "updater", "appIcon"],
receiver: receiver ? { id: "e2erx00001", name: "This Mac", origin: location.origin, local: true } : null,
rxBase: receiver ? "" : null,
};
Expand All @@ -122,6 +122,7 @@ function fakeShell() {
dockBadge: true,
keepRunning: true,
menuBarOnly: false,
appIcon: "default",
hotkey: null as string | null,
notifications: { enabled: !!notify.enabled, kinds: {}, pausedUntil: notify.pausedUntil ?? null },
firstRunDone,
Expand Down Expand Up @@ -1927,6 +1928,30 @@ test("in the phone app a board that can't reach its computer names it, with Retr
expect(scripts.filter((s) => /StartHere/.test(s))).toEqual([]);
});

test("Settings › General › App icon switches between Dark and Machined Silver and updates About", async ({ page }) => {
await openInShell(page, "/?settings=general", { receiver: true, firstRunDone: true });
const dlg = page.getByRole("dialog", { name: "Settings" });
await expect(dlg).toBeVisible({ timeout: 15_000 });
const darkTile = dlg.locator("label[data-app-icon='default']");
const silverTile = dlg.locator("label[data-app-icon='silver']");
await expect(darkTile).toHaveClass(/tile--on/);
await expect(silverTile).toBeVisible();

await silverTile.click();
await expect(silverTile).toHaveClass(/tile--on/);
await expect.poll(async () => (await settingsSent(page))?.appIcon).toBe("silver");

// Settings › About reflects the Machined Silver icon too
await dlg.getByRole("tab", { name: "About" }).click();
await expect(dlg.locator(".about-icon svg linearGradient").first()).toBeAttached();

// Switch back to Dark
await dlg.getByRole("tab", { name: "General" }).click();
await darkTile.click();
await expect(darkTile).toHaveClass(/tile--on/);
await expect.poll(async () => (await settingsSent(page))?.appIcon).toBe("default");
});

test("in a browser nothing native loads", async ({ page }) => {
const scripts: string[] = [];
page.on("request", (r) => {
Expand Down
Loading
Loading