do not hardcode `isRestartNeeded`
MODIFY
WalletWasabi.Fluent/ViewModels/SearchBar/Settings/Setting.cs
WalletWasabi.Fluent/ViewModels/SearchBar/Settings/Setting.cs
@@ -5,15 +5,15 @@ using System.Reactive.Linq;
using System.Windows.Input;
using ReactiveUI;
using WalletWasabi.Fluent.Helpers;
+using WalletWasabi.Fluent.ViewModels.Settings;
namespace WalletWasabi.Fluent.ViewModels.SearchBar.Settings;
-public class Setting<TTarget, TProperty> : ReactiveObject
+public partial class Setting<TTarget, TProperty> : ReactiveObject
{
- private TProperty? _value;
+ [AutoNotify] private TProperty? _value;
- public Setting([DisallowNull] TTarget target, Expression<Func<TTarget, TProperty>> selector,
- bool requiresRestart = false)
+ public Setting([DisallowNull] TTarget target, Expression<Func<TTarget, TProperty>> selector)
{
if (target == null)
{
@@ -30,40 +30,28 @@ public class Setting<TTarget, TProperty> : ReactiveObject
throw new InvalidOperationException($"The expression {selector} is not a valid property selector");
}
- ShowRestartNotificationCommand = ReactiveCommand.Create(() =>
- {
- NotificationHelpers.Show(
- new RestartViewModel("To apply the new setting, Wasabi Wallet needs to be restarted"));
- });
-
- var originalValue = (TProperty?) pr.GetValue(target);
Value = (TProperty?)pr.GetValue(target);
SetValueCommand = ReactiveCommand.Create(() => pr.SetValue(target, Value));
+ ShowNotificationCommand = ReactiveCommand.Create(() => NotificationHelpers.Show(new RestartViewModel("To apply the new setting, Wasabi Wallet needs to be restarted")));
+
this.WhenAnyValue(x => x.Value)
- .ObserveOn(RxApp.TaskpoolScheduler)
+ .ObserveOn(RxApp.MainThreadScheduler)
.Skip(1)
.Select(_ => Unit.Default)
.InvokeCommand(SetValueCommand);
- if (requiresRestart)
- {
this.WhenAnyValue(x => x.Value)
- .Select(currentValue => new{current = currentValue, originalValue})
- .Where(x => !Equals(x.current, x.originalValue))
+ .Skip(1)
+ .Throttle(TimeSpan.FromMilliseconds(SettingsTabViewModelBase.ThrottleTime + 50))
+ .ObserveOn(RxApp.MainThreadScheduler)
+ .Where(_ => SettingsTabViewModelBase.CheckIfRestartIsNeeded())
.Select(_ => Unit.Default)
- .InvokeCommand(ShowRestartNotificationCommand);
+ .InvokeCommand(ShowNotificationCommand);
}
- }
-
- public ICommand ShowRestartNotificationCommand { get; }
- public TProperty? Value
- {
- get => _value;
- set => this.RaiseAndSetIfChanged(ref _value, value);
- }
+ public ICommand SetValueCommand { get; }
- public ReactiveCommand<Unit, Unit> SetValueCommand { get; }
+ public ICommand ShowNotificationCommand { get; }
}

MODIFY
WalletWasabi.Fluent/ViewModels/SearchBar/Sources/SettingsSource.cs
WalletWasabi.Fluent/ViewModels/SearchBar/Sources/SettingsSource.cs
@@ -30,8 +30,8 @@ public class SettingsSource : ISearchItemSource
new NonActionableSearchItem(new Setting<GeneralSettingsTabViewModel, bool>(_settingsPage.GeneralSettingsTab, b => b.AutoPaste), "Auto paste addresses", "Settings", new List<string>(), "nav_settings_regular") { IsDefault = false },
new NonActionableSearchItem(new Setting<GeneralSettingsTabViewModel, bool>(_settingsPage.GeneralSettingsTab, b => b.HideOnClose), "Run in background when closed", "Settings", new List<string>() { "hide", "tray" }, "nav_settings_regular") { IsDefault = false },
new NonActionableSearchItem(new Setting<GeneralSettingsTabViewModel, bool>(_settingsPage.GeneralSettingsTab, b => b.RunOnSystemStartup), "Run Wasabi when computer starts", "Settings", new List<string>() { "startup", "boot" }, "nav_settings_regular") { IsDefault = false },
- new NonActionableSearchItem(new Setting<TorSettingsTabViewModel, bool>(_settingsPage.TorSettingsTab, b => b.UseTor, true), "Network anonymization (Tor)", "Settings", new List<string>(), "nav_settings_regular") { IsDefault = false },
- new NonActionableSearchItem(new Setting<TorSettingsTabViewModel, bool>(_settingsPage.TorSettingsTab, b => b.TerminateTorOnExit, true), "Terminate Tor when Wasabi shuts down", "Settings", new List<string>(), "nav_settings_regular") { IsDefault = false },
+ new NonActionableSearchItem(new Setting<TorSettingsTabViewModel, bool>(_settingsPage.TorSettingsTab, b => b.UseTor), "Network anonymization (Tor)", "Settings", new List<string>(), "nav_settings_regular") { IsDefault = false },
+ new NonActionableSearchItem(new Setting<TorSettingsTabViewModel, bool>(_settingsPage.TorSettingsTab, b => b.TerminateTorOnExit), "Terminate Tor when Wasabi shuts down", "Settings", new List<string>(), "nav_settings_regular") { IsDefault = false },
new NonActionableSearchItem(new Setting<BitcoinTabSettingsViewModel, bool>(_settingsPage.BitcoinTabSettings, b => b.StartLocalBitcoinCoreOnStartup), "Start local Bitcoin core on startup", "Settings", new List<string>(), "nav_settings_regular") { IsDefault = false },
new NonActionableSearchItem(new Setting<BitcoinTabSettingsViewModel, bool>(_settingsPage.BitcoinTabSettings, b => b.StopLocalBitcoinCoreOnShutdown), "Stop local Bitcoin core on shutdown", "Settings", new List<string>(), "nav_settings_regular") { IsDefault = false },
};

do not hardcode `isRestartNeeded`