Activation service

This commit is contained in:
2024-03-14 16:31:26 +01:00
Unverified
parent fa71543773
commit c9d81fe966
26 changed files with 356 additions and 154 deletions

View File

@@ -6,22 +6,13 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using VDownload.Services.Common;
using VDownload.Services.UI.StringResources;
namespace VDownload.Services.UI.Dialogs
{
public interface IDialogsService
public interface IDialogsService : IInitializableService<XamlRoot>
{
#region PROPERTIES
XamlRoot DefaultRoot { get; set; }
#endregion
#region METHODS
Task ShowClose(string title, string message);
Task<DialogResult> ShowDouble(string title, string message, string primaryButtonText, string secondaryButtonText);
Task ShowOk(string title, string message);
@@ -30,8 +21,6 @@ namespace VDownload.Services.UI.Dialogs
Task<DialogResult> ShowTriple(string title, string message, string primaryButtonText, string secondaryButtonText, string cancelButtonText);
Task<DialogResultYesNo> ShowYesNo(string title, string message);
Task<DialogResultYesNoCancel> ShowYesNoCancel(string title, string message);
#endregion
}
@@ -54,13 +43,7 @@ namespace VDownload.Services.UI.Dialogs
protected string _yesString;
protected string _noString;
#endregion
#region PROPERTIES
public XamlRoot DefaultRoot { get; set; }
protected XamlRoot _root;
#endregion
@@ -84,6 +67,8 @@ namespace VDownload.Services.UI.Dialogs
#region PUBLIC METHODS
public async Task Initialize(XamlRoot arg) => await Task.Run(() => _root = arg);
public async Task ShowOk(string title, string message) => await ShowSingle(title, message, _okString);
public async Task ShowClose(string title, string message) => await ShowSingle(title, message, _closeString);
public async Task ShowSingle(string title, string message, string buttonText)
@@ -138,7 +123,7 @@ namespace VDownload.Services.UI.Dialogs
{
Title = title,
Content = message,
XamlRoot = DefaultRoot
XamlRoot = _root
};
}

View File

@@ -15,6 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VDownload.Services.Common\VDownload.Services.Common.csproj" />
<ProjectReference Include="..\VDownload.Services.UI.StringResources\VDownload.Services.UI.StringResources.csproj" />
</ItemGroup>
</Project>

View File

@@ -4,12 +4,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Services.Common;
using Windows.Media.Core;
namespace VDownload.Services.UI.DictionaryResources
{
public interface IDictionaryResourcesService
public interface IDictionaryResourcesService : IInitializableService<ResourceDictionary>
{
ResourceDictionary Resources { get; set; }
T Get<T>(string key);
}
@@ -17,17 +18,9 @@ namespace VDownload.Services.UI.DictionaryResources
public class DictionaryResourcesService : IDictionaryResourcesService
{
#region PROPERTIES
#region FIELDS
public ResourceDictionary Resources { get; set; }
#endregion
#region CONSTRUCTORS
public DictionaryResourcesService() { }
protected ResourceDictionary _resources;
#endregion
@@ -35,9 +28,11 @@ namespace VDownload.Services.UI.DictionaryResources
#region PUBLIC METHODS
public async Task Initialize(ResourceDictionary arg) => await Task.Run(() => _resources = arg);
public T Get<T>(string key)
{
Resources.TryGetValue(key, out object value);
_resources.TryGetValue(key, out object value);
if (value is not null && value is T cast)
{
return cast;

View File

@@ -15,6 +15,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VDownload.Services.Common\VDownload.Services.Common.csproj" />
<ProjectReference Include="..\VDownload.Services.UI.Notifications\VDownload.Services.UI.Notifications.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,17 +1,19 @@
using Microsoft.Toolkit.Uwp.Notifications;
using Microsoft.UI.Xaml;
using Microsoft.Windows.AppNotifications;
using Microsoft.Windows.AppNotifications.Builder;
using SimpleToolkit.UI.WinUI.Helpers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VDownload.Services.Common;
namespace VDownload.Services.UI.Notifications
{
public interface INotificationsService
public interface INotificationsService : IInitializableService<Window>
{
void Initialize(Action notificationInvoked);
void SendNotification(string title, IEnumerable<string> message);
}
@@ -19,7 +21,15 @@ namespace VDownload.Services.UI.Notifications
public class NotificationsService : INotificationsService
{
#region CONSTRCUTORS
#region FIELDS
protected Window _window;
#endregion
#region CONSTRUCTORS
~NotificationsService()
{
@@ -32,12 +42,14 @@ namespace VDownload.Services.UI.Notifications
#region PUBLIC METHODS
public void Initialize(Action notificationInvoked)
public async Task Initialize(Window window) => await Task.Run(() =>
{
AppNotificationManager.Default.NotificationInvoked += (obj, args) => notificationInvoked.Invoke();
_window = window;
AppNotificationManager.Default.NotificationInvoked += NotificationInvoked;
AppNotificationManager.Default.Register();
}
});
public void SendNotification(string title, IEnumerable<string> message)
{
@@ -54,5 +66,13 @@ namespace VDownload.Services.UI.Notifications
}
#endregion
#region PRIVATE METHODS
private void NotificationInvoked(AppNotificationManager sender, AppNotificationActivatedEventArgs args) => WindowHelper.ShowWindow(_window);
#endregion
}
}

View File

@@ -13,5 +13,10 @@
<PackageReference Include="Microsoft.Toolkit.Uwp.Notifications" Version="7.1.3" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
<PackageReference Include="SimpleToolkit.UI.WinUI.Helpers" Version="1.7.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VDownload.Services.Common\VDownload.Services.Common.csproj" />
</ItemGroup>
</Project>

View File

@@ -3,24 +3,15 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using VDownload.Services.Common;
using Windows.Storage;
using Windows.Storage.Pickers;
using WinRT.Interop;
namespace VDownload.Services.UI.StoragePicker
{
public interface IStoragePickerService
public interface IStoragePickerService : IInitializableService<Window>
{
#region PROPERTIES
Window DefaultRoot { get; set; }
#endregion
#region METHODS
Task<string?> OpenDirectory();
Task<string?> OpenDirectory(StoragePickerStartLocation startLocation);
Task<IEnumerable<string>> OpenMultipleFiles();
@@ -33,17 +24,15 @@ namespace VDownload.Services.UI.StoragePicker
Task<string?> OpenSingleFile(string[] fileTypes, StoragePickerStartLocation startLocation);
Task<string?> SaveFile(FileSavePickerFileTypeChoice[] fileTypes, string defaultFileType);
Task<string?> SaveFile(FileSavePickerFileTypeChoice[] fileTypes, string defaultFileType, StoragePickerStartLocation startLocation);
#endregion
}
public class StoragePickerService : IStoragePickerService
{
#region PROPERTIES
#region FIELDS
public Window DefaultRoot { get; set; }
protected Window _root;
#endregion
@@ -51,6 +40,8 @@ namespace VDownload.Services.UI.StoragePicker
#region PUBLIC METHODS
public async Task Initialize(Window arg) => await Task.Run(() => _root = arg);
public async Task<string?> OpenDirectory() => await OpenDirectory(StoragePickerStartLocation.Unspecified);
public async Task<string?> OpenDirectory(StoragePickerStartLocation startLocation)
{
@@ -111,7 +102,7 @@ namespace VDownload.Services.UI.StoragePicker
protected void InitializePicker(object picker)
{
var hwnd = WindowNative.GetWindowHandle(DefaultRoot);
var hwnd = WindowNative.GetWindowHandle(_root);
InitializeWithWindow.Initialize(picker, hwnd);
}

View File

@@ -13,4 +13,8 @@
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240227000" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.3233" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\VDownload.Services.Common\VDownload.Services.Common.csproj" />
</ItemGroup>
</Project>