Skip to content

Conversation

@codebytere
Copy link
Member

@codebytere codebytere commented Jul 21, 2025

Description of Change

Closes #42154.

Fixes an issue where a tray icon on macOS would not maintain position across launches.

macOS allows setting an autosave name on an NSStatusItem, which enables the icon to maintain its position across launches. If a user creates and then closes a tray icon and then creates a new one with the same autosave name as the previously closed one, macOS will place it in the same position as the previous one with the same name.

We do this by adding a feature to customize the autosave name.

Checklist

Release Notes

Notes: Added tray.{get|set}AutosaveName to enable macOS tray icons to maintain position across launches.

@codebytere codebytere requested a review from a team July 21, 2025 08:41
@codebytere codebytere added semver/minor backwards-compatible functionality target/36-x-y PR should also be added to the "36-x-y" branch. target/37-x-y PR should also be added to the "37-x-y" branch. target/38-x-y PR should also be added to the "38-x-y" branch. labels Jul 21, 2025
Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

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

I feel like this should be in the constructor, not set after the fact.

In fact there is already a param for this for windows. new Tray(image, [guid]). That guid param is what does this on windows, we should just re-use the same param on macOS. Heck even make it a guid on macOS too, this name isn't user facing, just have folks assign it a static guid on both platforms.

@MarshallOfSound MarshallOfSound dismissed their stale review July 21, 2025 08:49

comment, not block, my bad

@codebytere
Copy link
Member Author

@MarshallOfSound fair enough - the reason i didn't do that was that we already have an optional second parameter for tray and i wanted to avoid a breaking change. ideally it'd be two options in an object in the ctor.

@MarshallOfSound
Copy link
Member

@MarshallOfSound fair enough - the reason i didn't do that was that we already have an optional second parameter for tray and i wanted to avoid a breaking change. ideally it'd be two options in an object in the ctor.

No like, I'm saying use that existing second parameter, it's usecase is just a windows-specific version of your use case. I don't think it's a breaking change to add platform support for a given parameter.

@codebytere
Copy link
Member Author

@MarshallOfSound oh gotcha - hm yeah i'll give it a go, easy enough!

@codebytere codebytere force-pushed the autosave-name-tray branch 3 times, most recently from 65515a4 to 84010ab Compare July 21, 2025 17:53
@codebytere codebytere force-pushed the autosave-name-tray branch 2 times, most recently from d632ec6 to 0787d3d Compare July 22, 2025 08:43
gin::Handle<Tray> Tray::New(gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> image,
std::optional<UUID> guid,
std::optional<base::Uuid> guid,
Copy link
Member

Choose a reason for hiding this comment

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

What is the difference here?

Copy link
Member Author

Choose a reason for hiding this comment

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

@MarshallOfSound easier to handle cross-platform and delegates parsing to upstream

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Jul 28, 2025
@codebytere codebytere force-pushed the autosave-name-tray branch from 0787d3d to df06d98 Compare July 31, 2025 09:10
@release-clerk
Copy link

release-clerk bot commented Aug 7, 2025

Release Notes Persisted

Added tray.{get|set}AutosaveName to enable macOS tray icons to maintain position across launches.

@trop
Copy link
Contributor

trop bot commented Aug 7, 2025

I was unable to backport this PR to "37-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot removed the target/37-x-y PR should also be added to the "37-x-y" branch. label Aug 7, 2025
@trop
Copy link
Contributor

trop bot commented Aug 7, 2025

I was unable to backport this PR to "36-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot added needs-manual-bp/37-x-y and removed target/36-x-y PR should also be added to the "36-x-y" branch. labels Aug 7, 2025
@trop
Copy link
Contributor

trop bot commented Aug 7, 2025

I was unable to backport this PR to "38-x-y" cleanly;
you will need to perform this backport manually.

@trop trop bot added needs-manual-bp/36-x-y needs-manual-bp/38-x-y and removed target/38-x-y PR should also be added to the "38-x-y" branch. labels Aug 7, 2025
@trop
Copy link
Contributor

trop bot commented Aug 14, 2025

@codebytere has manually backported this PR to "37-x-y", please check out #48076

@trop
Copy link
Contributor

trop bot commented Aug 14, 2025

@codebytere has manually backported this PR to "38-x-y", please check out #48077

@trop
Copy link
Contributor

trop bot commented Aug 14, 2025

@codebytere has manually backported this PR to "36-x-y", please check out #48078

@trop trop bot added in-flight/36-x-y merged/38-x-y PR was merged to the "38-x-y" branch. merged/36-x-y PR was merged to the "36-x-y" branch. merged/37-x-y PR was merged to the "37-x-y" branch. and removed needs-manual-bp/36-x-y in-flight/38-x-y in-flight/36-x-y in-flight/37-x-y labels Aug 14, 2025
kigh-ota pushed a commit to kigh-ota/electron that referenced this pull request Sep 30, 2025
* feat: allow macOS tray to maintain position

* refactor: just use guid

* test: fixup tests

* docs: clarify UUID format
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review/approved ✅ merged/36-x-y PR was merged to the "36-x-y" branch. merged/37-x-y PR was merged to the "37-x-y" branch. merged/38-x-y PR was merged to the "38-x-y" branch. semver/minor backwards-compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: NSStatusItem doesn't maintain position in menubar across launches

8 participants