Skip to content
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

Rewrite to use objc2 #172

Merged
merged 3 commits into from
Jun 28, 2024
Merged

Rewrite to use objc2 #172

merged 3 commits into from
Jun 28, 2024

Conversation

madsmtm
Copy link
Contributor

@madsmtm madsmtm commented Jun 26, 2024

This ensures that memory management rules are upheld, as well as greatly improving type-safety.

API-wise, this adds a new error case NotMainThread, which is triggered when a TrayIcon is created on a thread that is not the main thread.

There is probably a bug lurking in here somewhere, I'm not too familiar with the exact details of the NSStatusItem API.
Notably, there's also still a lot of if Some(...) checks that I'm not sure are completely necessary, though this PR shouldn't make the situation any worse on that front.

Related: The migration to objc2 in wry: tauri-apps/wry#1239

.map(|menu| menu.retain());
ns_status_item.setMenu(menu.as_deref());
if let Some(menu) = &menu {
let () = msg_send![menu, setDelegate: &**ns_status_item];
Copy link
Contributor Author

@madsmtm madsmtm Jun 26, 2024

Choose a reason for hiding this comment

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

I'm not sure what the original code intended here, but this is wrong, NSStatusItem doesn't implement NSMenuDelegate (at least not publicly).

I have kept the implementation as-is, but this should probably be looked into after this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, it was set to tray_target. Maybe @lucasfernog has some ideas?

This ensures that memory management rules are upheld, as well as greatly
improving type-safety.

API-wise, this adds a new error case `NotMainThread`, which is triggered
when a TrayIcon is created on a thread that is not the main thread.
@madsmtm
Copy link
Contributor Author

madsmtm commented Jun 27, 2024

The "covector" CI step is failing, it seems to be lacking certain permissions?

@amrbashir
Copy link
Member

amrbashir commented Jun 27, 2024

yeah that workflow can be ignored, it doesn't like forks (we are working on it)

@amrbashir amrbashir requested a review from pewsheen June 27, 2024 01:40
Copy link
Contributor

@pewsheen pewsheen left a comment

Choose a reason for hiding this comment

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

Looks good! It's a great example to follow. Just a question for you from my side.

Btw, I'm also doing the migration on wry. It's kind of chaos now, and the functionality is also broken 🤣

src/platform_impl/macos/mod.rs Show resolved Hide resolved
@madsmtm
Copy link
Contributor Author

madsmtm commented Jun 27, 2024

the migration on wry

I saw, it's nice! When you're ready, I'd be happy to help out, or review a PR, or something!

@pewsheen
Copy link
Contributor

pewsheen commented Jun 27, 2024

LGTM!
We need a change file and need you to sign these commits.

@madsmtm
Copy link
Contributor Author

madsmtm commented Jun 27, 2024

We need a change file

Ah yeah, have done that now (not sure it's correct though).

(Would've been nice to note in the CONTRIBUTING.md btw, that'd make it pop up automatically when I submitted the PR).

@pewsheen pewsheen merged commit d407869 into tauri-apps:dev Jun 28, 2024
8 of 9 checks passed
@madsmtm madsmtm deleted the objc2 branch June 28, 2024 04:49
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.

3 participants