From 8d452b59c86296cc7b51bce66b0eefc353254631 Mon Sep 17 00:00:00 2001 From: Johannes Meyer zum Alten Borgloh Date: Tue, 18 Feb 2020 19:22:20 +0100 Subject: [PATCH] Save settings to disk after change. Directly persists settings changes to the disk after performing a change via the "Settings" window, instead of only saving them on application exit. --- src/TumblThree/SharedAssemblyInfo.cs | 4 ++-- .../Controllers/ModuleController.cs | 11 +++++++++++ .../TumblThree.Applications/Services/IShellService.cs | 4 ++++ .../TumblThree.Applications/Services/ShellService.cs | 7 +++++++ .../ViewModels/SettingsViewModel.cs | 2 ++ .../DesignData/MockShellService.cs | 6 ++++++ 6 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/TumblThree/SharedAssemblyInfo.cs b/src/TumblThree/SharedAssemblyInfo.cs index 3f63beb..5844d65 100644 --- a/src/TumblThree/SharedAssemblyInfo.cs +++ b/src/TumblThree/SharedAssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: ComVisible(false)] [assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.MainAssembly)] -[assembly: AssemblyVersion("1.0.8.71")] -[assembly: AssemblyFileVersion("1.0.8.71")] +[assembly: AssemblyVersion("1.0.8.73")] +[assembly: AssemblyFileVersion("1.0.8.73")] diff --git a/src/TumblThree/TumblThree.Applications/Controllers/ModuleController.cs b/src/TumblThree/TumblThree.Applications/Controllers/ModuleController.cs index a4c33e4..18794af 100644 --- a/src/TumblThree/TumblThree.Applications/Controllers/ModuleController.cs +++ b/src/TumblThree/TumblThree.Applications/Controllers/ModuleController.cs @@ -91,6 +91,7 @@ public void Initialize() ShellService.ShowDetailsViewAction = ShowDetailsView; ShellService.ShowQueueViewAction = ShowQueueView; ShellService.UpdateDetailsViewAction = UpdateDetailsView; + ShellService.SettingsUpdatedHandler += OnSettingsUpdated; ShellService.InitializeOAuthManager(); ManagerController.QueueManager = queueManager; @@ -126,6 +127,11 @@ public void Shutdown() ManagerController.Shutdown(); CrawlerController.Shutdown(); + SaveSettings(); + } + + private void SaveSettings() + { string savePath = environmentService.AppSettingsPath; if (appSettings.PortableMode) savePath = AppDomain.CurrentDomain.BaseDirectory; @@ -136,6 +142,11 @@ public void Shutdown() SaveSettings(Path.Combine(savePath, cookiesFileName), new List(cookieService.GetAllCookies())); } + private void OnSettingsUpdated(object sender, EventArgs e) + { + SaveSettings(); + } + private void OnBlogManagerFinishedLoadingLibrary(object sender, EventArgs e) { QueueController.LoadQueue(); diff --git a/src/TumblThree/TumblThree.Applications/Services/IShellService.cs b/src/TumblThree/TumblThree.Applications/Services/IShellService.cs index a749a87..86246cb 100644 --- a/src/TumblThree/TumblThree.Applications/Services/IShellService.cs +++ b/src/TumblThree/TumblThree.Applications/Services/IShellService.cs @@ -43,5 +43,9 @@ public interface IShellService : INotifyPropertyChanged void AddTaskToCompleteBeforeShutdown(Task task); IDisposable SetApplicationBusy(); + + event EventHandler SettingsUpdatedHandler; + + void SettingsUpdated(); } } diff --git a/src/TumblThree/TumblThree.Applications/Services/ShellService.cs b/src/TumblThree/TumblThree.Applications/Services/ShellService.cs index c4e8f09..63ec3b9 100644 --- a/src/TumblThree/TumblThree.Applications/Services/ShellService.cs +++ b/src/TumblThree/TumblThree.Applications/Services/ShellService.cs @@ -29,6 +29,8 @@ internal class ShellService : Model, IShellService private object queueView; private object settingsView; + public event EventHandler SettingsUpdatedHandler; + [ImportingConstructor] public ShellService(Lazy shellView) { @@ -169,5 +171,10 @@ public void InitializeOAuthManager() OAuthManager["token"] = Settings.OAuthToken; OAuthManager["token_secret"] = Settings.OAuthTokenSecret; } + + public void SettingsUpdated() + { + SettingsUpdatedHandler.Invoke(null, EventArgs.Empty); + } } } diff --git a/src/TumblThree/TumblThree.Applications/ViewModels/SettingsViewModel.cs b/src/TumblThree/TumblThree.Applications/ViewModels/SettingsViewModel.cs index ff491b1..b5e0e98 100644 --- a/src/TumblThree/TumblThree.Applications/ViewModels/SettingsViewModel.cs +++ b/src/TumblThree/TumblThree.Applications/ViewModels/SettingsViewModel.cs @@ -1055,6 +1055,8 @@ private async Task Save() bool loadAllDatabasesChanged = LoadAllDatabasesChanged(); SaveSettings(); await ApplySettings(downloadLocationChanged, loadAllDatabasesChanged); + + ShellService.SettingsUpdated(); } private async Task ApplySettings(bool downloadLocationChanged, bool loadAllDatabasesChanged) diff --git a/src/TumblThree/TumblThree.Presentation/DesignData/MockShellService.cs b/src/TumblThree/TumblThree.Presentation/DesignData/MockShellService.cs index 3812fb3..aa1a4c4 100644 --- a/src/TumblThree/TumblThree.Presentation/DesignData/MockShellService.cs +++ b/src/TumblThree/TumblThree.Presentation/DesignData/MockShellService.cs @@ -33,6 +33,8 @@ public class MockShellService : Model, IShellService public event CancelEventHandler Closing; + public event EventHandler SettingsUpdatedHandler; + public void ShowError(Exception exception, string displayMessage) { } @@ -49,6 +51,10 @@ public void UpdateDetailsView() { } + public void SettingsUpdated() + { + } + public void AddTaskToCompleteBeforeShutdown(Task task) { }