Skip save on viewmodel creation
MODIFY
WalletWasabi.Fluent/ViewModels/Settings/BitcoinTabViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/BitcoinTabViewModel.cs
@@ -37,6 +37,8 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
x => x.BitcoinP2PEndPoint,
x => x.LocalBitcoinCoreDataDir)
.ObserveOn(RxApp.TaskpoolScheduler)
+ .Throttle(TimeSpan.FromSeconds(1))
+ .Skip(1)
.Subscribe(_ => Save());
}

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/GeneralTabViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/GeneralTabViewModel.cs
@@ -36,31 +36,32 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
this.WhenAnyValue(x => x.DustThreshold)
.ObserveOn(RxApp.TaskpoolScheduler)
+ .Throttle(TimeSpan.FromSeconds(1))
+ .Skip(1)
.Subscribe(_ => Save());
this.WhenAnyValue(x => x.DarkModeEnabled)
.Skip(1)
- .Subscribe(
- x =>
- {
- global.UiConfig.DarkModeEnabled = x;
- ThemeHelper.ApplyTheme(x);
- });
+ .Subscribe(x => global.UiConfig.DarkModeEnabled = x);
this.WhenAnyValue(x => x.Autocopy)
.ObserveOn(RxApp.TaskpoolScheduler)
+ .Skip(1)
.Subscribe(x => global.UiConfig.Autocopy = x);
this.WhenAnyValue(x => x.CustomFee)
.ObserveOn(RxApp.TaskpoolScheduler)
+ .Skip(1)
.Subscribe(x => global.UiConfig.IsCustomFee = x);
this.WhenAnyValue(x => x.CustomChangeAddress)
.ObserveOn(RxApp.TaskpoolScheduler)
+ .Skip(1)
.Subscribe(x => global.UiConfig.IsCustomChangeAddress = x);
this.WhenAnyValue(x => x.SelectedFeeDisplayFormat)
.ObserveOn(RxApp.MainThreadScheduler)
+ .Skip(1)
.Subscribe(x => global.UiConfig.FeeDisplayFormat = (int)x);
}

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/NetworkTabViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/NetworkTabViewModel.cs
@@ -29,6 +29,8 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
x => x.UseTor,
x => x.TorSocks5EndPoint)
.ObserveOn(RxApp.TaskpoolScheduler)
+ .Throttle(TimeSpan.FromSeconds(1))
+ .Skip(1)
.Subscribe(_ => Save());
}

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/PrivacyTabViewModel.cs
WalletWasabi.Fluent/ViewModels/Settings/PrivacyTabViewModel.cs
@@ -22,6 +22,8 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
x => x.MediumPrivacyLevel,
x => x.StrongPrivacyLevel)
.ObserveOn(RxApp.TaskpoolScheduler)
+ .Throttle(TimeSpan.FromSeconds(1))
+ .Skip(1)
.Subscribe(_ => Save());
this.WhenAnyValue(x => x.MinimalPrivacyLevel)

MODIFY
WalletWasabi.Fluent/ViewModels/Settings/SettingsViewModelBase.cs
WalletWasabi.Fluent/ViewModels/Settings/SettingsViewModelBase.cs
@@ -12,23 +12,14 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
{
public abstract class SettingsViewModelBase : ViewModelBase
{
- private static string _configFilePath = "";
-
protected SettingsViewModelBase(Global global)
{
- _configFilePath = global.Config.FilePath;
-
- SaveSubject = new Subject<Config>();
- SaveSubject
- .ObserveOn(RxApp.TaskpoolScheduler)
- .Throttle(TimeSpan.FromSeconds(1))
- .Where(x => !global.Config.AreDeepEqual(x))
- .Subscribe(x => x.ToFile());
+ Global = global;
}
- private static object ConfigLock { get; } = new ();
+ public Global Global { get; }
- private Subject<Config> SaveSubject { get; }
+ private static object ConfigLock { get; } = new ();
protected void Save()
{
@@ -37,7 +28,7 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
return;
}
- var config = new Config(_configFilePath);
+ var config = new Config(Global.Config.FilePath);
Dispatcher.UIThread.PostLogException(
() =>
@@ -46,7 +37,11 @@ namespace WalletWasabi.Fluent.ViewModels.Settings
{
config.LoadFile();
EditConfigOnSave(config);
- SaveSubject.OnNext(config);
+
+ if (!Global.Config.AreDeepEqual(config))
+ {
+ config.ToFile();
+ }
// IsModified = !Global.Config.AreDeepEqual(config);
}

Skip save on viewmodel creation