-
-
Notifications
You must be signed in to change notification settings - Fork 201
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
feat: add support to deeplink and file association on macOS #422
Conversation
c3d582c
to
e8ec189
Compare
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.
Thank you for your PR. Please check my review.
Did you try using https://developer.apple.com/documentation/appkit/nsapplicationdelegate/2887193-application?language=objc instead? I'm asking because that's what we need for "deep linking" support and it conflicts with openFile, and i'm not sure yet how we want to handle this conflict. I guess if we can use one interface for both that would be the easiest/best solution. Anyway, i wanted to try making deep linking work on macos tomorrow, so i can try it out myself too. |
I did not aware of the conflict before, and i will try |
I have tried |
OpenFile
Event for macOSOpenURLs
Event for macOS
OpenURLs
Event for macOSOpenFile
Event for macOS
I think Electron has both events btw. |
Actually I saw it gets weird on multiple files :( This scares me about openURLs
|
electron doesn't mention anything about this in their docs so I wonder how electron behaves if you register for both events, anyways, lets follow the official docs. And in light of this limitation, we need to use the callback style then like this PR rust-windowing/winit#1759 so it can be opt-in for whichever event you want. |
We could also emit OpenFile if the url is |
maybe that's something that could be offloaded to tauri instead and tao just allows registering both and documents that only one should be registered. |
What is the progress on this issue? |
@wusyong could you check out this PR when you have some time? especially the |
@amrbashir How do I test this? Is there an example to run? |
use tao::{
event::{Event, WindowEvent},
event_loop::{ControlFlow, EventLoop},
window::WindowBuilder,
};
#[allow(clippy::single_match)]
fn main() {
let event_loop = EventLoop::new();
let window = Some(
WindowBuilder::new()
.with_title("A fantastic window!")
.with_inner_size(tao::dpi::LogicalSize::new(128.0, 128.0))
.build(&event_loop)
.unwrap(),
);
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Wait;
println!("{:?}", event);
match event {
Event::OpenFile { filename, success } => {
dbg!(filename);
*success = false; // reject the drop, change to true to accept it
}
Event::WindowEvent {
event: WindowEvent::Destroyed,
window_id: _,
..
} => {
*control_flow = ControlFlow::Exit;
}
Event::MainEventsCleared => {
if let Some(w) = &window {
w.request_redraw();
}
}
_ => (),
}
});
} |
I tired example above but it couldn't really test if events work. If anyone knows how to test it, please let me know. |
AppState::open_file(filename, &mut success); | ||
trace!("Completed `application:openFile:`"); | ||
|
||
success as i8 |
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.
This line throws error since return should be BOOL
OpenURLs
Event for macOS
I'm testing it again and seems like |
I honestly forgot most of it too, but yeah, openurls is enough unless we need to respond to the openfile event (tho tbh i've not seen a usecase for that yet) and and could be used to simplify the implementation 🤷 One thing tho, did you test it with multiple files too? we've had issues with that when we tried to abuse my deep link plugin for that. So if all of that works i personally don't see much of a reason to keep openFile/s around |
I did test with multiple files, seems to work fine. I guess we can go with the openURLs approach and wait for community feedback. |
I'd support openFile but default to openURLs because this will and should be upstreamed to winit and could serve as a reference the en |
@amrbashir when we upstream we could always use |
yeah I know it is enough but I never want to restrict tao to an API and if possible allow both ways if it is not much hassle. Just to be safe from a future feature request where someone might request it. |
What kind of change does this PR introduce?
Does this PR introduce a breaking change?
Checklist
fix: remove a typo, closes #___, #___
)Other information
This feature is necessary for the file-association function: open files with tauri-based app.
ref: tauri-apps/tauri#4320