桌面桥toast打开app
Desktop bridge toast open app
我开发了一个 WPF 应用程序,我已经通过 Desktop App Converter 进行了转换并且运行正常。
我添加了从桌面应用程序调用 UWP API 的 toast 通知,如此处所述https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/10/16/quickstart-handling-toast-activations-from-win32-apps-in-windows-10/
但是为了能够在用户点击 toast 时自动打开应用程序,我必须创建一个快捷方式并以与 https://github.com/WindowsNotifications/desktop-toasts 相同的方式注册一个 COM 组件,这也是可以的。
我认为与 UWP 应用程序相比工作量太大,默认行为就是这样,无需任何代码即可打开应用程序。
我如何在转换后的应用程序中打开应用程序点击 toast throw Bridge,就像真正的 UWP 一样?
谢谢。
I think It´s too much work compared with a UWP app where default behaviour is just this, open app without any code.
有一个简单的解决方案,技术要点如下:
- 使用 Desktop Bridge app extensions 文章中描述的协议关联
- 使用协议 ActivationType 启动相应的应用程序,参考 Adaptive and interactive toast notifications
我们需要注意的一些详细步骤:
在 toast 通知的负载中使用协议激活类型:
<toast activationType='protocol' launch='mytoastsample:'>
<visual>
<binding template='ToastGeneric'>
<text>Click to launch Wpf Toast Sample</text>
</binding>
</visual>
</toast>
将应用程序转换为 UWP 应用程序后,我们需要打开 Output 目录并找到 AppxManifest.xml 文件。
在 AppxManifest.xml 文件中附加协议关联扩展
<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 "%1"" />
</uap3:Extension>
</Extensions>
</Application>
- 按照 Manually convert your app to UWP using the Desktop Bridge 重新打包并退出您的应用程序
我在 here
中创建了一个样本
截图(gif): LINK
其实比这个更简单。使用 Desktop Bridge 后,您可以使用与 UWP 应用程序相同的方式创建 Toast。单击 toast 将以正确的模式启动您的 Desktop Bridge 应用程序。我最近发布了几个这样做的示例。您可以从 Windows 商店下载它们并在 GitHub 上找到源。链接和更多详细信息在此 blog post 中。如果这没有帮助,请告诉我。如果需要,我可以在 WPF 中为此发送更简洁的 'hello world' 示例。
谢谢,
斯特凡维克
我发现(在我的例子中是手动转换的 WinForms 应用程序)toast 通知(使用协议或前台激活)启动应用程序的新实例。当用户与 toast 交互时应用不是 运行 时,这很好。但是,如果应用程序是 运行,那就太糟糕了。
为了解决这个问题,我使用了 Mutex,这样如果另一个实例已经存在,第二个实例就可以正常退出。 toast 视觉参数以 Main 为基础,就好像它们是命令行参数一样。
我正在使用几个助手来做这个 GitHub:https://github.com/dkackman/DesktopBridgeEnvironment
所以我的 Main 看起来像这样(其中 SingleInstance
和 ExecutionEnvironment
是辅助类型)
static void Main(string [] args)
{
using (var instance = new SingleInstance(ExecutionEnvironment.Current.AppId))
{
if (instance.IsFirstInstance)
{
ExecutionEnvironment.Current.StartupArgs = args;
HockeyClient.Current.Configure("xxxxxxxxxxxxxxxxxxx");
try
{
HockeyClient.Current.SendCrashesAsync();
}
catch { }
using (var program = new Program())
{
program.Show();
}
}
}
}
在程序的其他地方,检查启动参数以查看如何处理通知(如果有)。有点蛮力,但如果没有生成多个应用程序实例,我无法让它以任何其他方式工作。
我开发了一个 WPF 应用程序,我已经通过 Desktop App Converter 进行了转换并且运行正常。
我添加了从桌面应用程序调用 UWP API 的 toast 通知,如此处所述https://blogs.msdn.microsoft.com/tiles_and_toasts/2015/10/16/quickstart-handling-toast-activations-from-win32-apps-in-windows-10/
但是为了能够在用户点击 toast 时自动打开应用程序,我必须创建一个快捷方式并以与 https://github.com/WindowsNotifications/desktop-toasts 相同的方式注册一个 COM 组件,这也是可以的。
我认为与 UWP 应用程序相比工作量太大,默认行为就是这样,无需任何代码即可打开应用程序。
我如何在转换后的应用程序中打开应用程序点击 toast throw Bridge,就像真正的 UWP 一样?
谢谢。
I think It´s too much work compared with a UWP app where default behaviour is just this, open app without any code.
有一个简单的解决方案,技术要点如下:
- 使用 Desktop Bridge app extensions 文章中描述的协议关联
- 使用协议 ActivationType 启动相应的应用程序,参考 Adaptive and interactive toast notifications
我们需要注意的一些详细步骤:
在 toast 通知的负载中使用协议激活类型:
<toast activationType='protocol' launch='mytoastsample:'> <visual> <binding template='ToastGeneric'> <text>Click to launch Wpf Toast Sample</text> </binding> </visual> </toast>
将应用程序转换为 UWP 应用程序后,我们需要打开 Output 目录并找到 AppxManifest.xml 文件。
在 AppxManifest.xml 文件中附加协议关联扩展
<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 "%1"" />
</uap3:Extension>
</Extensions>
</Application>
- 按照 Manually convert your app to UWP using the Desktop Bridge 重新打包并退出您的应用程序
我在 here
中创建了一个样本截图(gif): LINK
其实比这个更简单。使用 Desktop Bridge 后,您可以使用与 UWP 应用程序相同的方式创建 Toast。单击 toast 将以正确的模式启动您的 Desktop Bridge 应用程序。我最近发布了几个这样做的示例。您可以从 Windows 商店下载它们并在 GitHub 上找到源。链接和更多详细信息在此 blog post 中。如果这没有帮助,请告诉我。如果需要,我可以在 WPF 中为此发送更简洁的 'hello world' 示例。
谢谢, 斯特凡维克
我发现(在我的例子中是手动转换的 WinForms 应用程序)toast 通知(使用协议或前台激活)启动应用程序的新实例。当用户与 toast 交互时应用不是 运行 时,这很好。但是,如果应用程序是 运行,那就太糟糕了。
为了解决这个问题,我使用了 Mutex,这样如果另一个实例已经存在,第二个实例就可以正常退出。 toast 视觉参数以 Main 为基础,就好像它们是命令行参数一样。
我正在使用几个助手来做这个 GitHub:https://github.com/dkackman/DesktopBridgeEnvironment
所以我的 Main 看起来像这样(其中 SingleInstance
和 ExecutionEnvironment
是辅助类型)
static void Main(string [] args)
{
using (var instance = new SingleInstance(ExecutionEnvironment.Current.AppId))
{
if (instance.IsFirstInstance)
{
ExecutionEnvironment.Current.StartupArgs = args;
HockeyClient.Current.Configure("xxxxxxxxxxxxxxxxxxx");
try
{
HockeyClient.Current.SendCrashesAsync();
}
catch { }
using (var program = new Program())
{
program.Show();
}
}
}
}
在程序的其他地方,检查启动参数以查看如何处理通知(如果有)。有点蛮力,但如果没有生成多个应用程序实例,我无法让它以任何其他方式工作。