-
Notifications
You must be signed in to change notification settings - Fork 929
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
Handle URLs on macOS #3825
base: master
Are you sure you want to change the base?
Handle URLs on macOS #3825
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @madsmtm has a different idea on how to approach all of that, but I don't mind having it under macOS specific application handler.
Also, it should be added without a specific event, just rely on the newly added callback.
/// Emitted when the application has received a URL, through a | ||
/// custom URL handler. | ||
/// | ||
/// Only supported on macOS. | ||
fn received_url(&mut self, event_loop: &ActiveEventLoop, url: String) { | ||
let _ = event_loop; | ||
let _ = url; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you create a macOS specific ApplicationHandler
and add it there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would very much like to get Iced back to using mainline Winit!
I just merged #3758, could you check if that allows you to do what Iced needs? See in particular the new docs under winit::platform::macos
.
@madsmtm Super excited to see #3758 merged. That looks like an absolutely fantastic solution for modular Winit on apple platforms. I'll have to implement it to be sure, but I reckon it will be possible for this to be implemented outside of Winit on top of #3758. And I reckon I can use some of the objc2 crates' functionality to really clean it up too. The one question I have is when/where I ought to run the code that registers the listener for the event that returns the url: I could use my own AppDelegate and register it in applicationWillFinishLaunching like the current PR does. But I would really like to be able to wrap this up in a library, and my feeling is that the approach you've used in #3758 ought to enable that. But that perhaps the Regarding event registration ordering:
|
It is quite a simple function, and will become even simpler in the future once
I don't know anything about the let block = RcBlock::new(|notification: NonNull<NSNotification>| {
let notification = unsafe { notification.as_ref() };
// ... Register in here
});
let observer = unsafe {
center.addObserverForName_object_queue_usingBlock(
// `applicationWillFinishLaunching:`
Some(unsafe { NSApplicationWillFinishLaunchingNotification }),
None,
None,
&block,
)
}
// Keep `observer` around until the end of `main` (or leak it). |
This allows macOS apps to access the URL when they are opened "as a browser / url handler". This is adapted from Iced's fork of Winit and I believe it is the main things preventing Iced from using upstream Winit.
Fixes #2190
changelog
module if knowledge of this change could be valuable to users