-
Notifications
You must be signed in to change notification settings - Fork 770
Description
Describe the bug
Please remove the security check for LauncherOptions
or add a pop-up for the IinitializeWithWindow
interop implementation
------------------------------------
请为 LauncherOptions
移除安全检查或添加弹窗 IinitializeWithWindow
互操作实现
The problem is the above problem 10428,2357, 4438 Detailed investigation and provision of specific solutions
------------------------------------
该问题为上述这些问题 10428,2357,4438的详细调查和提供的具体的解决方案
通过调查发现,WinUI 3
桌面模式下的 HyperlinkButton
,Hyperlink
这两个类中包含一个 NavigateUri
属性,通过设置 NavigateUri
属性可以在点击按钮时快速打开对应的链接。但在实际操作中发现,该属性有时会失效。查看源代码发现,WinUI 3
的 LauncherOptions
缺少与 IInitializeWithWindow
(桌面窗口句柄)的互操作,所以在设置 TreatAsUntrusted
属性后,才会导致安全检查窗口弹出失败。
所以希望能完善 LauncherOptions
与桌面窗口的互操作,但这个互操作会在管理员模式下失败,所以最好的解决方法就是不要进行链接安全检查,直接将 TreatAsUntrusted
设置为 false
是最佳解决方案。
------------------------------------
Through the investigation, it is found that the HyperlinkButton
and Hyperlink
classes in WinUI 3
desktop mode contain a NavigateUri
attribute, which can be set to quickly open the corresponding link when the button is clicked. However, in practice, it was found that this property sometimes fails. Looking at the source code, it was found that WinUI 3
's LauncherOptions
lacked interoperability with IInitializeWithWindow
(desktop window handle), so setting the TreatAsUntrusted
property would cause the security check window to pop up and fail.
So hopefully improve the interop between LauncherOptions
and the desktop window, but this interop will fail in administrator mode, so the best solution is to avoid link security checks and simply set TreatAsUntrusted
to false
is the best solution.
Winui 3
桌面模式通过 IInitializeWithWindow
互操作显示链接安全检查弹窗
------------------------------------
Winui 3 desktop mode displays a link security check pop-up via IInitializeWithWindow interop
链接安全检查弹窗(Link security check pop-up)
代码实现(Code implementation)
LauncherOptions launcherOptions = new LauncherOptions()
{
TreatAsUntrusted = true,
};
WinRT.Interop.InitializeWithWindow.Initialize(launcherOptions, (IntPtr)AppWindow.Id.Value);
await Launcher.LaunchUriAsync(new Uri("https://www.bing.com"), launcherOptions);
参考链接(Reference link)
HyperlinkButton:https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.hyperlinkbutton?view=windows-app-sdk-1.6
Hyperlink:https://learn.microsoft.com/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.documents.hyperlink?view=windows-app-sdk-1.6
NavigateUri in HyperlinkButton:https://learn.microsoft.com/zh-cn/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.hyperlinkbutton.navigateuri?view=windows-app-sdk-1.6#microsoft-ui-xaml-controls-hyperlinkbutton-navigateuri
NavigateUri in Hyperlink:https://learn.microsoft.com/zh-cn/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.documents.hyperlink.navigateuri?view=windows-app-sdk-1.6#microsoft-ui-xaml-documents-hyperlink-navigateuri
LauncherOptions need InitializeWithWindow in desktop mode:https://learn.microsoft.com/zh-cn/windows/apps/develop/ui-input/display-ui-objects
https://learn.microsoft.com/zh-cn/uwp/api/windows.system.launcheroptions?view=winrt-26100
问题代码位置(The location of the problem code)
IFC_RETURN(Launcher::TryInvokeLauncher(spNavigateUri.Get())); |
IFC(spLauncherOptions->put_TreatAsUntrusted(true)); |
Steps to reproduce the bug
1.创建一个新 WinUI 3
项目
2.打开 MainWindow.xaml.cs
3.在 myButton_Click
中添加如下代码实现
------------------------------------
- Create a new
WinUI 3
project - Open the
MainWindow.xaml.cs
- Add the following code to
myButton_Click
LauncherOptions launcherOptions = new LauncherOptions()
{
TreatAsUntrusted = true,
};
WinRT.Interop.InitializeWithWindow.Initialize(launcherOptions, /// 主窗口/顶级窗口句柄(Main window/top-level window handle)///);
await Launcher.LaunchUriAsync(new Uri("https://www.bing.com"), launcherOptions);
Expected behavior
完善 LauncherOptions
与桌面窗口的互操作,但这个互操作会在管理员模式下失败,所以最好的解决方法就是不要进行链接安全检查,直接将 TreatAsUntrusted
设置为 false
是最佳解决方案。
------------------------------------
Improve the interop between LauncherOptions
and the desktop window, but this interop will fail in administrator mode, so the best solution is to avoid link security checks and simply set TreatAsUntrusted
to false
is the best solution.
Screenshots
链接安全检查弹窗(Link security check pop-up)
NuGet package version
WinUI 3 - Windows App SDK 1.7.0: 1.7.250310001(存在于所有版本中(Present in all versions))
Windows version
Windows 11 (24H2): Build 26100(Windows 10 18362 以后的所有系统版本中(Windows 10 18362 and later in all system versions))
Additional context
Test code
App1.zip