Search code examples
c#.netuwpdesktop-bridge

Desktop bridge toast open app


I've develop a WPF application that I've converter through Desktop App Converter and runs ok.

I´ve added toast notifications calling UWP APIs from desktop app as is explained here https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/10/16/quickstart-handling-toast-activations-from-win32-apps-in-windows-10/

But to be able to open the app automatically when user tap on the toast, I had to create a shortcut and register a COM component same way as https://github.com/WindowsNotifications/desktop-toasts and it's also ok.

I think It´s too much work compared with a UWP app where default behaviour is just this, open app without any code.

How could I open the app tapping toast in my converted app throw the Bridge, same way as a truly UWP?

Thanks.


Solution

  • I think It´s too much work compared with a UWP app where default behaviour is just this, open app without any code.

    There is a simple solution, the technical points as follow:

    1. Using the protocol association which described in the Desktop Bridge app extensions article
    2. Using the protocol ActivationType to launch the corresponding app, ref Adaptive and interactive toast notifications

    Some detailed steps we need to notice:

    1. Using protocal activation type in your payload of toast notification: <toast activationType='protocol' launch='mytoastsample:'> <visual> <binding template='ToastGeneric'> <text>Click to launch Wpf Toast Sample</text> </binding> </visual> </toast>

    2. After converting the application to UWP app, we need to open the Output directory and locate the AppxManifest.xml file.

    3. Append the protocol association extension in the AppxManifest.xml file

    <Application Id="WpfToastSample" Executable="WpfToastSample.exe" EntryPoint="Windows.FullTrustApplication"> <uap:VisualElements DisplayName="WpfToastSample" Description="WpfToastSample" BackgroundColor="#777777" Square150x150Logo="Assets\SampleAppx.150x150.png" Square44x44Logo="Assets\SampleAppx.44x44.png" /> <Extensions> <uap3:Extension Category="windows.protocol"> <uap3:Protocol Name="mytoastsample" Parameters="/p &quot;%1&quot;" /> </uap3:Extension> </Extensions> </Application>

    1. Follow Manually convert your app to UWP using the Desktop Bridge to repack and resign your app

    I created a sample in here

    The screenshot(gif): LINK