Activation service
This commit is contained in:
@@ -31,13 +31,7 @@ namespace VDownload.Core.Views
|
||||
{ typeof(AuthenticationViewModel), typeof(AuthenticationView) }
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PROPERTIES
|
||||
|
||||
public static IServiceProvider ServiceProvider { protected get; set; }
|
||||
protected static IServiceProvider _serviceProvider;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -45,6 +39,8 @@ namespace VDownload.Core.Views
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public static void Initialize(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, string language)
|
||||
{
|
||||
if (value is null)
|
||||
@@ -53,11 +49,11 @@ namespace VDownload.Core.Views
|
||||
}
|
||||
if (value is Type type && _viewModelViewBinding.ContainsKey(type))
|
||||
{
|
||||
return ServiceProvider.GetService(_viewModelViewBinding[type]);
|
||||
return _serviceProvider.GetService(_viewModelViewBinding[type]);
|
||||
}
|
||||
if (_viewModelViewBinding.ContainsKey(value.GetType()))
|
||||
{
|
||||
return ServiceProvider.GetService(_viewModelViewBinding[value.GetType()]);
|
||||
return _serviceProvider.GetService(_viewModelViewBinding[value.GetType()]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VDownload.Services.Common
|
||||
{
|
||||
public interface IInitializableService
|
||||
{
|
||||
#region METHODS
|
||||
|
||||
Task Initialize();
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public interface IInitializableService<T>
|
||||
{
|
||||
#region METHODS
|
||||
|
||||
Task Initialize(T arg);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -4,11 +4,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Services.Common;
|
||||
using VDownload.Services.Data.Configuration;
|
||||
|
||||
namespace VDownload.Services.Data.Application
|
||||
{
|
||||
public interface IApplicationDataService
|
||||
public interface IApplicationDataService : IInitializableService
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
@@ -73,6 +74,8 @@ namespace VDownload.Services.Data.Application
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public async Task Initialize() => await Load();
|
||||
|
||||
public async Task Load()
|
||||
{
|
||||
if (File.Exists(_filePath))
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\VDownload.Services.Common\VDownload.Services.Common.csproj" />
|
||||
<ProjectReference Include="..\VDownload.Services.Data.Configuration\VDownload.Services.Data.Configuration.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Services.Common;
|
||||
using VDownload.Services.Data.Configuration;
|
||||
|
||||
namespace VDownload.Services.Data.Authentication
|
||||
{
|
||||
public interface IAuthenticationDataService
|
||||
public interface IAuthenticationDataService : IInitializableService
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
@@ -70,6 +71,8 @@ namespace VDownload.Services.Data.Authentication
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public async Task Initialize() => await Load();
|
||||
|
||||
public async Task Load()
|
||||
{
|
||||
Data = null;
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\VDownload.Services.Common\VDownload.Services.Common.csproj" />
|
||||
<ProjectReference Include="..\VDownload.Services.Data.Configuration\VDownload.Services.Data.Configuration.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -4,11 +4,12 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Services.Common;
|
||||
using VDownload.Services.Data.Configuration;
|
||||
|
||||
namespace VDownload.Services.Data.Settings
|
||||
{
|
||||
public interface ISettingsService
|
||||
public interface ISettingsService : IInitializableService
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
@@ -73,6 +74,8 @@ namespace VDownload.Services.Data.Settings
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public async Task Initialize() => await Load();
|
||||
|
||||
public async Task Load()
|
||||
{
|
||||
if (File.Exists(_filePath))
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\VDownload.Models\VDownload.Models.csproj" />
|
||||
<ProjectReference Include="..\..\..\VDownload.Sources\VDownload.Sources.Twitch\VDownload.Sources.Twitch.Settings\VDownload.Sources.Twitch.Settings.csproj" />
|
||||
<ProjectReference Include="..\..\VDownload.Services.Common\VDownload.Services.Common.csproj" />
|
||||
<ProjectReference Include="..\VDownload.Services.Data.Configuration\VDownload.Services.Data.Configuration.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Services.Common;
|
||||
using VDownload.Services.Data.Configuration;
|
||||
|
||||
namespace VDownload.Services.Data.Subscriptions
|
||||
{
|
||||
public interface ISubscriptionsDataService
|
||||
public interface ISubscriptionsDataService : IInitializableService
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
@@ -72,6 +74,8 @@ namespace VDownload.Services.Data.Subscriptions
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public async Task Initialize() => await Load();
|
||||
|
||||
public async Task Load()
|
||||
{
|
||||
if (File.Exists(_filePath))
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\VDownload.Models\VDownload.Models.csproj" />
|
||||
<ProjectReference Include="..\..\VDownload.Services.Common\VDownload.Services.Common.csproj" />
|
||||
<ProjectReference Include="..\VDownload.Services.Data.Configuration\VDownload.Services.Data.Configuration.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -73,7 +73,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VDownload.Services.Utility.
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VDownload.Services.Data.Application", "VDownload.Services\VDownload.Services.Data\VDownload.Services.Data.Application\VDownload.Services.Data.Application.csproj", "{4983E15B-3730-4646-A2BD-16B9ECC9E4FF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VDownload.Services.Data.Subscriptions", "VDownload.Services\VDownload.Services.Data\VDownload.Services.Data.Subscriptions\VDownload.Services.Data.Subscriptions.csproj", "{3193DABC-87F8-4256-9449-3CF42FEF7098}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VDownload.Services.Data.Subscriptions", "VDownload.Services\VDownload.Services.Data\VDownload.Services.Data.Subscriptions\VDownload.Services.Data.Subscriptions.csproj", "{3193DABC-87F8-4256-9449-3CF42FEF7098}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VDownload.Services.Common", "VDownload.Services\VDownload.Services.Common\VDownload.Services.Common.csproj", "{267F5A31-1257-4820-9FE5-C11D26CC3C55}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -557,6 +559,22 @@ Global
|
||||
{3193DABC-87F8-4256-9449-3CF42FEF7098}.Release|x64.Build.0 = Release|Any CPU
|
||||
{3193DABC-87F8-4256-9449-3CF42FEF7098}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{3193DABC-87F8-4256-9449-3CF42FEF7098}.Release|x86.Build.0 = Release|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Debug|ARM64.ActiveCfg = Debug|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Debug|ARM64.Build.0 = Debug|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Release|ARM64.ActiveCfg = Release|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Release|ARM64.Build.0 = Release|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Release|x64.Build.0 = Release|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -593,6 +611,7 @@ Global
|
||||
{4647EFB5-A206-4F47-976D-BAED11B52579} = {1020167A-4101-496E-82CF-41B65769DD28}
|
||||
{4983E15B-3730-4646-A2BD-16B9ECC9E4FF} = {05A45688-7EEF-4656-818A-2477625C3707}
|
||||
{3193DABC-87F8-4256-9449-3CF42FEF7098} = {05A45688-7EEF-4656-818A-2477625C3707}
|
||||
{267F5A31-1257-4820-9FE5-C11D26CC3C55} = {8D351DB0-74E6-4C1E-A123-34D6BBBD5585}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {9FD7B842-C3E2-4FD0-AD8A-C8E619280AB7}
|
||||
|
||||
38
VDownload/Activation/ActivationHandler.cs
Normal file
38
VDownload/Activation/ActivationHandler.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VDownload.Activation
|
||||
{
|
||||
public interface IActivationHandler
|
||||
{
|
||||
bool CanHandle(object args);
|
||||
Task HandleAsync(object args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public abstract class ActivationHandler<T> : IActivationHandler
|
||||
where T : class
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public bool CanHandle(object args) => args is T && CanHandleInternal((args as T)!);
|
||||
|
||||
public async Task HandleAsync(object args) => await HandleInternalAsync((args as T)!);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected virtual bool CanHandleInternal(T args) => true;
|
||||
|
||||
protected abstract Task HandleInternalAsync(T args);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
131
VDownload/Activation/ActivationService.cs
Normal file
131
VDownload/Activation/ActivationService.cs
Normal file
@@ -0,0 +1,131 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Core.Views;
|
||||
using VDownload.Services.Common;
|
||||
using VDownload.Services.Data.Application;
|
||||
using VDownload.Services.Data.Authentication;
|
||||
using VDownload.Services.Data.Settings;
|
||||
using VDownload.Services.Data.Subscriptions;
|
||||
using VDownload.Services.UI.Dialogs;
|
||||
using VDownload.Services.UI.DictionaryResources;
|
||||
using VDownload.Services.UI.Notifications;
|
||||
using VDownload.Services.UI.StoragePicker;
|
||||
|
||||
namespace VDownload.Activation
|
||||
{
|
||||
public interface IActivationService
|
||||
{
|
||||
Task ActivateAsync(object activationArgs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class ActivationService : IActivationService
|
||||
{
|
||||
#region SERVICES
|
||||
protected readonly ActivationHandler<LaunchActivatedEventArgs> _defaultHandler;
|
||||
protected readonly IEnumerable<IActivationHandler> _activationHandlers;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region FIELDS
|
||||
|
||||
protected readonly ICollection<Func<Task>> _beforeActivationInitializations = new List<Func<Task>>();
|
||||
protected readonly ICollection<Func<Task>> _afterActivationInitializations = new List<Func<Task>>();
|
||||
protected readonly ICollection<Func<Task>> _afterWindowRootLoadedInitializations = new List<Func<Task>>();
|
||||
|
||||
protected BaseWindow _window;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
public ActivationService(ActivationHandler<LaunchActivatedEventArgs> defaultHandler, IEnumerable<IActivationHandler> activationHandlers, ISettingsService settingsService, IApplicationDataService applicationDataService, IAuthenticationDataService authenticationDataService, ISubscriptionsDataService subscriptionsDataService, IStoragePickerService storagePickerService, INotificationsService notificationsService, IDictionaryResourcesService dictionaryResourcesService, IDialogsService dialogsService)
|
||||
{
|
||||
_defaultHandler = defaultHandler;
|
||||
_activationHandlers = activationHandlers;
|
||||
|
||||
_beforeActivationInitializations.Add(() => dictionaryResourcesService.Initialize((App.Current as App).Resources));
|
||||
|
||||
_afterActivationInitializations.Add(settingsService.Initialize);
|
||||
_afterActivationInitializations.Add(applicationDataService.Initialize);
|
||||
_afterActivationInitializations.Add(authenticationDataService.Initialize);
|
||||
_afterActivationInitializations.Add(subscriptionsDataService.Initialize);
|
||||
_afterActivationInitializations.Add(() => storagePickerService.Initialize(_window));
|
||||
_afterActivationInitializations.Add(() => notificationsService.Initialize(_window));
|
||||
|
||||
_afterWindowRootLoadedInitializations.Add(() => dialogsService.Initialize(_window.XamlRoot));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public async Task ActivateAsync(object activationArgs)
|
||||
{
|
||||
await InitializeAsync();
|
||||
ViewModelToViewConverter.Initialize((App.Current as App)!.Host.Services);
|
||||
|
||||
await HandleActivationAsync(activationArgs);
|
||||
|
||||
_window = App.GetService<BaseWindow>();
|
||||
_window.RootLoaded += Window_RootLoaded;
|
||||
_window.Activate();
|
||||
|
||||
await StartupAsync();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
#region EVENT HANDLERS
|
||||
|
||||
protected async void Window_RootLoaded(object sender, EventArgs e) => await AfterWindowRootLoaded();
|
||||
|
||||
#endregion
|
||||
|
||||
protected async Task InitializeAsync()
|
||||
{
|
||||
List<Task> tasks = new List<Task>();
|
||||
foreach (Func<Task> init in _beforeActivationInitializations)
|
||||
{
|
||||
tasks.Add(init.Invoke());
|
||||
}
|
||||
await Task.WhenAll(tasks);
|
||||
}
|
||||
|
||||
protected async Task StartupAsync() => await Task.WhenAll(_afterActivationInitializations.Select(x => x.Invoke()));
|
||||
|
||||
protected async Task AfterWindowRootLoaded() => await Task.WhenAll(_afterWindowRootLoadedInitializations.Select(x => x.Invoke()));
|
||||
|
||||
protected async Task HandleActivationAsync(object activationArgs)
|
||||
{
|
||||
var activationHandler = _activationHandlers.FirstOrDefault(h => h.CanHandle(activationArgs));
|
||||
|
||||
if (activationHandler != null)
|
||||
{
|
||||
await activationHandler.HandleAsync(activationArgs);
|
||||
}
|
||||
|
||||
if (_defaultHandler.CanHandle(activationArgs))
|
||||
{
|
||||
await _defaultHandler.HandleAsync(activationArgs);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
21
VDownload/Activation/DefaultActivationHandler.cs
Normal file
21
VDownload/Activation/DefaultActivationHandler.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VDownload.Activation
|
||||
{
|
||||
public class DefaultActivationHandler : ActivationHandler<LaunchActivatedEventArgs>
|
||||
{
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected override async Task HandleInternalAsync(LaunchActivatedEventArgs args)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Activation;
|
||||
using VDownload.Core.Tasks;
|
||||
using VDownload.Core.ViewModels;
|
||||
using VDownload.Core.ViewModels.About;
|
||||
@@ -97,49 +98,11 @@ namespace VDownload
|
||||
|
||||
BuildTasksManager(services);
|
||||
BuildPresentation(services);
|
||||
BuildActivation(services);
|
||||
})
|
||||
.Build();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region EVENT HANDLERS
|
||||
|
||||
private void WindowRootLoaded(object sender, EventArgs e)
|
||||
{
|
||||
GetService<IDialogsService>().DefaultRoot = Window.XamlRoot;
|
||||
}
|
||||
|
||||
protected override async void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
base.OnLaunched(args);
|
||||
|
||||
GetService<IDictionaryResourcesService>().Resources = (App.Current as App).Resources;
|
||||
|
||||
Window = GetService<BaseWindow>();
|
||||
Window.RootLoaded += WindowRootLoaded;
|
||||
|
||||
IApplicationDataService applicationDataService = GetService<IApplicationDataService>();
|
||||
ISettingsService settingsService = GetService<ISettingsService>();
|
||||
IAuthenticationDataService authenticationDataService = GetService<IAuthenticationDataService>();
|
||||
ISubscriptionsDataService subscriptionsDataService = GetService<ISubscriptionsDataService>();
|
||||
Task initViewModelToViewConverterTask = Task.Run(() => ViewModelToViewConverter.ServiceProvider = (App.Current as App)!.Host.Services);
|
||||
Task initStoragePickerServiceTask = Task.Run(() => GetService<IStoragePickerService>().DefaultRoot = Window);
|
||||
Task initNotificationsServiceTask = Task.Run(() => GetService<INotificationsService>().Initialize(() => WindowHelper.ShowWindow(Window)));
|
||||
|
||||
await Task.WhenAll(
|
||||
applicationDataService.Load(),
|
||||
settingsService.Load(),
|
||||
authenticationDataService.Load(),
|
||||
subscriptionsDataService.Load(),
|
||||
initStoragePickerServiceTask,
|
||||
initViewModelToViewConverterTask,
|
||||
initNotificationsServiceTask
|
||||
);
|
||||
|
||||
Window.Activate();
|
||||
UnhandledException += UnhandledExceptionCatched;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -148,6 +111,22 @@ namespace VDownload
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
#region EVENT HANDLERS
|
||||
|
||||
protected override async void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
base.OnLaunched(args);
|
||||
|
||||
await GetService<IActivationService>().ActivateAsync(args);
|
||||
}
|
||||
|
||||
protected void UnhandledExceptionCatched(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected void BuildCore(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<HttpClient>();
|
||||
@@ -223,6 +202,13 @@ namespace VDownload
|
||||
services.AddTransient<BaseWindow>();
|
||||
}
|
||||
|
||||
protected void BuildActivation(IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<ActivationHandler<LaunchActivatedEventArgs>, DefaultActivationHandler>();
|
||||
|
||||
services.AddSingleton<IActivationService, ActivationService>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
|
||||
<Version>0.0.0</Version>
|
||||
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
|
||||
<WindowsPackageType>None</WindowsPackageType>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
<EnableMsixTooling>true</EnableMsixTooling>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace VDownload
|
||||
{
|
||||
public static partial class WindowHelper
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public static void ShowWindow(Window window)
|
||||
{
|
||||
// Bring the window to the foreground... first get the window handle...
|
||||
var hwnd = WinRT.Interop.WindowNative.GetWindowHandle(window);
|
||||
|
||||
// Restore window if minimized... requires DLL import above
|
||||
ShowWindow(hwnd, 0x00000009);
|
||||
|
||||
// And call SetForegroundWindow... requires DLL import above
|
||||
SetForegroundWindow(hwnd);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
[LibraryImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
||||
|
||||
[LibraryImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
private static partial bool SetForegroundWindow(IntPtr hWnd);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user