From 83f278b8da883aef8b72d6d634edfcc0d22c9afb Mon Sep 17 00:00:00 2001 From: Omid Mafakher Date: Fri, 11 Aug 2023 12:00:42 +0200 Subject: [PATCH] #6110 resolve comments --- .../Avalonia.Tizen/NuiViewControlHandle.cs | 2 +- .../Avalonia.Tizen/Platform/ScalingInfo.cs | 40 ------------------- .../Avalonia.Tizen/TizenStorageProvider.cs | 39 ++---------------- .../Avalonia.Tizen/TizenThreadingInterface.cs | 4 +- 4 files changed, 7 insertions(+), 78 deletions(-) delete mode 100644 src/Tizen/Avalonia.Tizen/Platform/ScalingInfo.cs diff --git a/src/Tizen/Avalonia.Tizen/NuiViewControlHandle.cs b/src/Tizen/Avalonia.Tizen/NuiViewControlHandle.cs index 93152aa7b13..66aa70ec87e 100644 --- a/src/Tizen/Avalonia.Tizen/NuiViewControlHandle.cs +++ b/src/Tizen/Avalonia.Tizen/NuiViewControlHandle.cs @@ -8,7 +8,7 @@ namespace Avalonia.Tizen; /// public class NuiViewControlHandle : INativeControlHostDestroyableControlHandle { - internal const string ViewDescriptor = nameof(View); + internal const string ViewDescriptor = "NuiView"; /// /// Create handle with native view diff --git a/src/Tizen/Avalonia.Tizen/Platform/ScalingInfo.cs b/src/Tizen/Avalonia.Tizen/Platform/ScalingInfo.cs deleted file mode 100644 index 87ac7cb7649..00000000000 --- a/src/Tizen/Avalonia.Tizen/Platform/ScalingInfo.cs +++ /dev/null @@ -1,40 +0,0 @@ -using Tizen.System; -using ElmSharp; - -namespace Avalonia.Tizen.Platform; -public static class ScalingInfo -{ - private static readonly Lazy profile = new Lazy(() => Elementary.GetProfile()); - - private static readonly Lazy dpi = new Lazy(() => - { - // TV has fixed DPI value (72) - if (Profile == "tv") - return 72; - -#pragma warning disable CS0618 // Type or member is obsolete - SystemInfo.TryGetValue("http://tizen.org/feature/screen.dpi", out int dpi); -#pragma warning restore CS0618 // Type or member is obsolete - return dpi; - }); - - // allows to convert pixels to Android-style device-independent pixels - private static readonly Lazy scalingFactor = new Lazy(() => dpi.Value / 160.0); - - private static double? scalingFactorOverride; - - public static string Profile => profile.Value; - - public static int Dpi => dpi.Value; - - public static double ScalingFactor => scalingFactorOverride ?? scalingFactor.Value; - - public static double FromPixel(double v) => v / ScalingFactor; - - public static double ToPixel(double v) => v * ScalingFactor; - - public static void SetScalingFactor(double? scalingFactor) - { - scalingFactorOverride = scalingFactor; - } -} diff --git a/src/Tizen/Avalonia.Tizen/TizenStorageProvider.cs b/src/Tizen/Avalonia.Tizen/TizenStorageProvider.cs index b0631253cf1..444d896fc87 100644 --- a/src/Tizen/Avalonia.Tizen/TizenStorageProvider.cs +++ b/src/Tizen/Avalonia.Tizen/TizenStorageProvider.cs @@ -71,43 +71,10 @@ public async Task> OpenFilePickerAsync(FilePickerOpe return await tcs.Task; } - public async Task> OpenFolderPickerAsync(FolderPickerOpenOptions options) + public Task> OpenFolderPickerAsync(FolderPickerOpenOptions options) { - Permissions.EnsureDeclared(Permissions.AppManagerLaunchPrivilege); - if (await Permissions.RequestPrivilegeAsync(Permissions.MediaStoragePrivilege) == false) - { - throw new SecurityException("Application doesn't have storage permission."); - } - - var tcs = new TaskCompletionSource>(); - - var appControl = new AppControl - { - Operation = AppControlOperations.Pick, - Mime = "inode/directory" - }; - appControl.ExtraData.Add(AppControlData.SectionMode, options.AllowMultiple ? "multiple" : "single"); - if (options.SuggestedStartLocation?.Path is { } startupPath) - appControl.ExtraData.Add(AppControlData.Path, startupPath.ToString()); - appControl.LaunchMode = AppControlLaunchMode.Single; - - var fileResults = new List(); - - AppControl.SendLaunchRequest(appControl, (_, reply, result) => - { - if (result == AppControlReplyResult.Succeeded) - { - if (reply.ExtraData.Count() > 0) - { - var selectedFiles = reply.ExtraData.Get>(AppControlData.Selected).ToList(); - fileResults.AddRange(selectedFiles.Select(f => new BclStorageFolder(new System.IO.DirectoryInfo(f)))); - } - } - - tcs.TrySetResult(fileResults); - }); - - return await tcs.Task; + return Task.FromException>( + new PlatformNotSupportedException("Open folder is not supported by Tizen")); } public Task OpenFolderBookmarkAsync(string bookmark) diff --git a/src/Tizen/Avalonia.Tizen/TizenThreadingInterface.cs b/src/Tizen/Avalonia.Tizen/TizenThreadingInterface.cs index 5cfbe070d9e..ce62abdccc4 100644 --- a/src/Tizen/Avalonia.Tizen/TizenThreadingInterface.cs +++ b/src/Tizen/Avalonia.Tizen/TizenThreadingInterface.cs @@ -7,7 +7,9 @@ internal class TizenThreadingInterface : IPlatformThreadingInterface internal event Action? TickExecuted; private bool _signaled; +#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. internal static SynchronizationContext MainloopContext { get; set; } +#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. public IDisposable StartTimer(DispatcherPriority priority, TimeSpan interval, Action tick) { @@ -22,7 +24,7 @@ private void EnsureInvokeOnMainThread(Action action) if (SynchronizationContext.Current != null) action(); else - MainloopContext.Post(_ => action(), null); + MainloopContext.Post(static arg => ((Action)arg!).Invoke(), action); } public void Signal(DispatcherPriority prio)