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).
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
.
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() }
});
}));
But my problem is getting hold of the Dispatcher
reference within the Application-Class and in the context of OnAppServiceRequestReceived
.
How can this be achieved? Is it even possible or do I need a full-trust Win32 desktop bridge?
Even using
CoreDispatcher dispatcher = Windows.ApplicationModel.Core.CoreApplication.MainView.Dispatcher;
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.
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.
来源:https://stackoverflow.com/questions/48079220/edge-in-process-native-extension-and-windows-system-launcher-launchfileasync