From 9091d66e3081dbc8e6ed9c4aabdb3e3bcad95602 Mon Sep 17 00:00:00 2001 From: Steve Date: Tue, 19 Nov 2024 20:36:25 +0900 Subject: [PATCH] Fix crashing after opening a uri on browser (#17524) * Fix crashing after opening a uri on browser * Update NavigationHelper.cs --- src/Browser/Avalonia.Browser/Interop/NavigationHelper.cs | 6 +++--- src/Browser/Avalonia.Browser/Storage/BrowserLauncher.cs | 3 +-- .../webapp/modules/avalonia/navigationHelper.ts | 4 ++++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Browser/Avalonia.Browser/Interop/NavigationHelper.cs b/src/Browser/Avalonia.Browser/Interop/NavigationHelper.cs index d392cc54af0..824ea9e06da 100644 --- a/src/Browser/Avalonia.Browser/Interop/NavigationHelper.cs +++ b/src/Browser/Avalonia.Browser/Interop/NavigationHelper.cs @@ -16,7 +16,7 @@ public static Task OnBackRequested() .OnBackRequested() ?? false; return Task.FromResult(handled); } - - [JSImport("globalThis.open")] - public static partial JSObject? WindowOpen(string uri, string target); + + [JSImport("NavigationHelper.openUri", AvaloniaModule.MainModuleName)] + public static partial bool WindowOpen(string uri, string target); } diff --git a/src/Browser/Avalonia.Browser/Storage/BrowserLauncher.cs b/src/Browser/Avalonia.Browser/Storage/BrowserLauncher.cs index e046a7947da..b875d90bcd0 100644 --- a/src/Browser/Avalonia.Browser/Storage/BrowserLauncher.cs +++ b/src/Browser/Avalonia.Browser/Storage/BrowserLauncher.cs @@ -13,8 +13,7 @@ public Task LaunchUriAsync(Uri uri) if (uri.IsAbsoluteUri) { - var window = NavigationHelper.WindowOpen(uri.AbsoluteUri, "_blank"); - return Task.FromResult(window is not null); + return Task.FromResult(NavigationHelper.WindowOpen(uri.AbsoluteUri, "_blank")); } return Task.FromResult(false); } diff --git a/src/Browser/Avalonia.Browser/webapp/modules/avalonia/navigationHelper.ts b/src/Browser/Avalonia.Browser/webapp/modules/avalonia/navigationHelper.ts index ee594fe85c6..0b844941408 100644 --- a/src/Browser/Avalonia.Browser/webapp/modules/avalonia/navigationHelper.ts +++ b/src/Browser/Avalonia.Browser/webapp/modules/avalonia/navigationHelper.ts @@ -11,4 +11,8 @@ export class NavigationHelper { } }; } + + public static openUri(uri?: string, target?: string) { + return !!window.open(uri, target); + } }