边缘:进程内本机扩展和Windows.System.Launcher.LaunchFileAsync [英] Edge: In-Process native extension and Windows.System.Launcher.LaunchFileAsync
问题描述
I have developed an edge browser extension (native messaging) using the in-process mechanism as described here (through an activation of OnBackgroundActivated
). Within OnBackgroundActivated
, or to be more specific in OnAppServiceRequestReceived
of the established app service connection, I am attempting to call Windows.System.Launcher.LaunchFileAsync(IStorageFile)
. This doesn't appear to happen on the UI-Thread (although it does work in debug mode with a debugger attached).
我面临的问题是,该应用程序没有头,因此没有CoreWindow.GetForCurrentThread().Dispatcher
,也无法从Window.Current
检索调度程序.
The problem that I am facing is, that the application is headless, and therefore there is no CoreWindow.GetForCurrentThread().Dispatcher
, nor could I retrieve the dispatcher from Window.Current
.
即使在发布模式下或未连接调试器的情况下,如何强制在UI-Thread上执行LaunchFileAsync
?
How do I force LaunchFileAsync
to be executed on the UI-Thread even in release mode or without a debugger attached ?
我知道我可以简单地执行以下操作:
I do know that I can simply do the following:
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, (async () =>
{
bool success = await Windows.System.Launcher.LaunchFileAsync(shortcut);
await args.Request.SendResponseAsync(new ValueSet {
{ "message", "Launched File: " + success.ToString() }
});
}));
但是我的问题是要在应用程序类和OnAppServiceRequestReceived
的上下文中获取Dispatcher
引用.
But my problem is getting hold of the Dispatcher
reference within the Application-Class and in the context of OnAppServiceRequestReceived
.
如何实现?甚至有可能还是我需要完全信任的Win32桌面网桥?
How can this be achieved? Is it even possible or do I need a full-trust Win32 desktop bridge?
即使使用
CoreDispatcher dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher;
在没有连接调试器的情况下不起作用.我很好奇,是否可以在没有Win32 Desktop Bridge的无头UWP应用程序中完全调用LaunchFileAsync.
does not work without a Debugger attached. I am curious as to whether calling LaunchFileAsync is possible at all in a head-less UWP app, without a Win32 Desktop Bridge.
推荐答案
您是正确的-您将需要构建完全信任的Win32 Desktop Bridge.分派器未在OnAppServiceRequestReceived
上下文中公开.因此,您将无法启动您想要的任何东西.
You are correct - you will need to build a full-trust Win32 Desktop Bridge. The Dispatcher is not exposed inside the OnAppServiceRequestReceived
context. So you wont be able to launch whatever you intend.
这篇关于边缘:进程内本机扩展和Windows.System.Launcher.LaunchFileAsync的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!