Skip to content

feat(studio): add a setting to hide the macOS menu bar icon - #11937

Merged
danielhanchen merged 10 commits into
unslothai:mainfrom
Mathews-Tom:studio/hide-macos-menu-bar-icon
Oct 19, 2026
Merged

danielhanchen merged 10 commits into
unslothai:mainfrom
Mathews-Tom:studio/hide-macos-menu-bar-icon

Conversation

@Mathews-Tom

@Mathews-Tom Mathews-Tom commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

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

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

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.

@Mathews-Tom
Mathews-Tom force-pushed the studio/hide-macos-menu-bar-icon branch 2 times, most recently from 7b7731e to cfcd9fc Compare September 25, 2026 17:43
@Mathews-Tom Mathews-Tom changed the title Studio: let macOS users hide the menu bar icon feat(studio): add a setting to hide the macOS menu bar icon Sep 25, 2026
Add a macOS-only Settings > General > Startup "Show in menu bar" switch. The choice persists in a new tray-icon-visible-v1 preference beside close-to-tray-v1; a missing or unreadable file means shown, so hiding stays opt-in.

The tray is built with a stable id so the new set_tray_icon_visible command can reach it; the command applies TrayIcon::set_visible first and restores the previous visibility if persisting fails. get_tray_icon_visible returns None off macOS, so the row renders only there.

A login start (--hidden) drops the Dock icon via ActivationPolicy::Accessory. With the menu bar icon also hidden that would leave no way back to the app, so Accessory is now applied only when the menu bar icon is visible; otherwise the hidden start keeps its Dock icon.

Closes unslothai#10157
@Mathews-Tom
Mathews-Tom force-pushed the studio/hide-macos-menu-bar-icon branch from 82a91d4 to dbee215 Compare September 25, 2026 19:39
@NilayYadav NilayYadav self-assigned this Sep 25, 2026
@danielhanchen danielhanchen self-assigned this Sep 30, 2026
@shimmyshimmer

Copy link
Copy Markdown
Member

Review record for #11937, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#235.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1: reviewed mirror 2a079930bc (this PR's 2a079930b)

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 2a079930bc

No triage reaction was recorded on the mirror

chatgpt-codex-connector[bot] (on the mirror)

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 2a079930bc

View security finding report

Only the user who started this review can view the report in Codex.

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror 2a079930bc (this PR's 2a079930b).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 30, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 30, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@danielhanchen

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-10-19T12:18:21.517192Z a80d92e Manual request
ℹ️ 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

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: bd4b485c4f

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

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: a80d92e2fb

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

@danielhanchen
danielhanchen merged commit 2b20770 into unslothai:main Oct 19, 2026
danielhanchen added a commit that referenced this pull request Oct 19, 2026
danielhanchen added a commit that referenced this pull request Oct 19, 2026
## Summary

Main is over the startup bundle budget again, by 189 B raw, so `Frontend
build + bundle sanity` fails on every PR based on it:

```
over the startup budget: raw 6682.2 KB > 6682.0 KB      (main at 6ccf0e4)
```

#14258 set both limits to the measured build plus a 160 B raw / 189 B
transfer margin. #11937 (a setting to hide the macOS menu bar icon) then
added 349 B raw / 78 B transfer to the startup chunks, and merged
without raising them.

## Cause

#11937 adds strings to `i18n/locales/en.ts`, which ships in the startup
chunks, and entries to the settings search index (`settings-search.ts`,
`dialog-search-index.ts`). That is small real growth. I measured each
commit since #14258 on its own:

| tree | raw B | transfer B |
|---|---|---|
| `46e4f50bea` (#14258) | 6,842,183 | 2,060,321 |
| `2b20770c91` (+ #11937) | 6,842,532 | 2,060,399 |
| `f5e91f1ca5` (+ #14223) | 6,842,532 | 2,060,421 |
| main `6ccf0e4e74` (+ #14232) | 6,842,532 | 2,060,400 |

#14223 and #14232 add no raw bytes. #14021 and #14263 change no frontend
code.

## Change

- **`check-bundle-budget.ts`:** a BUDGET comment entry for #11937, and
both limits moved to the measured build at main plus the same margin:
  - `rawBytes`: 6,842,343 -> 6,842,692.
  - `transferBytes`: 2,060,510 -> 2,060,589.

## Testing

One machine and build, Node 24, exact byte totals from the budget
script, 96 chunks.

- **Main against the old limits:** `over the startup budget: raw 6682.2
KB > 6682.0 KB`.
- **With this change:** `within budget (0.2 KB transfer, 0.2 KB raw to
spare)`.
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.

[Feature] Ability to disable the Menu bar icon on macOS

5 participants