Skip to content

Commit

Permalink
misc: Prevent value change logging when the value is changed to the s…
Browse files Browse the repository at this point in the history
…ame thing it was before the value change.
  • Loading branch information
GreemDev committed Jan 1, 2025
1 parent 3fa714b commit 732aafd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 66 deletions.
11 changes: 11 additions & 0 deletions src/Ryujinx.Common/ReactiveObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ public static class ReactiveObjectHelper
{
public static void LogValueChange<T>(LogClass logClass, ReactiveEventArgs<T> eventArgs, string valueName)
{
if ((eventArgs.NewValue == null || eventArgs.OldValue == null))
{
if (!(eventArgs.NewValue == null && eventArgs.OldValue == null))
goto Log;
}
else if (!eventArgs.NewValue!.Equals(eventArgs.OldValue))
goto Log;

return;

Log:
string message = string.Create(CultureInfo.InvariantCulture, $"{valueName} set to: {eventArgs.NewValue}");

Logger.Info?.Print(logClass, message);
Expand Down
79 changes: 13 additions & 66 deletions src/Ryujinx/UI/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
using Gommon;
using LibHac.Tools.FsSystem;
using Ryujinx.Audio.Backends.OpenAL;
Expand Down Expand Up @@ -46,9 +47,9 @@ public partial class SettingsViewModel : BaseModel
private int _resolutionScale;
private int _graphicsBackendMultithreadingIndex;
private float _volume;
private bool _isVulkanAvailable = true;
private bool _gameDirectoryChanged;
private bool _autoloadDirectoryChanged;
[ObservableProperty] private bool _isVulkanAvailable = true;
[ObservableProperty] private bool _gameDirectoryChanged;
[ObservableProperty] private bool _autoloadDirectoryChanged;
private readonly List<string> _gpuIds = new();
private int _graphicsBackendIndex;
private int _scalingFilter;
Expand All @@ -63,7 +64,7 @@ public partial class SettingsViewModel : BaseModel
private int _networkInterfaceIndex;
private int _multiplayerModeIndex;
private string _ldnPassphrase;
private string _ldnServer;
[ObservableProperty] private string _ldnServer;

public SettingsHacksViewModel DirtyHacks { get; }

Expand Down Expand Up @@ -111,43 +112,10 @@ public float CustomResolutionScale
}
}

public bool IsVulkanAvailable
{
get => _isVulkanAvailable;
set
{
_isVulkanAvailable = value;

OnPropertyChanged();
}
}

public bool IsOpenGLAvailable => !OperatingSystem.IsMacOS();

public bool IsAppleSiliconMac => OperatingSystem.IsMacOS() && RuntimeInformation.ProcessArchitecture == Architecture.Arm64;

public bool GameDirectoryChanged
{
get => _gameDirectoryChanged;
set
{
_gameDirectoryChanged = value;

OnPropertyChanged();
}
}

public bool AutoloadDirectoryChanged
{
get => _autoloadDirectoryChanged;
set
{
_autoloadDirectoryChanged = value;

OnPropertyChanged();
}
}

public bool IsMacOS => OperatingSystem.IsMacOS();

public bool EnableDiscordIntegration { get; set; }
Expand Down Expand Up @@ -182,19 +150,12 @@ public int CustomVSyncIntervalPercentageProxy
_customVSyncInterval = newInterval;
_customVSyncIntervalPercentageProxy = value;
OnPropertiesChanged(
nameof(CustomVSyncInterval),
nameof(CustomVSyncInterval),
nameof(CustomVSyncIntervalPercentageText));
}
}

public string CustomVSyncIntervalPercentageText
{
get
{
string text = CustomVSyncIntervalPercentageProxy + "%";
return text;
}
}
public string CustomVSyncIntervalPercentageText => CustomVSyncIntervalPercentageProxy + "%";

public bool EnableCustomVSyncInterval
{
Expand Down Expand Up @@ -356,7 +317,6 @@ public int NetworkInterfaceIndex
set
{
_networkInterfaceIndex = value != -1 ? value : 0;
ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value = _networkInterfaces[NetworkInterfaceList[_networkInterfaceIndex]];
}
}

Expand All @@ -366,7 +326,6 @@ public int MultiplayerModeIndex
set
{
_multiplayerModeIndex = value;
ConfigurationState.Instance.Multiplayer.Mode.Value = (MultiplayerMode)_multiplayerModeIndex;
}
}

Expand All @@ -375,16 +334,6 @@ public int MultiplayerModeIndex

public bool IsInvalidLdnPassphraseVisible { get; set; }

public string LdnServer
{
get => _ldnServer;
set
{
_ldnServer = value;
OnPropertyChanged();
}
}

public SettingsViewModel(VirtualFileSystem virtualFileSystem, ContentManager contentManager) : this()
{
_virtualFileSystem = virtualFileSystem;
Expand Down Expand Up @@ -647,16 +596,14 @@ public void SaveSettings()
config.ShowTitleBar.Value = ShowTitleBar;
config.HideCursor.Value = (HideCursorMode)HideCursor;

if (_gameDirectoryChanged)
if (GameDirectoryChanged)
{
List<string> gameDirs = new(GameDirectories);
config.UI.GameDirs.Value = gameDirs;
config.UI.GameDirs.Value = [..GameDirectories];
}

if (_autoloadDirectoryChanged)
if (AutoloadDirectoryChanged)
{
List<string> autoloadDirs = new(AutoloadDirectories);
config.UI.AutoloadDirs.Value = autoloadDirs;
config.UI.AutoloadDirs.Value = [..AutoloadDirectories];
}

config.UI.BaseStyle.Value = BaseStyleIndex switch
Expand Down Expand Up @@ -766,8 +713,8 @@ public void SaveSettings()

SaveSettingsEvent?.Invoke();

_gameDirectoryChanged = false;
_autoloadDirectoryChanged = false;
GameDirectoryChanged = false;
AutoloadDirectoryChanged = false;
}

private static void RevertIfNotSaved()
Expand Down

0 comments on commit 732aafd

Please sign in to comment.