Skip to content

GWin32AppInfo: Fixes for UWP (packaged) apps activation

Luca Bacci requested to merge lb90/glib:g-win32-app-info-enhancements into main

Currently there are two issues with activation of UWP apps:

  1. g_app_info_launch_uris (and related) only launches the first URI when the target application is UWP, others are ignored.
  2. g_app_info_launch_uris (and related) does not work when passing file URI's and the target application is UWP. The target app is launched, but no file is opened in the app. As en example, if you have the MS Photos app as the registered handler for PNG images, and you call gtk_show_uri ("file:///C:\\path\\to\\image.png"), the MS Photos app will be launched but no file will show up.

This MR accounts for the two issues:

  1. For launching UWP apps we create an IShellItemArray which wraps all the passed-in URI's or GFiles, then call either ActivateForProtocol() or ActivateForFile(). For the latter (ActivateForFile) that's entirely fine, however the former,ActivateForProtocol, wants an IShellItemArray consisting of only one item. This is documented on MSDN:

    itemArray: a pointer to an array of a single Shell item. The first item in the array
    is converted into a Uri object that is passed to the app through Protocol-
    ActivatedEventArgs. Any items in the array except for the first element
    are ignored.

    Here we fix that by calling ActivateForProtocol repeatedly in a loop for each passed URI.

  2. UWP apps support many URI protocols for opening different "activities". Most also support opening files, however not through the file:/// protocol. As an exaxmple, the Microsoft Photos app supports the following protocols:

    • microsoft.windows.photos.picker
    • ms-wcrv
    • microsoft.windows.photos.crop
    • microsoft.windows.photos.videoedit
    • ms-wpdrmv
    • ms-photos

    It also supports opening files, but doesn't support the file:/// protocol. Handle that case by checking if supports_files () is TRUE and calling ActivateForFiles ().

Edited by Luca Bacci

Merge request reports