Skip to content

Commit

Permalink
feat: Launcher support on Tizen
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Feb 9, 2021
1 parent a3dada5 commit 0754994
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 9 deletions.
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);
}
}
}
3 changes: 3 additions & 0 deletions src/Uno.UI.Runtime.Skia.Tizen/Tizen/TizenHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
using Uno.UI.Runtime.Skia.Tizen.ApplicationModel.Contacts;
using Uno.ApplicationModel.DataTransfer;
using Uno.UI.Runtime.Skia.Tizen.ApplicationModel.DataTransfer;
using Uno.UI.Runtime.Skia.Tizen.System;
using Uno.Extensions.System;

namespace Uno.UI.Runtime.Skia
{
Expand Down Expand Up @@ -82,6 +84,7 @@ public void Run()
ApiExtensibility.Register(typeof(IPackageIdExtension), o => new TizenPackageIdExtension(o));
ApiExtensibility.Register(typeof(IDataTransferManagerExtension), o => new TizenDataTransferManagerExtension(o));
ApiExtensibility.Register(typeof(IContactPickerExtension), o => new TizenContactPickerExtension(o));
ApiExtensibility.Register(typeof(ILauncherExtension), o => new TizenLauncherExtension(o));

void CreateApp(ApplicationInitializationCallbackParams _)
{
Expand Down
12 changes: 12 additions & 0 deletions src/Uno.UWP/System/ILauncherExtension.skia.cs
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);
}
}
53 changes: 44 additions & 9 deletions src/Uno.UWP/System/Launcher.Skia.cs
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);
}
}
}
}

0 comments on commit 0754994

Please sign in to comment.