Skip to content

Commit 0754994

Browse files
committed
feat: Launcher support on Tizen
1 parent a3dada5 commit 0754994

File tree

4 files changed

+91
-9
lines changed

4 files changed

+91
-9
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#nullable enable
2+
3+
using System;
4+
using Tizen.Applications;
5+
using System.Threading.Tasks;
6+
using Uno.System;
7+
using Uno.UI.Runtime.Skia.Tizen.Helpers;
8+
9+
namespace Uno.UI.Runtime.Skia.Tizen.System
10+
{
11+
internal class TizenLauncherExtension : ILauncherExtension
12+
{
13+
public TizenLauncherExtension(object owner)
14+
{
15+
}
16+
17+
public Task<bool> LaunchUriAsync(Uri uri)
18+
{
19+
PrivilegesHelper.EnsureDeclared(Privileges.AppManagerLaunch);
20+
21+
var appControl = new AppControl
22+
{
23+
Operation = AppControlOperations.View,
24+
Uri = uri.AbsoluteUri,
25+
};
26+
27+
AppControl.SendLaunchRequest(appControl);
28+
29+
return Task.FromResult(true);
30+
}
31+
}
32+
}

src/Uno.UI.Runtime.Skia.Tizen/Tizen/TizenHost.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
using Uno.UI.Runtime.Skia.Tizen.ApplicationModel.Contacts;
2828
using Uno.ApplicationModel.DataTransfer;
2929
using Uno.UI.Runtime.Skia.Tizen.ApplicationModel.DataTransfer;
30+
using Uno.UI.Runtime.Skia.Tizen.System;
31+
using Uno.Extensions.System;
3032

3133
namespace Uno.UI.Runtime.Skia
3234
{
@@ -82,6 +84,7 @@ public void Run()
8284
ApiExtensibility.Register(typeof(IPackageIdExtension), o => new TizenPackageIdExtension(o));
8385
ApiExtensibility.Register(typeof(IDataTransferManagerExtension), o => new TizenDataTransferManagerExtension(o));
8486
ApiExtensibility.Register(typeof(IContactPickerExtension), o => new TizenContactPickerExtension(o));
87+
ApiExtensibility.Register(typeof(ILauncherExtension), o => new TizenLauncherExtension(o));
8588

8689
void CreateApp(ApplicationInitializationCallbackParams _)
8790
{
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#nullable enable
2+
3+
using System;
4+
using System.Threading.Tasks;
5+
6+
namespace Uno.Extensions.System
7+
{
8+
internal interface ILauncherExtension
9+
{
10+
Task<bool> LaunchUriAsync(Uri uri);
11+
}
12+
}

src/Uno.UWP/System/Launcher.Skia.cs

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,57 @@
1-
using System;
1+
#nullable enable
2+
3+
using System;
24
using System.Diagnostics;
35
using System.Threading.Tasks;
6+
using Microsoft.Extensions.Logging;
7+
using Uno.Extensions;
8+
using Uno.Extensions.System;
9+
using Uno.Foundation.Extensibility;
410

511
namespace Windows.System
612
{
713
public static partial class Launcher
814
{
9-
public static Task<bool> LaunchUriPlatformAsync(Uri uri)
15+
private static readonly Lazy<ILauncherExtension?> _launcherExtension = new Lazy<ILauncherExtension?>(() =>
1016
{
11-
var processStartInfo = new ProcessStartInfo(uri.OriginalString)
17+
if (ApiExtensibility.CreateInstance<ILauncherExtension>(typeof(Launcher), out var launcherExtension))
1218
{
13-
UseShellExecute = true,
14-
Verb = "open"
15-
};
19+
return launcherExtension;
20+
}
21+
return null;
22+
});
23+
24+
public static async Task<bool> LaunchUriPlatformAsync(Uri uri)
25+
{
26+
if (_launcherExtension.Value != null)
27+
{
28+
return await _launcherExtension.Value.LaunchUriAsync(uri);
29+
}
30+
return await LaunchUriFallbackAsync(uri);
31+
}
1632

17-
var process = new Process();
18-
process.StartInfo = processStartInfo;
19-
return Task.FromResult(process.Start());
33+
private static Task<bool> LaunchUriFallbackAsync(Uri uri)
34+
{
35+
try
36+
{
37+
var processStartInfo = new ProcessStartInfo(uri.OriginalString)
38+
{
39+
UseShellExecute = true,
40+
Verb = "open"
41+
};
42+
43+
var process = new Process();
44+
process.StartInfo = processStartInfo;
45+
return Task.FromResult(process.Start());
46+
}
47+
catch (Exception ex)
48+
{
49+
if (typeof(Launcher).Log().IsEnabled(LogLevel.Error))
50+
{
51+
typeof(Launcher).Log().LogError($"Could not launch URI - {ex}");
52+
}
53+
return Task.FromResult(false);
54+
}
2055
}
2156
}
2257
}

0 commit comments

Comments
 (0)