Skip to content

Use a native template icon in the macOS menu bar - #10196

Merged
danielhanchen merged 1 commit into
unslothai:mainfrom
guus6457:fix/macos-tray-icon
Oct 6, 2026
Merged

danielhanchen merged 1 commit into
unslothai:mainfrom
guus6457:fix/macos-tray-icon

Conversation

@guus6457

@guus6457 guus6457 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

The macOS tray currently reuses the full-color app icon, which leaves a green square in the menu bar. This adds a small transparent version of the existing sloth mark and registers it as a template image so macOS can match light and dark appearances automatically.

Windows and Linux keep the existing tray icon.

Tested with:

  • cargo check --manifest-path studio/src-tauri/Cargo.toml --all-targets
  • cargo test --manifest-path studio/src-tauri/Cargo.toml --all-targets (453 passed)

@guus6457
guus6457 requested a review from wasimysaid as a code owner September 2, 2026 12:30
@guus6457

guus6457 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 10f6da48a2

ℹ️ 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".

@guus6457

guus6457 commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

@wasimysaid When you have a moment, could you take a look? This is a small macOS-only tray icon change, and the local Tauri checks and all 453 Rust tests pass.

Superseded by unslothai#10880, which already ships a macOS template tray icon.
@danielhanchen

Copy link
Copy Markdown
Member

Thank you for the PR and for testing it so carefully, @guus6457!

We will not be taking the code change here because #10880, merged on 2026-09-14, already does the same thing: on macOS the tray now uses a monochrome icon registered with icon_as_template(true), so AppKit adapts it to light and dark menu bars. It also adds an appearance observer. Windows and Linux keep the color icon, as in your PR.

So that your contribution is still recorded and you are listed as a contributor, I reduced this PR to a single empty commit under your authorship and am merging that. Thanks again, and we would be glad to see more PRs from you.

@danielhanchen
danielhanchen merged commit 2231988 into unslothai:main Oct 6, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants