diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml index 9f7f3444..28bbfb23 100644 --- a/apps/desktop/src-tauri/Cargo.toml +++ b/apps/desktop/src-tauri/Cargo.toml @@ -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"] } diff --git a/apps/desktop/src-tauri/icons/icon-silver.png b/apps/desktop/src-tauri/icons/icon-silver.png new file mode 100644 index 00000000..966e9e72 Binary files /dev/null and b/apps/desktop/src-tauri/icons/icon-silver.png differ diff --git a/apps/desktop/src-tauri/icons/src/app-icon-silver.svg b/apps/desktop/src-tauri/icons/src/app-icon-silver.svg new file mode 100644 index 00000000..0b0b1ccc --- /dev/null +++ b/apps/desktop/src-tauri/icons/src/app-icon-silver.svg @@ -0,0 +1,81 @@ + + sessionpipe — Machined Silver Chassis + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/apps/desktop/src-tauri/src/commands.rs b/apps/desktop/src-tauri/src/commands.rs index 2b585bd6..ee944157 100644 --- a/apps/desktop/src-tauri/src/commands.rs +++ b/apps/desktop/src-tauri/src/commands.rs @@ -290,6 +290,9 @@ pub fn apply_settings( 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. diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs index 89eefe6f..f21ebcaf 100644 --- a/apps/desktop/src-tauri/src/lib.rs +++ b/apps/desktop/src-tauri/src/lib.rs @@ -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())?; diff --git a/apps/desktop/src-tauri/src/macos/icon.rs b/apps/desktop/src-tauri/src/macos/icon.rs new file mode 100644 index 00000000..acc368ae --- /dev/null +++ b/apps/desktop/src-tauri/src/macos/icon.rs @@ -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(); +} diff --git a/apps/desktop/src-tauri/src/macos/mod.rs b/apps/desktop/src-tauri/src/macos/mod.rs index 05e885b9..8808143b 100644 --- a/apps/desktop/src-tauri/src/macos/mod.rs +++ b/apps/desktop/src-tauri/src/macos/mod.rs @@ -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; diff --git a/apps/desktop/src-tauri/src/settings.rs b/apps/desktop/src-tauri/src/settings.rs index f9fb138f..d0f773fb 100644 --- a/apps/desktop/src-tauri/src/settings.rs +++ b/apps/desktop/src-tauri/src/settings.rs @@ -33,6 +33,14 @@ pub struct NotifySettings { pub paused_until: Option, } +#[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 { @@ -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, pub notifications: NotifySettings, @@ -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, @@ -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; @@ -142,6 +154,7 @@ mod tests { "dockBadge", "keepRunning", "menuBarOnly", + "appIcon", "hotkey", "notifications", "autoUpdate", @@ -149,6 +162,7 @@ mod tests { ] { assert!(v.get(k).is_some(), "{k}"); } + assert_eq!(v["appIcon"], "silver"); assert_eq!( v["notifications"]["pausedUntil"], "2026-10-25T10:00:00.000Z" diff --git a/apps/desktop/src-tauri/src/window.rs b/apps/desktop/src-tauri/src/window.rs index 964dd0e1..bf48127f 100644 --- a/apps/desktop/src-tauri/src/window.rs +++ b/apps/desktop/src-tauri/src/window.rs @@ -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 @@ -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(app: &AppHandle, 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 { @@ -259,6 +283,13 @@ fn build_main(app: &AppHandle, initial_path: Option<&str>) -> tau builder }; let w = builder.build()?; + #[cfg(not(target_os = "macos"))] + if handle.state::().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::(); @@ -362,6 +393,7 @@ mod tests { cfg!(target_os = "macos") ); assert!(features().contains(&"tray")); + assert!(features().contains(&"appIcon")); } #[test] diff --git a/test/e2e/native-shell.spec.ts b/test/e2e/native-shell.spec.ts index f7e85a9e..5bedc81a 100644 --- a/test/e2e/native-shell.spec.ts +++ b/test/e2e/native-shell.spec.ts @@ -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; + settings?: Record; /** Where the app's update is (app_update_status): checked a moment ago and up to date * unless said. */ update?: UpdateOut; @@ -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, }; @@ -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, @@ -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) => { diff --git a/web/src/components/AppIcon.tsx b/web/src/components/AppIcon.tsx index c0054fe2..0e7318e7 100644 --- a/web/src/components/AppIcon.tsx +++ b/web/src/components/AppIcon.tsx @@ -1,10 +1,92 @@ // SPDX-License-Identifier: Apache-2.0 -// The app icon as Settings › About shows it: the mark on its ink tile, as the favicon and -// the installed app draw it (web/public/brand/favicon.svg), the same in both schemes, with -// a hairline edge on a dark ground so it does not sink (--brand-edge). Its own module, so -// only the lazy Settings chunk carries it. +// The app icon as Settings › About and the App icon picker show it: the mark on its ink +// tile ("default", matching web/public/brand/favicon.svg) or on the two-piece CNC +// machined silver chassis ("silver", matching apps/desktop/src-tauri/icons/src/app-icon-silver.svg). +// Its own module, so only the lazy Settings chunk carries it. +import { useId } from "react"; -export function AppIcon({ size = 64 }: { size?: number }) { +export type AppIconVariant = "default" | "silver"; + +export function AppIcon({ size = 64, variant = "default" }: { size?: number; variant?: AppIconVariant }) { + const id = useId(); + if (variant === "silver") { + const outer = `${id}-outer`; + const inner = `${id}-inner`; + const radial = `${id}-radial`; + const groove = `${id}-groove`; + const dot = `${id}-dot`; + const dotShadow = `${id}-dotshadow`; + return ( + + ); + } return ( @@ -608,7 +622,7 @@ function Display({ only }: { only?: "skin" }) { /** A row of picture choices, one checked: real radios, visually hidden, in a fieldset, * so Tab lands on the group and the arrows pick. */ -function TileGroup({ label, disabled, children }: { label: string; disabled?: boolean; children: ReactNode }) { +export function TileGroup({ label, disabled, children }: { label: string; disabled?: boolean; children: ReactNode }) { const name = useId(); return (
@@ -618,22 +632,25 @@ function TileGroup({ label, disabled, children }: { label: string; disabled?: bo ); } -function Tile({ +export function Tile({ label, on, onPick, children, + className, ...rest }: { label: string; on: boolean; onPick: () => void; children: ReactNode; + className?: string; "data-skin"?: string; + "data-app-icon"?: string; }) { const group = useContext(TileName); return ( -