build fix
This commit is contained in:
10
.github/workflows/push_master.yml
vendored
10
.github/workflows/push_master.yml
vendored
@@ -57,14 +57,10 @@ jobs:
|
||||
uses: actions/setup-dotnet@v3
|
||||
with:
|
||||
dotnet-version: 8.0.x
|
||||
- name: Setup msbuild
|
||||
uses: microsoft/setup-msbuild@v2
|
||||
- name: Deploy application
|
||||
shell: cmd
|
||||
run: |
|
||||
"%MSBUILD_PATH%" VDownload.sln /Deploy Release
|
||||
- name: Build application
|
||||
run: dotnet build -o build
|
||||
- name: Upload artifact
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: build
|
||||
path: bin
|
||||
path: build
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace VDownload.Services.UI.DictionaryResources
|
||||
{
|
||||
public interface IDictionaryResourcesService
|
||||
{
|
||||
ResourceDictionary Resources { get; set; }
|
||||
T Get<T>(string key);
|
||||
}
|
||||
|
||||
@@ -16,6 +17,14 @@ namespace VDownload.Services.UI.DictionaryResources
|
||||
|
||||
public class DictionaryResourcesService : IDictionaryResourcesService
|
||||
{
|
||||
#region PROPERTIES
|
||||
|
||||
public ResourceDictionary Resources { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region CONSTRUCTORS
|
||||
|
||||
public DictionaryResourcesService() { }
|
||||
@@ -28,7 +37,7 @@ namespace VDownload.Services.UI.DictionaryResources
|
||||
|
||||
public T Get<T>(string key)
|
||||
{
|
||||
Application.Current.Resources.TryGetValue(key, out object value);
|
||||
Resources.TryGetValue(key, out object value);
|
||||
if (value is not null && value is T cast)
|
||||
{
|
||||
return cast;
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Configuration.Json;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Toolkit.Uwp.Notifications;
|
||||
using Microsoft.UI;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.Windows.AppNotifications;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using VDownload.Core.Tasks;
|
||||
@@ -47,11 +50,21 @@ namespace VDownload
|
||||
{
|
||||
public partial class App : Application
|
||||
{
|
||||
#region FIELDS
|
||||
#region PROPERTIES
|
||||
|
||||
protected IServiceProvider _serviceProvider;
|
||||
public static BaseWindow Window { get; protected set; }
|
||||
|
||||
protected BaseWindow _window;
|
||||
public static T GetService<T>() where T : class
|
||||
{
|
||||
if ((App.Current as App)!.Host.Services.GetService(typeof(T)) is not T service)
|
||||
{
|
||||
throw new ArgumentException($"{typeof(T)} needs to be registered in ConfigureServices within App.xaml.cs.");
|
||||
}
|
||||
|
||||
return service;
|
||||
}
|
||||
|
||||
public IHost Host { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -63,13 +76,20 @@ namespace VDownload
|
||||
{
|
||||
this.InitializeComponent();
|
||||
|
||||
|
||||
IServiceCollection services = new ServiceCollection();
|
||||
|
||||
Host = Microsoft.Extensions.Hosting.Host
|
||||
.CreateDefaultBuilder()
|
||||
.UseContentRoot(AppContext.BaseDirectory)
|
||||
.ConfigureAppConfiguration((builder) =>
|
||||
{
|
||||
builder.Sources.Add(new JsonConfigurationSource
|
||||
{
|
||||
Path = "configuration.json"
|
||||
});
|
||||
})
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
BuildCore(services);
|
||||
|
||||
BuildConfiguration(services);
|
||||
|
||||
BuildDataServices(services);
|
||||
BuildUIServices(services);
|
||||
BuildUtilityServices(services);
|
||||
@@ -77,8 +97,49 @@ namespace VDownload
|
||||
|
||||
BuildTasksManager(services);
|
||||
BuildPresentation(services);
|
||||
})
|
||||
.Build();
|
||||
}
|
||||
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
#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();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -92,22 +153,6 @@ namespace VDownload
|
||||
services.AddSingleton<HttpClient>();
|
||||
}
|
||||
|
||||
protected void BuildConfiguration(IServiceCollection services)
|
||||
{
|
||||
IConfigurationBuilder configBuilder = new ConfigurationBuilder
|
||||
{
|
||||
Sources =
|
||||
{
|
||||
new JsonConfigurationSource
|
||||
{
|
||||
Path = "configuration.json"
|
||||
}
|
||||
}
|
||||
};
|
||||
IConfiguration config = configBuilder.Build();
|
||||
services.AddSingleton(config);
|
||||
}
|
||||
|
||||
protected void BuildDataServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IConfigurationService, ConfigurationService>();
|
||||
@@ -178,42 +223,6 @@ namespace VDownload
|
||||
services.AddTransient<BaseWindow>();
|
||||
}
|
||||
|
||||
protected async Task InitializeServices()
|
||||
{
|
||||
IApplicationDataService applicationDataService = _serviceProvider.GetService<IApplicationDataService>();
|
||||
ISettingsService settingsService = _serviceProvider.GetService<ISettingsService>();
|
||||
IAuthenticationDataService authenticationDataService = _serviceProvider.GetService<IAuthenticationDataService>();
|
||||
ISubscriptionsDataService subscriptionsDataService = _serviceProvider.GetService<ISubscriptionsDataService>();
|
||||
Task initViewModelToViewConverterTask = Task.Run(() => ViewModelToViewConverter.ServiceProvider = _serviceProvider);
|
||||
Task initStoragePickerServiceTask = Task.Run(() => _serviceProvider.GetService<IStoragePickerService>().DefaultRoot = _window);
|
||||
Task initNotificationsServiceTask = Task.Run(() => _serviceProvider.GetService<INotificationsService>().Initialize(() => WindowHelper.ShowWindow(_window)));
|
||||
|
||||
await Task.WhenAll(
|
||||
applicationDataService.Load(),
|
||||
settingsService.Load(),
|
||||
authenticationDataService.Load(),
|
||||
subscriptionsDataService.Load(),
|
||||
initStoragePickerServiceTask,
|
||||
initViewModelToViewConverterTask,
|
||||
initNotificationsServiceTask
|
||||
);
|
||||
}
|
||||
|
||||
protected override async void OnLaunched(LaunchActivatedEventArgs args)
|
||||
{
|
||||
_window = _serviceProvider.GetService<BaseWindow>();
|
||||
_window.RootLoaded += Window_RootLoaded;
|
||||
_window.Activate();
|
||||
|
||||
await InitializeServices();
|
||||
}
|
||||
|
||||
protected void Window_RootLoaded(object sender, EventArgs e)
|
||||
{
|
||||
IDialogsService dialogsService = _serviceProvider.GetService<IDialogsService>();
|
||||
dialogsService.DefaultRoot = _window.XamlRoot;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,6 +168,7 @@
|
||||
<PackageReference Include="CommunityToolkit.WinUI.Converters" Version="8.0.240109" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||
<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" />
|
||||
|
||||
Reference in New Issue
Block a user