Skip to content

feat(workbench): add a show-system-tray-icon toggle - #1094

Merged
t8y2 merged 1 commit into
t8y2:mainfrom
DeanCen:feat/tray-icon-visibility-toggle
Nov 25, 2026
Merged

t8y2 merged 1 commit into
t8y2:mainfrom
DeanCen:feat/tray-icon-visibility-toggle

Conversation

@DeanCen

@DeanCen DeanCen commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a "Show system tray icon" switch to General settings, beside Start at login (#1039).

  • The choice is device-local (tray_icon_off) and read before the first window opens, so a hidden icon never flashes up. It is applied live through Options.SetTrayIcon.
  • Turning the icon off brings back any window hiding behind it first, so none is left unreachable.
  • The close logic is unchanged. Closing hides to the background only when an icon is present (status.hasStatusArea()). With the icon hidden — or on a desktop that cannot show one — closing the last window quits as usual.

Scope

This PR only adds the toggle. The "Closing the window" behavior is left exactly as upstream; no close-action rework is included.

Test plan

  • go test -race ./cmd/motty -run Tray (real status-item add/remove, ShowHidden).
  • go test -race ./internal/workbench -run 'Tray|CloseAction|SavedStateField|StatusArea|WhatClosingDoes|ShowHidden' (toggle + remember across restart; incremental saves of a running window; restore-then-toggle; settings-reload-after-save; device-local field registration; upstream close behavior).
  • Full workbench -race suite (batched): no data races; failure set identical to the pristine upstream baseline at bcb60df3 on Windows (zero new failures).
  • gofmt clean.

Closes #1039

@DeanCen DeanCen changed the title feat(workbench): add a show-system-tray-icon toggle and tie the close action to it feat(workbench): add a show-system-tray-icon toggle with background close behavior Nov 19, 2026
@DeanCen
DeanCen force-pushed the feat/tray-icon-visibility-toggle branch 2 times, most recently from 2946e8f to 86ca93b Compare November 19, 2026 16:50

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the work on this. Three items before merge:

  1. cmd/motty/main.go:380: the status.hasStatusArea() check was removed from requestClose. The default close action is stay-in-tray, so on a desktop where the status item cannot be created (e.g. Linux without a StatusNotifier host), closing the last window now hides it and keeps the process running with no icon and no way back except relaunching. Please keep quitting when the icon could not be shown (the user-hidden case can keep the new behavior), and add a test for that path.
  2. The issue (#1039) asks for a show/hide toggle. The rework of "Closing the window" goes beyond it and changes user-facing behavior. Please confirm that scope with the maintainer before it lands.
  3. persist_records_test.go:27 is not gofmt-clean (run gofmt -w). The comments at main.go:222-223 and 236-238 still describe the old behavior. The PR is also CONFLICTING with main, so please rebase.

General settings gain a switch beside Start at login that shows or hides
the system tray icon. The choice belongs to this device and is read before
the first window opens, so an icon the user turned off never flashes up.
Hiding the icon brings back any window hiding behind it first so none is
left unreachable.

The close logic is left exactly as it was: closing hides to the background
only when an icon is present, so with the icon hidden (or on a desktop that
cannot show one) closing the last window quits as usual.

Closes t8y2#1039
@DeanCen
DeanCen force-pushed the feat/tray-icon-visibility-toggle branch from 86ca93b to 0a75971 Compare November 23, 2026 09:49
@DeanCen DeanCen changed the title feat(workbench): add a show-system-tray-icon toggle with background close behavior feat(workbench): add a show-system-tray-icon toggle Nov 23, 2026
@DeanCen

DeanCen commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review — I've reworked the PR to keep it strictly to the toggle, addressing all three points:

  1. Close path is now exactly upstream's. The status.hasStatusArea() && state.StaysInTray() && (…) gate in requestClose is unchanged. With the icon hidden — or on a desktop that cannot create a status item (e.g. Linux without a StatusNotifier host) — hasStatusArea() is false, so closing the last window quits as before. No window can be stranded hidden with no way back.

  2. Scope narrowed to the toggle. I removed the "Closing the window" rework entirely. This PR now only adds the show/hide switch; the close behavior is left exactly as upstream. The toggle description states the consequence plainly: "When off, the tray icon is hidden and closing the window quits the app." Hiding the icon also brings back any window already hiding behind it first, so nothing is left unreachable.

  3. Hygiene. Rebased onto latest main (no conflicts), gofmt clean. The earlier stale-comment note no longer applies since the close logic and its comments are upstream's again.

The full workbench -race suite (batched) shows no data races and a failure set identical to the pristine baseline on Windows. Happy to adjust further if you'd like.

@t8y2
t8y2 merged commit 06778e3 into t8y2:main Nov 25, 2026
19 checks passed
@t8y2

t8y2 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution! Merged in 06778e3, will be released in the next version.

@DeanCen
DeanCen deleted the feat/tray-icon-visibility-toggle branch November 25, 2026 09:27
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.

[Feature] 系统托盘/菜单栏图标支持设置是否显示

2 participants