Skip to content

Commit

Permalink
Fix crashing after opening a uri on browser (#17524)
Browse files Browse the repository at this point in the history
* Fix crashing after opening a uri on browser

* Update NavigationHelper.cs
  • Loading branch information
hez2010 authored Nov 19, 2024
1 parent 6728f06 commit 9091d66
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Browser/Avalonia.Browser/Interop/NavigationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static Task<bool> 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);
}
3 changes: 1 addition & 2 deletions src/Browser/Avalonia.Browser/Storage/BrowserLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public Task<bool> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ export class NavigationHelper {
}
};
}

public static openUri(uri?: string, target?: string) {
return !!window.open(uri, target);
}
}

0 comments on commit 9091d66

Please sign in to comment.