-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: DataTransferManager support on Tizen
# Conflicts: # src/Uno.UWP/ApplicationModel/DataTransfer/DataTransferManager.cs # src/Uno.UWP/ApplicationModel/DataTransfer/DataTransferManager.other.cs
- Loading branch information
1 parent
09b4ad0
commit 41d8fc0
Showing
9 changed files
with
126 additions
and
9 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...ntime.Skia.Tizen/Tizen/ApplicationModel/DataTransfer/TizenDataTransferManagerExtension.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,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; | ||
} | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/Uno.UI.Runtime.Skia.Tizen/Tizen/Helpers/PrivilegeHelper.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,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); | ||
} | ||
} | ||
} |
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
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
2 changes: 1 addition & 1 deletion
2
src/Uno.UWP/ApplicationModel/DataTransfer/DataTransferManager.other.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
33 changes: 33 additions & 0 deletions
33
src/Uno.UWP/ApplicationModel/DataTransfer/DataTransferManager.skia.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,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; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Uno.UWP/ApplicationModel/DataTransfer/IDataTransferManagerExtension.skia.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,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); | ||
} | ||
} |