Skip to content

Commit

Permalink
feat: DataTransferManager support on Tizen
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Uno.UWP/ApplicationModel/DataTransfer/DataTransferManager.cs
#	src/Uno.UWP/ApplicationModel/DataTransfer/DataTransferManager.other.cs
  • Loading branch information
MartinZikmund committed Jan 29, 2021
1 parent 09b4ad0 commit 41d8fc0
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Tizen.Applications;
using Uno.ApplicationModel.DataTransfer;
using Uno.Extensions;
using Uno.UI.Runtime.Skia.Tizen.Helpers;
using Windows.ApplicationModel.DataTransfer;

namespace Uno.UI.Runtime.Skia.Tizen.ApplicationModel.DataTransfer
{
public class TizenDataTransferManagerExtension : IDataTransferManagerExtension
{
private const string LaunchAppPrivilege = "http://tizen.org/privilege/appmanager.launch";

public TizenDataTransferManagerExtension(object owner)
{
}

public bool IsSupported() => true;

public async Task<bool> ShowShareUIAsync(ShareUIOptions options, DataPackage dataPackage)
{
if (!PrivilegeHelper.IsDeclared(LaunchAppPrivilege))
{
if (this.Log().IsEnabled(LogLevel.Error))
{
this.Log().LogError($"The Launch app privilege must be declared ({LaunchAppPrivilege})");
}
return false;
}

var appControl = new AppControl
{
Operation = AppControlOperations.ShareText,
};

var dataPackageView = dataPackage.GetView();

if (dataPackageView.Contains(StandardDataFormats.Text))
{
var text = await dataPackageView.GetTextAsync();
appControl.ExtraData.Add(AppControlData.Text, text);
}

var uri = await DataTransferManager.GetSharedUriAsync(dataPackageView);
if (uri != null)
{
appControl.ExtraData.Add(AppControlData.Url, uri.ToString());
}

AppControl.SendLaunchRequest(appControl);

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using Tizen.Applications;
using Uno.Extensions.Specialized;
using Uno.UI.Runtime.Skia.Tizen.Helpers;

namespace Uno.UI.Runtime.Skia.Tizen.Devices.Haptics
{
Expand All @@ -19,10 +20,7 @@ public VibrationAccessStatus AccessStatus
{
get
{
var packageId = Application.Current.ApplicationInfo.PackageId;
var package = PackageManager.GetPackage(packageId);

if (package.Privileges.Any(p=> p == TizenPrivilege))
if (PrivilegeHelper.IsDeclared(TizenPrivilege))
{
return VibrationAccessStatus.Allowed;
}
Expand Down
16 changes: 16 additions & 0 deletions src/Uno.UI.Runtime.Skia.Tizen/Tizen/Helpers/PrivilegeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Linq;
using Tizen.Applications;

namespace Uno.UI.Runtime.Skia.Tizen.Helpers
{
internal static class PrivilegeHelper
{
public static bool IsDeclared(string privilege)
{
var packageId = Application.Current.ApplicationInfo.PackageId;
var package = PackageManager.GetPackage(packageId);

return package.Privileges.Any(p => p == privilege);
}
}
}
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 @@ -23,6 +23,8 @@
using Windows.ApplicationModel;
using Uno.UI.Runtime.Skia.Tizen.ApplicationModel;
using Uno.ApplicationModel;
using Uno.ApplicationModel.DataTransfer;
using Uno.UI.Runtime.Skia.Tizen.ApplicationModel.DataTransfer;

namespace Uno.UI.Runtime.Skia
{
Expand Down Expand Up @@ -76,6 +78,7 @@ public void Run()
ApiExtensibility.Register(typeof(ISimpleHapticsControllerExtension), o => new TizenSimpleHapticsControllerExtension(o));
ApiExtensibility.Register(typeof(IAnalyticsInfoExtension), o => new TizenAnalyticsInfoExtension(o));
ApiExtensibility.Register(typeof(IPackageIdExtension), o => new TizenPackageIdExtension(o));
ApiExtensibility.Register(typeof(IDataTransferManagerExtension), o => new TizenDataTransferManagerExtension(o));

void CreateApp(ApplicationInitializationCallbackParams _)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#nullable enable

#if __WASM__ || __IOS__ || __ANDROID__ || __SKIA__ || __MACOS__
#if __WASM__ || __IOS__ || __ANDROID__ || __MACOS__ || __SKIA__
using System;
using Windows.Foundation;
using Uno.Logging;
Expand Down Expand Up @@ -55,7 +55,7 @@ public static async void ShowShareUI(ShareUIOptions options)
}
}

private static async Task<Uri?> GetSharedUriAsync(DataPackageView view)
internal static async Task<Uri?> GetSharedUriAsync(DataPackageView view)
{
if (view.Contains(StandardDataFormats.Uri))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ private static async Task<bool> ShowShareUIAsync(ShareUIOptions options, DataPac

var sharedData = new List<NSObject>();

var title = dataPackage.Properties.Title ?? string.Empty;

if (dataPackageView.Contains(StandardDataFormats.Text))
{
var text = await dataPackageView.GetTextAsync();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !__WASM__ && !__IOS__ && !__ANDROID__ && !__SKIA__ && !__MACOS__
#if !__WASM__ && !__IOS__ && !__ANDROID__ && !__MACOS__ && !__SKIA__

namespace Windows.ApplicationModel.DataTransfer
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#nullable enable

using System;
using System.Threading.Tasks;
using Uno.ApplicationModel.DataTransfer;
using Uno.Foundation.Extensibility;

namespace Windows.ApplicationModel.DataTransfer
{
public partial class DataTransferManager
{
private static readonly Lazy<IDataTransferManagerExtension?> _dataTransferManagerExtension = new Lazy<IDataTransferManagerExtension?>(() =>
{
if (ApiExtensibility.CreateInstance(typeof(DataTransferManager), out IDataTransferManagerExtension dataTransferManagerExtension))
{
return dataTransferManagerExtension;
}
return null;
});

public static bool IsSupported() => _dataTransferManagerExtension.Value?.IsSupported() == true;

private static async Task<bool> ShowShareUIAsync(ShareUIOptions options, DataPackage dataPackage)
{
var extension = _dataTransferManagerExtension.Value;
if(extension != null)
{
return await extension.ShowShareUIAsync(options, dataPackage);
}
return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;
using Windows.ApplicationModel.DataTransfer;

namespace Uno.ApplicationModel.DataTransfer
{
internal interface IDataTransferManagerExtension
{
bool IsSupported();

Task<bool> ShowShareUIAsync(ShareUIOptions options, DataPackage dataPackage);
}
}

0 comments on commit 41d8fc0

Please sign in to comment.