Edge: In-Process native extension and Windows.System.Launcher.LaunchFileAsync

≯℡__Kan透↙ 提交于 2019-12-06 16:58:31

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!