Files
Wino-Mail/Wino.Core.WinUI/Services/NativeAppService.cs
T

107 lines
2.9 KiB
C#
Raw Normal View History

2024-04-18 01:44:37 +02:00
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel;
using Windows.Storage;
using Windows.System;
using Wino.Core.Domain.Interfaces;
#if WINDOWS_UWP
2025-09-29 11:16:14 +02:00
using Microsoft.UI.Xaml;
using Microsoft.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; }
2025-02-16 11:54:23 +01:00
public string GetWebAuthenticationBrokerUri()
{
#if WINDOWS_UWP
2025-02-16 11:54:23 +01:00
return WebAuthenticationBroker.GetCurrentApplicationCallbackUri().AbsoluteUri;
#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()
{
#if WINDOWS_UWP
2025-02-16 11:54:23 +01:00
return (Window.Current?.Content as Frame)?.Content != null;
#endif
2025-02-16 11:54:23 +01:00
return true;
}
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-10-06 17:46:00 +02:00
[Obsolete("Not supported for Win SDK")]
2025-02-16 11:54:23 +01:00
public async Task PinAppToTaskbarAsync()
{
// If Start screen manager API's aren't present
2025-10-06 17:46:00 +02:00
//if (!ApiInformation.IsTypePresent("Windows.UI.Shell.TaskbarManager")) return;
2024-04-18 01:44:37 +02:00
2025-10-06 17:46:00 +02:00
//// Get the taskbar manager
//var taskbarManager = TaskbarManager.GetDefault();
2024-04-18 01:44:37 +02:00
2025-10-06 17:46:00 +02: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-10-06 17:46:00 +02:00
//// If already pinned, don't show the tip
//if (await taskbarManager.IsCurrentAppPinnedAsync()) return;
2024-04-18 01:44:37 +02:00
2025-10-06 17:46:00 +02:00
//await taskbarManager.RequestPinCurrentAppAsync();
2024-04-18 01:44:37 +02:00
}
}