Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

Commit

Permalink
Save settings to disk after change.
Browse files Browse the repository at this point in the history
Directly persists settings changes to the disk after performing a change via the "Settings" window, instead of only saving them on application exit.
  • Loading branch information
johanneszab committed Feb 18, 2020
1 parent edb3bc9 commit 8d452b5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/TumblThree/SharedAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public void Initialize()
ShellService.ShowDetailsViewAction = ShowDetailsView;
ShellService.ShowQueueViewAction = ShowQueueView;
ShellService.UpdateDetailsViewAction = UpdateDetailsView;
ShellService.SettingsUpdatedHandler += OnSettingsUpdated;
ShellService.InitializeOAuthManager();

ManagerController.QueueManager = queueManager;
Expand Down Expand Up @@ -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;
Expand All @@ -136,6 +142,11 @@ public void Shutdown()
SaveSettings(Path.Combine(savePath, cookiesFileName), new List<Cookie>(cookieService.GetAllCookies()));
}

private void OnSettingsUpdated(object sender, EventArgs e)
{
SaveSettings();
}

private void OnBlogManagerFinishedLoadingLibrary(object sender, EventArgs e)
{
QueueController.LoadQueue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@ public interface IShellService : INotifyPropertyChanged
void AddTaskToCompleteBeforeShutdown(Task task);

IDisposable SetApplicationBusy();

event EventHandler SettingsUpdatedHandler;

void SettingsUpdated();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ internal class ShellService : Model, IShellService
private object queueView;
private object settingsView;

public event EventHandler SettingsUpdatedHandler;

[ImportingConstructor]
public ShellService(Lazy<IShellView> shellView)
{
Expand Down Expand Up @@ -169,5 +171,10 @@ public void InitializeOAuthManager()
OAuthManager["token"] = Settings.OAuthToken;
OAuthManager["token_secret"] = Settings.OAuthTokenSecret;
}

public void SettingsUpdated()
{
SettingsUpdatedHandler.Invoke(null, EventArgs.Empty);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class MockShellService : Model, IShellService

public event CancelEventHandler Closing;

public event EventHandler SettingsUpdatedHandler;

public void ShowError(Exception exception, string displayMessage)
{
}
Expand All @@ -49,6 +51,10 @@ public void UpdateDetailsView()
{
}

public void SettingsUpdated()
{
}

public void AddTaskToCompleteBeforeShutdown(Task task)
{
}
Expand Down

0 comments on commit 8d452b5

Please sign in to comment.