forked from unoplatform/uno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3dada5
commit 0754994
Showing
4 changed files
with
91 additions
and
9 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/Uno.UI.Runtime.Skia.Tizen/Tizen/System/TizenLauncherExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using Tizen.Applications; | ||
using System.Threading.Tasks; | ||
using Uno.System; | ||
using Uno.UI.Runtime.Skia.Tizen.Helpers; | ||
|
||
namespace Uno.UI.Runtime.Skia.Tizen.System | ||
{ | ||
internal class TizenLauncherExtension : ILauncherExtension | ||
{ | ||
public TizenLauncherExtension(object owner) | ||
{ | ||
} | ||
|
||
public Task<bool> LaunchUriAsync(Uri uri) | ||
{ | ||
PrivilegesHelper.EnsureDeclared(Privileges.AppManagerLaunch); | ||
|
||
var appControl = new AppControl | ||
{ | ||
Operation = AppControlOperations.View, | ||
Uri = uri.AbsoluteUri, | ||
}; | ||
|
||
AppControl.SendLaunchRequest(appControl); | ||
|
||
return Task.FromResult(true); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Uno.Extensions.System | ||
{ | ||
internal interface ILauncherExtension | ||
{ | ||
Task<bool> LaunchUriAsync(Uri uri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,57 @@ | ||
using System; | ||
#nullable enable | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using Uno.Extensions; | ||
using Uno.Extensions.System; | ||
using Uno.Foundation.Extensibility; | ||
|
||
namespace Windows.System | ||
{ | ||
public static partial class Launcher | ||
{ | ||
public static Task<bool> LaunchUriPlatformAsync(Uri uri) | ||
private static readonly Lazy<ILauncherExtension?> _launcherExtension = new Lazy<ILauncherExtension?>(() => | ||
{ | ||
var processStartInfo = new ProcessStartInfo(uri.OriginalString) | ||
if (ApiExtensibility.CreateInstance<ILauncherExtension>(typeof(Launcher), out var launcherExtension)) | ||
{ | ||
UseShellExecute = true, | ||
Verb = "open" | ||
}; | ||
return launcherExtension; | ||
} | ||
return null; | ||
}); | ||
|
||
public static async Task<bool> LaunchUriPlatformAsync(Uri uri) | ||
{ | ||
if (_launcherExtension.Value != null) | ||
{ | ||
return await _launcherExtension.Value.LaunchUriAsync(uri); | ||
} | ||
return await LaunchUriFallbackAsync(uri); | ||
} | ||
|
||
var process = new Process(); | ||
process.StartInfo = processStartInfo; | ||
return Task.FromResult(process.Start()); | ||
private static Task<bool> LaunchUriFallbackAsync(Uri uri) | ||
{ | ||
try | ||
{ | ||
var processStartInfo = new ProcessStartInfo(uri.OriginalString) | ||
{ | ||
UseShellExecute = true, | ||
Verb = "open" | ||
}; | ||
|
||
var process = new Process(); | ||
process.StartInfo = processStartInfo; | ||
return Task.FromResult(process.Start()); | ||
} | ||
catch (Exception ex) | ||
{ | ||
if (typeof(Launcher).Log().IsEnabled(LogLevel.Error)) | ||
{ | ||
typeof(Launcher).Log().LogError($"Could not launch URI - {ex}"); | ||
} | ||
return Task.FromResult(false); | ||
} | ||
} | ||
} | ||
} |