How can I pass a URI to a running desktop app

  1. 8 months ago

    Tim S

    14 Apr 2018 Canterbury, UK
    Edited 8 months ago

    A user can click on a URI (perhaps mailto: or ftp:) in for example a Safari window. Assuming my app is set to be the default app for a given URI type, how can I get that URI passed to my app so it can handle it?

  2. Axel S

    is not verified 14 Apr 2018 Europe (Germany, Erfurt)

    App.OpenDocument

  3. Tim S

    14 Apr 2018 Canterbury, UK

    @Axel S App.OpenDocument

    What would that give you for a URI? That event supplies a folderitem.

  4. Ramon S

    14 Apr 2018 Pre-Release Testers, Xojo Pro UPC, Europe (Barcelona, Spain)

    Command line, perhaps?

  5. Michel B

    14 Apr 2018 Pre-Release Testers RubberViews.com
      dim sh as new shell
      sh.execute("start http://fontmenu.com")
      sh.execute("start mailto:tagada@test.com")
  6. Paul L

    14 Apr 2018 Xojo Inc Answer http://docs.xojo.com

    Windows: https://blog.xojo.com/2016/08/16/custom-uri-schemes-on-windows/

    Mac: http://blog.xojo.com/2016/05/09/let-your-os-x-desktop-app-react-to-custom-uris/

  7. Sam R

    14 Apr 2018 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan

    If you have App Wrapper, there's a help document on how to configure your Mac application and how to support it from within the product.

  8. Tim S

    16 Apr 2018 Canterbury, UK

    @Paul L Windows: https://blog.xojo.com/2016/08/16/custom-uri-schemes-on-windows/

    Mac: http://blog.xojo.com/2016/05/09/let-your-os-x-desktop-app-react-to-custom-uris/

    Well, for macOS that works a treat, both when the app is running, and if it is not. For the Windows equivalent, I have a couple of questions:

    1) It suggests that the registry modifications be done at the install stage rather than at the app's runtime. Can I do this at runtime instead? If so, and the user doesn't have admin privs, would it offer to authenticate the user? And if I do it at runtime, is that making a new entry in the registry each time the app runs, or is it replacing the entry from last time I ran the app (I worry about the registry getting bigger and bigger).

    2) The method given seems oriented towards starting the app when it is not running, and then having the app look at the System.CommandLine property. But what if the app is already running? What event is triggered to give the app the hint to look at the System.CommandLine property?

    For both platforms, are the sequences given just registering the app as capable of handling the URI, or are they also setting the app as the default handler for the URI?

  9. Michel B

    16 Apr 2018 Pre-Release Testers RubberViews.com
    Edited 8 months ago

    I posted the Windows way above. But hey, my post was not as fancy. It works like clockworks, though.

    My way does not change the user defaults. It simply opens the URI in the default client. It will launch the client if necessary.

    And, BTW, here is the Mac method :

    dim sh as new shell
    sh.execute("open http://fontmenu.com")
    sh.execute("open mailto:tagada@test.com")
  10. Tim S

    16 Apr 2018 Canterbury, UK

    @Michel B I posted the Windows way above.

    I don't think you read my OP properly. My app is the default client, not some other app. My app is receiving the URI, not sending it out.

  11. Michel B

    16 Apr 2018 Pre-Release Testers RubberViews.com

    Go get it, Tiger.

  12. Julian S

    16 Apr 2018 Pre-Release Testers, Xojo Pro UK
    Edited 8 months ago

    @Tim S Can I do this at runtime instead?

    Yes

    @Tim S If so, and the user doesn't have admin privs, would it offer to authenticate the user?

    No, you need to elevate the app at runtime, you could spawn a new elevated version of your app and close this one, or create an elevated helper who's sole task it to register the URI then run it if needed. Check the existence of the registry entry from your main app then use the helper to add the registry entry. That is if you don't want to have an elevated app running all the time which might cause issues as IE might stop elevated apps running from URI's, I don't know for sure on that as I've not tested it.

    @Tim S And if I do it at runtime, is that making a new entry in the registry each time the app runs, or is it replacing the entry from last time I ran the app

    It will only create/modify the entry, it wont creat more than one.

    @Tim S The method given seems oriented towards starting the app when it is not running, and then having the app look at the System.CommandLine property. But what if the app is already running? What event is triggered to give the app the hint to look at the System.CommandLine property?

    The URI system will always spawn a new app. When your app starts, have it check if another is running (mutex ) and IPC the information across to that app to handle the new URI request then close down the app that was just created.

    @Tim S For both platforms, are the sequences given just registering the app as capable of handling the URI, or are they also setting the app as the default handler for the URI?

    I can't speak for macOS but in Windows, if you register the URI to your app it will be the only one handling it.

  13. Tim S

    17 Apr 2018 Canterbury, UK

    @Julian S Yes

    Good.

    No, you need to elevate the app at runtime, you could spawn a new elevated version of your app and close this one, or create an elevated helper whose sole task is to register the URI then run it if needed. Check the existence of the registry entry from your main app then use the helper to add the registry entry. That is if you don't want to have an elevated app running all the time which might cause issues as IE might stop elevated apps running from URI's, I don't know for sure on that as I've not tested it.

    Oh boy.

    It will only create/modify the entry, it wont create more than one.

    Good!

    The URI system will always spawn a new app. When your app starts, have it check if another is running (mutex ) and IPC the information across to that app to handle the new URI request then close down the app that was just created.

    Oh boy - again.

    I can't speak for macOS but in Windows, if you register the URI to your app it will be the only one handling it.

    OK I see - because there's just the one registry entry.

    Thanks for all that, Julian, although I'm not sure when I'll get round to working on it. Already, testing my app under Win7 in a VM has highlighted some issues. Still - onwards and upwards, and now at least I know what's involved.

or Sign Up to reply!