Browse Source

Fix settings not saved if changed after file was edited

If you made a change in advanced settings and saved that file THEN made a change through the regular menu, it would never save the second time.

The current behavior was a hold-over from when we didn't reload when the file got changed.

#7 ?
Daniel Chalmers 1 year ago
parent
commit
3d5aee9c91
2 changed files with 1 additions and 18 deletions
  1. 1 1
      DesktopClock/MainWindow.xaml.cs
  2. 0 17
      DesktopClock/Properties/Settings.cs

+ 1 - 1
DesktopClock/MainWindow.xaml.cs

@@ -276,7 +276,7 @@ public partial class MainWindow : Window
 
     private void Window_Closed(object sender, EventArgs e)
     {
-        Settings.Default.SaveIfNotModifiedExternally();
+        Settings.Default.Save();
 
         App.SetRunOnStartup(Settings.Default.RunOnStartup);
 

+ 0 - 17
DesktopClock/Properties/Settings.cs

@@ -10,7 +10,6 @@ namespace DesktopClock.Properties;
 public sealed class Settings : INotifyPropertyChanged, IDisposable
 {
     private readonly FileSystemWatcher _watcher;
-    private DateTime _fileDate = DateTime.UtcNow;
 
     private static readonly Lazy<Settings> _default = new(() => Load() ?? new Settings());
 
@@ -83,11 +82,6 @@ public sealed class Settings : INotifyPropertyChanged, IDisposable
 
     #endregion "Properties"
 
-    /// <summary>
-    /// Determines if the settings file has been modified externally since the last time it was used.
-    /// </summary>
-    public bool CheckIfModifiedExternally() => File.GetLastWriteTimeUtc(FilePath) > _fileDate;
-
     /// <summary>
     /// Saves to the default path.
     /// </summary>
@@ -98,17 +92,6 @@ public sealed class Settings : INotifyPropertyChanged, IDisposable
         using var jsonWriter = new JsonTextWriter(streamWriter);
 
         JsonSerializer.Create(_jsonSerializerSettings).Serialize(jsonWriter, this);
-
-        _fileDate = DateTime.UtcNow;
-    }
-
-    /// <summary>
-    /// Saves to the default path unless a save has already happened from an external source.
-    /// </summary>
-    public void SaveIfNotModifiedExternally()
-    {
-        if (!CheckIfModifiedExternally())
-            Save();
     }
 
     /// <summary>