Skip to content

Commit

Permalink
Merge pull request unoplatform#15558 from ajpinedam/fix/ios.launchurl
Browse files Browse the repository at this point in the history
fix(catalyst): Launcher.LaunchUriAsync from not UI thread
  • Loading branch information
jeromelaban authored Feb 21, 2024
2 parents afb7ad9 + 7dbaebc commit 1feb6a2
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/Uno.UWP/System/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ public static IAsyncOperation<bool> LaunchUriAsync(Uri uri)
}

#if !__WASM__
if (!CoreDispatcher.Main.HasThreadAccess)
if (CoreDispatcher.Main.HasThreadAccess)
{
if (typeof(Launcher).Log().IsEnabled(LogLevel.Error))
{
typeof(Launcher).Log().Error($"{nameof(LaunchUriAsync)} must be called on the UI thread");
}
// LaunchUriAsync throws the following exception if used on UI thread on UWP
throw new InvalidOperationException($"{nameof(LaunchUriAsync)} must be called on the UI thread");
return LaunchUriPlatformAsync(uri).AsAsyncOperation();
}
else
{
return CoreDispatcher.Main.RunWithResultAsync(
priority: CoreDispatcherPriority.Normal,
task: async () => await LaunchUriPlatformAsync(uri)
).AsAsyncOperation();
}
#else
return LaunchUriPlatformAsync(uri).AsAsyncOperation();
#endif

return LaunchUriPlatformAsync(uri).AsAsyncOperation();
#else
if (typeof(Launcher).Log().IsEnabled(LogLevel.Error))
{
Expand Down

0 comments on commit 1feb6a2

Please sign in to comment.