Skip to content

Studio: adapt macOS tray artwork to the menu bar appearance - #10880

Merged
wasimysaid merged 3 commits into
unslothai:mainfrom
wasimysaid:fix/macos-tray-template-icon
Sep 14, 2026
Merged

wasimysaid merged 3 commits into
unslothai:mainfrom
wasimysaid:fix/macos-tray-template-icon

Conversation

@wasimysaid

@wasimysaid wasimysaid commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • add separate 36×36 dark and light tray artwork for macOS
  • observe the actual NSStatusBarButton.effectiveAppearance, rather than the app/window theme, so wallpaper-, display-, and fullscreen-specific menu-bar changes are handled
  • select black filled artwork for a light menu bar and white outlined artwork for a dark menu bar
  • keep the native template icon as a visible fallback if the AppKit observer cannot install
  • unregister the KVO observer on the main thread before Tauri tears down the tray
  • preserve the existing Windows/Linux tray behavior

Why

On modern macOS, the menu bar's effective appearance can differ from the system or application theme and can change with the wallpaper or display. WindowEvent::ThemeChanged therefore cannot reliably select a contrasting status-item image. AppKit exposes the authoritative appearance on the status bar button itself.

Verification

  • cargo test --manifest-path studio/src-tauri/Cargo.toml --no-fail-fast (539 passed locally)
  • cargo check --manifest-path studio/src-tauri/Cargo.toml
  • rustfmt --edition 2021 --check studio/src-tauri/src/macos_tray.rs
  • git diff --check
  • verified all three 36×36 fallback/light/dark assets are RGBA PNGs with non-empty alpha and expected black/white pixel data
  • macOS-only tests cover Aqua/DarkAqua classification, dimensions, and artwork polarity

A Linux-hosted Apple-target check reaches native Apple dependencies but cannot complete without the macOS SDK (Cocoa/Cocoa.h and TargetConditionals.h). The repository's macOS Rust CI job provides native compile/test coverage.

References

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-14T09:32:12.645478Z 0f7fcdb New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ae705968d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// macOS renders tray images at 18 points. Embed the 36 px scale for crisp Retina output;
// template mode lets AppKit choose the correct monochrome color for the current menu bar.
#[cfg(target_os = "macos")]
let tray_icon = tauri::include_image!("./icons/[email protected]");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Point the embedded icon at its source-relative path

On macOS, this cfg branch expands include_image!, whose path is resolved relative to the invoking Rust source file. Since main.rs is under src/, this searches for studio/src-tauri/src/icons/[email protected], but the asset was added under studio/src-tauri/icons; consequently every macOS build fails while Linux tests skip the branch. Use ../icons/[email protected] here.

Useful? React with 👍 / 👎.

@wasimysaid

Copy link
Copy Markdown
Collaborator Author

Superseded by #10890, which uses the separate light/dark artwork and switches the tray icon when macOS appearance changes.

@wasimysaid wasimysaid closed this Sep 14, 2026
@wasimysaid wasimysaid reopened this Sep 14, 2026
@wasimysaid wasimysaid changed the title Studio: use a native template tray icon on macOS Studio: adapt macOS tray artwork to the menu bar appearance Sep 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4d1428028e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread studio/src-tauri/src/macos_tray.rs Resolved
@wasimysaid

Copy link
Copy Markdown
Collaborator Author

Real macOS tray E2E evidence

Tested exact PR head: 4d1428028e53edd90dbcf40b09ab8930eb3c9be3

The GitHub-hosted Apple Silicon macOS job built and launched the actual Tauri .app, then kept the same process alive while changing the real menu-bar appearance from light to dark. This is live UI evidence, not a mocked assertion.

GitHub Actions run 34824594349 · evidence source PR · artifact pr10880-real-macos-tray-evidence

Labelled light/dark comparison

PR 10880 light and dark menu-bar tray evidence

Full-screen light and dark captures

Light menu bar — black filled tray artwork

PR 10880 light menu bar

Dark menu bar — white outlined tray artwork, same live PID

PR 10880 dark menu bar

Measured from the real screenshots:

  • same PID across appearance change: 23300
  • light: 176/176 changed pixels became darker
  • dark: 141/141 changed pixels became lighter
  • menu-bar median luminance: 218 light vs 32 dark

Result: PASS — the tray artwork stays visible and switches to the correct contrasting variant when macOS appearance changes.

@wasimysaid
wasimysaid merged commit dabb59f into unslothai:main Sep 14, 2026
21 of 30 checks passed
danielhanchen pushed a commit that referenced this pull request Oct 6, 2026
Superseded by #10880. Null contribution.

Co-authored-by: Guus <[email protected]>
danielhanchen added a commit that referenced this pull request Oct 19, 2026
Closes #10157

## What

Adds a macOS-only **Settings → General → Startup → Show in menu bar**
switch. Turning it off hides the Unsloth menu bar icon immediately and
keeps it hidden on later launches; turning it on brings it back.

## Why this shape

A login start runs with `--hidden`, and `.setup` then switches the app
to `ActivationPolicy::Accessory` (no Dock icon). With the menu bar icon
also gone, a hidden start would leave a running app with no way back to
it. So a hidden start keeps its Dock icon whenever the menu bar icon is
hidden: the window still stays hidden, and clicking the Dock icon opens
it through the existing `RunEvent::Reopen` → `show_main_window` path.
"Run Unsloth at login" is left exactly as the user set it.

## Changes

**`studio/src-tauri/src/main.rs`**
- New `tray-icon-visible-v1` preference beside `close-to-tray-v1`, with
the same read/write helpers. A missing, unreadable or invalid file reads
as *visible*: hiding is opt-in, and a corrupt file can never strand the
app.
- The tray is built with `TrayIconBuilder::with_id("main")`, and on
macOS the stored visibility is applied right after it is built.
- `get_tray_icon_visible` returns `None` off macOS, so the row only
renders on macOS. `set_tray_icon_visible` applies
`TrayIcon::set_visible` first, then persists; if persisting fails it
restores the previous visibility and returns the error, so the switch
never disagrees with what the next launch will do.
- The Accessory policy is applied only when `launched_hidden` **and**
the icon is visible.
- Two unit tests: the default is visible and round-trips; an invalid
file reads as visible.

**`studio/frontend`**
- `api/tray-icon.ts` invoke wrappers, and a Startup row in
`general-tab.tsx` built on the existing `useDesktopBooleanSetting` hook,
mirroring the close-to-tray row.
- The row is indexed for Settings search only on the macOS desktop
(`createSettingsSearchIndex({ …, menuBarIcon })`), with a test extended
in `tests/settings-search.test.ts`.
- `menuBarIcon`, `menuBarIconDescription` and `menuBarIconSaveError`
added to `en.ts` and translated in all 11 other locales, since
`i18n:check:strict` requires them.

## Not in this PR

The issue comment also asked for a monochrome icon. That already shipped
in #10880 (`macos_tray.rs` picks light or dark artwork from the menu
bar's effective appearance), and #10196 is marked superseded.

## Verification (macOS 26, Apple M1 Pro)

- `cargo test --no-fail-fast`: 580 passed, including the two new tests.
`cargo fmt --check` / `cargo clippy` report only findings that already
exist on `main` (120 fmt diffs on `main` itself); none are in the lines
this PR touches.
- `npm run typecheck`, `npm test` (8776 passed), `npm run
i18n:check:strict`, `npm run build` all pass. `npm run lint` reports
only existing findings in files this PR does not touch.
- Ran the debug desktop build and read the menu bar and Dock state
through System Events:
  - normal launch → menu bar icon shown, Dock icon shown;
- `--hidden`, icon visible → menu bar icon shown, no Dock icon
(unchanged behaviour);
  - `--hidden`, icon hidden → no menu bar icon, Dock icon kept.
- Toggled the switch in the running debug build: off → the menu bar item
disappears and `tray-icon-visible-v1` holds `false`; on → it returns and
the file holds `true`. After switching it off, quitting and relaunching,
the icon stays hidden at startup and the switch reads off.


## macOS Desktop before/after

Captured on a GitHub `macos-26` runner: the Desktop app built from the
merge base (`31436b1`) and from this PR (`2a07993`), both attached to
the same installed Studio backend and driven through the Accessibility
API.

Settings > General > Startup. The new "Show in menu bar" row appears
only on the PR build:

![Settings General tab, merge base vs this
PR](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/11937/composite_settings-3da676a27886.png)

Flipping the switch on the PR build removes the Unsloth menu bar item,
and flipping it back restores it:

![Menu bar with the switch on and
off](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/11937/composite_menubar-f266878583c3.png)

Read from the running app at each step: the app's menu bar extras count
went 1 -> 0 -> 1, the switch value 1 -> 0 -> 1, and
`tray-icon-visible-v1` held `false`, then `true`.

---------

Co-authored-by: Nilay Yadav <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant