2024-04-18 01:44:37 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using Windows.ApplicationModel;
|
|
|
|
|
|
using Windows.Foundation.Metadata;
|
|
|
|
|
|
using Windows.Storage;
|
|
|
|
|
|
using Windows.System;
|
|
|
|
|
|
using Windows.UI.Shell;
|
|
|
|
|
|
using Wino.Core.Domain.Interfaces;
|
2024-08-05 00:36:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if WINDOWS_UWP
|
|
|
|
|
|
using Windows.UI.Xaml;
|
|
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
|
#endif
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
namespace Wino.Services;
|
|
|
|
|
|
|
|
|
|
|
|
public class NativeAppService : INativeAppService
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
private string _mimeMessagesFolder;
|
|
|
|
|
|
private string _editorBundlePath;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public Func<IntPtr> GetCoreWindowHwnd { get; set; }
|
2024-08-05 00:36:26 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public string GetWebAuthenticationBrokerUri()
|
|
|
|
|
|
{
|
2024-08-05 00:36:26 +02:00
|
|
|
|
#if WINDOWS_UWP
|
2025-02-16 11:54:23 +01:00
|
|
|
|
return WebAuthenticationBroker.GetCurrentApplicationCallbackUri().AbsoluteUri;
|
2024-08-05 00:36:26 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
return string.Empty;
|
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public async Task<string> GetMimeMessageStoragePath()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_mimeMessagesFolder))
|
|
|
|
|
|
return _mimeMessagesFolder;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
var localFolder = ApplicationData.Current.LocalFolder;
|
|
|
|
|
|
var mimeFolder = await localFolder.CreateFolderAsync("Mime", CreationCollisionOption.OpenIfExists);
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
_mimeMessagesFolder = mimeFolder.Path;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
return _mimeMessagesFolder;
|
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public async Task<string> GetEditorBundlePathAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(_editorBundlePath))
|
2024-04-18 01:44:37 +02:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
var editorFileFromBundle = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///JS/editor.html"))
|
|
|
|
|
|
.AsTask()
|
|
|
|
|
|
.ConfigureAwait(false);
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
_editorBundlePath = editorFileFromBundle.Path;
|
2025-02-16 11:43:30 +01:00
|
|
|
|
}
|
2025-02-16 11:35:43 +01:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
return _editorBundlePath;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Obsolete("This should be removed. There should be no functionality.")]
|
|
|
|
|
|
public bool IsAppRunning()
|
|
|
|
|
|
{
|
2024-08-05 00:36:26 +02:00
|
|
|
|
#if WINDOWS_UWP
|
2025-02-16 11:54:23 +01:00
|
|
|
|
return (Window.Current?.Content as Frame)?.Content != null;
|
2024-08-05 00:36:26 +02:00
|
|
|
|
#endif
|
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2024-08-05 00:36:26 +02:00
|
|
|
|
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public async Task LaunchFileAsync(string filePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
var file = await StorageFile.GetFileFromPathAsync(filePath);
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
await Launcher.LaunchFileAsync(file);
|
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public Task<bool> LaunchUriAsync(Uri uri) => Launcher.LaunchUriAsync(uri).AsTask();
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public string GetFullAppVersion()
|
|
|
|
|
|
{
|
|
|
|
|
|
Package package = Package.Current;
|
|
|
|
|
|
PackageId packageId = package.Id;
|
|
|
|
|
|
PackageVersion version = packageId.Version;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
return string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);
|
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public async Task PinAppToTaskbarAsync()
|
|
|
|
|
|
{
|
|
|
|
|
|
// If Start screen manager API's aren't present
|
|
|
|
|
|
if (!ApiInformation.IsTypePresent("Windows.UI.Shell.TaskbarManager")) return;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
// Get the taskbar manager
|
|
|
|
|
|
var taskbarManager = TaskbarManager.GetDefault();
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
// If Taskbar doesn't allow pinning, don't show the tip
|
|
|
|
|
|
if (!taskbarManager.IsPinningAllowed) return;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
// If already pinned, don't show the tip
|
|
|
|
|
|
if (await taskbarManager.IsCurrentAppPinnedAsync()) return;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
await taskbarManager.RequestPinCurrentAppAsync();
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|