From f244a8bd1ae01803ad9e511ac73bc57f7e264135 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 22 Aug 2020 02:23:51 +0100 Subject: [PATCH] Load settings. --- RomRepoMgr/RomRepoMgr.csproj | 5 ++- .../ViewModels/SplashWindowViewModel.cs | 33 +++++++++++++++++++ RomRepoMgr/Views/SplashWindow.xaml.cs | 8 +++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/RomRepoMgr/RomRepoMgr.csproj b/RomRepoMgr/RomRepoMgr.csproj index 3afba35..b6a6623 100644 --- a/RomRepoMgr/RomRepoMgr.csproj +++ b/RomRepoMgr/RomRepoMgr.csproj @@ -1,7 +1,7 @@  WinExe - netcoreapp3.0 + netcoreapp3.1 @@ -19,4 +19,7 @@ + + + diff --git a/RomRepoMgr/ViewModels/SplashWindowViewModel.cs b/RomRepoMgr/ViewModels/SplashWindowViewModel.cs index 9c6eda6..2b06847 100644 --- a/RomRepoMgr/ViewModels/SplashWindowViewModel.cs +++ b/RomRepoMgr/ViewModels/SplashWindowViewModel.cs @@ -23,9 +23,12 @@ // Copyright © 2020 Natalia Portillo *******************************************************************************/ +using System; using System.Reactive; +using System.Threading.Tasks; using Avalonia; using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Threading; using ReactiveUI; namespace RomRepoMgr.ViewModels @@ -169,5 +172,35 @@ namespace RomRepoMgr.ViewModels MigratingDatabaseText = "Migrating database..."; ExitButtonText = "Exit"; } + + internal void OnOpened() => Dispatcher.UIThread.Post(LoadSettings); + + void LoadSettings() => Task.Run(() => + { + try + { + Settings.Settings.LoadSettings(); + } + catch(Exception e) + { + // TODO: Log error + Dispatcher.UIThread.Post(FailedLoadingSettings); + } + + Dispatcher.UIThread.Post(LoadDatabase); + }); + + void FailedLoadingSettings() + { + LoadingSettingsUnknown = false; + LoadingSettingsError = true; + ExitVisible = true; + } + + void LoadDatabase() + { + LoadingSettingsUnknown = false; + LoadingSettingsOk = true; + } } } \ No newline at end of file diff --git a/RomRepoMgr/Views/SplashWindow.xaml.cs b/RomRepoMgr/Views/SplashWindow.xaml.cs index be834ba..2aea804 100644 --- a/RomRepoMgr/Views/SplashWindow.xaml.cs +++ b/RomRepoMgr/Views/SplashWindow.xaml.cs @@ -23,8 +23,10 @@ // Copyright © 2020 Natalia Portillo *******************************************************************************/ +using System; using Avalonia.Controls; using Avalonia.Markup.Xaml; +using RomRepoMgr.ViewModels; namespace RomRepoMgr.Views { @@ -33,5 +35,11 @@ namespace RomRepoMgr.Views public SplashWindow() => InitializeComponent(); void InitializeComponent() => AvaloniaXamlLoader.Load(this); + + protected override void OnOpened(EventArgs e) + { + base.OnOpened(e); + (DataContext as SplashWindowViewModel)?.OnOpened(); + } } } \ No newline at end of file