Skip to content

feat: allow macOS tray to maintain position #47838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 7, 2025
Merged

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
}

Tray::~Tray() = default;

// static
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
Copy link
Member

@itsananderson itsananderson left a comment

Choose a reason for hiding this comment

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

API LGTM

Copy link
Member

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

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

API LGTM

@codebytere codebytere merged commit a0d983e into main Aug 7, 2025
105 of 107 checks passed
@codebytere codebytere deleted the autosave-name-tray branch August 7, 2025 17:25
@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
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.

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