use Subject and Throttle instead of timer
MODIFY
WalletWasabi.Fluent/ViewModels/Settings/BitcoinTabViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/BitcoinTabViewModel.cs
@@ -37,7 +37,7 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
x => x.BitcoinP2PEndPoint,
x => x.LocalBitcoinCoreDataDir)
.ObserveOn(RxApp.TaskpoolScheduler)
- .Subscribe(_ => RequestSave());
+ .Subscribe(_ => Save());
}
public Version BitcoinCoreVersion => Constants.BitcoinCoreVersion;

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/GeneralTabViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/GeneralTabViewModel.cs
@@ -37,7 +37,7 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
this.WhenAnyValue(x => x.DustThreshold)
.ObserveOn(RxApp.TaskpoolScheduler)
- .Subscribe(_ => RequestSave());
+ .Subscribe(_ => Save());
this.WhenAnyValue(x => x.DarkModeEnabled)
.Skip(1)

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/NetworkTabViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/NetworkTabViewModel.cs
@@ -29,7 +29,7 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
x => x.UseTor,
x => x.TorSocks5EndPoint)
.ObserveOn(RxApp.TaskpoolScheduler)
- .Subscribe(_ => RequestSave());
+ .Subscribe(_ => Save());
}
public bool UseTor

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/PrivacyTabViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/PrivacyTabViewModel.cs
@@ -22,7 +22,7 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
x => x.MediumPrivacyLevel,
x => x.StrongPrivacyLevel)
.ObserveOn(RxApp.TaskpoolScheduler)
- .Subscribe(_ => RequestSave());
+ .Subscribe(_ => Save());
this.WhenAnyValue(x => x.MinimalPrivacyLevel)
.Subscribe(

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/SettingsPageViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/SettingsPageViewModel.cs
@@ -30,10 +30,7 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
NetworkTab = new NetworkTabViewModel(Global, config);
BitcoinTab = new BitcoinTabViewModel(Global, config);
- return Disposable.Create(() =>
- {
- GeneralTab.Dispose();
- });
+ return Disposable.Empty;
});
}

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/SettingsViewModelBase.cs
WalletWasabi.Fluent/ViewModels/Settings/SettingsViewModelBase.cs
@@ -4,36 +4,33 @@ using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Timers;
using Avalonia.Threading;
+using ReactiveUI;
using WalletWasabi.Gui;
using WalletWasabi.Gui.ViewModels;
namespace WalletWasabi.Fluent.ViewModels.Settings
{
- public abstract class SettingsViewModelBase : ViewModelBase, IDisposable
+ public abstract class SettingsViewModelBase : ViewModelBase
{
- private readonly string _configFilePath;
+ private static string _configFilePath = "";
protected SettingsViewModelBase(Global global)
{
_configFilePath = global.Config.FilePath;
- SaveTimer = new Timer(1000);
- SaveTimer.Elapsed += Save;
- SaveTimer.AutoReset = false;
+ SaveSubject = new Subject<Config>();
+ SaveSubject
+ .ObserveOn(RxApp.TaskpoolScheduler)
+ .Throttle(TimeSpan.FromMilliseconds(1000))
+ .Where(x => !global.Config.AreDeepEqual(x))
+ .Subscribe(x => x.ToFile());
}
- public Timer SaveTimer { get; }
-
private static object ConfigLock { get; } = new ();
- protected void RequestSave()
- {
- // This will prevent multiple save in a moment
- SaveTimer.Stop();
- SaveTimer.Start();
- }
+ private Subject<Config> SaveSubject { get; }
- private void Save(object sender, ElapsedEventArgs e)
+ protected void Save()
{
if (Validations.Any)
{
@@ -42,12 +39,6 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
var config = new Config(_configFilePath);
- // var subject = new Subject<Config>();
- // subject
- // .Throttle(TimeSpan.FromMilliseconds(1000))
- // .Subscribe(x => x.ToFile());
- //
- // subject.OnNext(config);
Dispatcher.UIThread.PostLogException(
() =>
{
@@ -55,7 +46,7 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
{
config.LoadFile();
EditConfigOnSave(config);
- config.ToFile();
+ SaveSubject.OnNext(config);
// IsModified = !Global.Config.AreDeepEqual(config);
}
@@ -63,10 +54,5 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
}
protected abstract void EditConfigOnSave(Config config);
-
- public virtual void Dispose()
- {
- SaveTimer.Dispose();
- }
}
}
\ No newline at end of file

use Subject and Throttle instead of timer