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

Associating a File type with application #80

Open
wilsonowilson opened this issue Aug 31, 2021 · 5 comments
Open

Associating a File type with application #80

wilsonowilson opened this issue Aug 31, 2021 · 5 comments

Comments

@wilsonowilson
Copy link

When you right-click a .pdf file and hover over the "Open with" menu on macOS or Windows, a list of applications that can open the file show up. How can we set file associations in a Nativeshell application?

@knopp
Copy link
Contributor

knopp commented Sep 2, 2021

Generally file associations are registered in Info.plist file. There's quite a bit of documentation about this online. However handling the file open notification will require some rust code right now.

I haven't tested this particular thing so it's possible that some things won't work. In general you will get a method called (application:openFiles:) or (application:openURLs:) on your NSApplicationDelegate. NativeShell exposes NSApplicationDelegate to rust, so you don't need to write any objc bindings.

Create a struct and let it implement the ApplicationDelegate trait. In the trait, override application_open_urls method. Then register your delegate

context.get().unwrap().application_delegate_manager.borrow().set_delegate(my_app_delegate);

At this point your should get notification when your application was asked to open URLs. After that you might need to use platform channels to let the dart code know that it should open the file.

@knopp
Copy link
Contributor

knopp commented Sep 2, 2021

I'll try to find some time to make a working example of this.

@wilsonowilson
Copy link
Author

Thanks for the tips! But how do we edit the Info.plist file?

@knopp
Copy link
Contributor

knopp commented Sep 2, 2021

You can copy the Info.plist template from NativeShell, put it somewhere in your project and then reference it in build.rs:

let options = AppBundleOptions {
...
   info_plist_template: Some("resources/Info.plist".into()), // assuming you placed it in resources/Info.plist
...
}

@prateekmedia
Copy link

@knopp Can this be made multi-platform like for windows and linux too.

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

No branches or pull requests

3 participants