mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-11-24 09:24:16 +00:00
Ava UI: Make some settings methods async (#5332)
* Ava: Asynchronously load Vulkan device settings items. * Sound checks, timezones and network interface async * Refresh UI items once awaited tasks complete * Remove unused dep * Timezone UI update * Use UIThread dispatcher for thread-unsafe collections + simplify GPU collection. * Remove empty lines * Remove unused string * Dispatch property changes * format changes * format 2 * Use Tasks instead of async void * Make NetworkInterfaceIndex access thread safe.
This commit is contained in:
parent
8c61ddd49d
commit
2efd74b9cb
1 changed files with 48 additions and 22 deletions
|
@ -1,7 +1,6 @@
|
||||||
using Avalonia.Collections;
|
using Avalonia.Collections;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using DynamicData;
|
|
||||||
using LibHac.Tools.FsSystem;
|
using LibHac.Tools.FsSystem;
|
||||||
using Ryujinx.Audio.Backends.OpenAL;
|
using Ryujinx.Audio.Backends.OpenAL;
|
||||||
using Ryujinx.Audio.Backends.SDL2;
|
using Ryujinx.Audio.Backends.SDL2;
|
||||||
|
@ -24,6 +23,7 @@ using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.NetworkInformation;
|
using System.Net.NetworkInformation;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using TimeZone = Ryujinx.Ava.UI.Models.TimeZone;
|
using TimeZone = Ryujinx.Ava.UI.Models.TimeZone;
|
||||||
|
|
||||||
namespace Ryujinx.Ava.UI.ViewModels
|
namespace Ryujinx.Ava.UI.ViewModels
|
||||||
|
@ -44,7 +44,7 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
private float _volume;
|
private float _volume;
|
||||||
private bool _isVulkanAvailable = true;
|
private bool _isVulkanAvailable = true;
|
||||||
private bool _directoryChanged;
|
private bool _directoryChanged;
|
||||||
private List<string> _gpuIds = new();
|
private readonly List<string> _gpuIds = new();
|
||||||
private KeyboardHotkeys _keyboardHotkeys;
|
private KeyboardHotkeys _keyboardHotkeys;
|
||||||
private int _graphicsBackendIndex;
|
private int _graphicsBackendIndex;
|
||||||
private string _customThemePath;
|
private string _customThemePath;
|
||||||
|
@ -278,7 +278,7 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
_contentManager = contentManager;
|
_contentManager = contentManager;
|
||||||
if (Program.PreviewerDetached)
|
if (Program.PreviewerDetached)
|
||||||
{
|
{
|
||||||
LoadTimeZones();
|
Task.Run(LoadTimeZones);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,27 +290,34 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
_validTzRegions = new List<string>();
|
_validTzRegions = new List<string>();
|
||||||
_networkInterfaces = new Dictionary<string, string>();
|
_networkInterfaces = new Dictionary<string, string>();
|
||||||
|
|
||||||
CheckSoundBackends();
|
Task.Run(CheckSoundBackends);
|
||||||
PopulateNetworkInterfaces();
|
Task.Run(PopulateNetworkInterfaces);
|
||||||
|
|
||||||
if (Program.PreviewerDetached)
|
if (Program.PreviewerDetached)
|
||||||
{
|
{
|
||||||
LoadAvailableGpus();
|
Task.Run(LoadAvailableGpus);
|
||||||
LoadCurrentConfiguration();
|
LoadCurrentConfiguration();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CheckSoundBackends()
|
public async Task CheckSoundBackends()
|
||||||
{
|
{
|
||||||
IsOpenAlEnabled = OpenALHardwareDeviceDriver.IsSupported;
|
IsOpenAlEnabled = OpenALHardwareDeviceDriver.IsSupported;
|
||||||
IsSoundIoEnabled = SoundIoHardwareDeviceDriver.IsSupported;
|
IsSoundIoEnabled = SoundIoHardwareDeviceDriver.IsSupported;
|
||||||
IsSDL2Enabled = SDL2HardwareDeviceDriver.IsSupported;
|
IsSDL2Enabled = SDL2HardwareDeviceDriver.IsSupported;
|
||||||
|
|
||||||
|
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
OnPropertyChanged(nameof(IsOpenAlEnabled));
|
||||||
|
OnPropertyChanged(nameof(IsSoundIoEnabled));
|
||||||
|
OnPropertyChanged(nameof(IsSDL2Enabled));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadAvailableGpus()
|
private async Task LoadAvailableGpus()
|
||||||
{
|
{
|
||||||
_gpuIds = new List<string>();
|
AvailableGpus.Clear();
|
||||||
List<string> names = new();
|
|
||||||
var devices = VulkanRenderer.GetPhysicalDevices();
|
var devices = VulkanRenderer.GetPhysicalDevices();
|
||||||
|
|
||||||
if (devices.Length == 0)
|
if (devices.Length == 0)
|
||||||
|
@ -322,16 +329,23 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
{
|
{
|
||||||
foreach (var device in devices)
|
foreach (var device in devices)
|
||||||
{
|
{
|
||||||
_gpuIds.Add(device.Id);
|
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
names.Add($"{device.Name} {(device.IsDiscrete ? "(dGPU)" : "")}");
|
{
|
||||||
|
_gpuIds.Add(device.Id);
|
||||||
|
|
||||||
|
AvailableGpus.Add(new ComboBoxItem { Content = $"{device.Name} {(device.IsDiscrete ? "(dGPU)" : "")}" });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AvailableGpus.Clear();
|
// GPU configuration needs to be loaded during the async method or it will always return 0.
|
||||||
AvailableGpus.AddRange(names.Select(x => new ComboBoxItem { Content = x }));
|
PreferredGpuIndex = _gpuIds.Contains(ConfigurationState.Instance.Graphics.PreferredGpu) ?
|
||||||
|
_gpuIds.IndexOf(ConfigurationState.Instance.Graphics.PreferredGpu) : 0;
|
||||||
|
|
||||||
|
Dispatcher.UIThread.Post(() => OnPropertyChanged(nameof(PreferredGpuIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadTimeZones()
|
public async Task LoadTimeZones()
|
||||||
{
|
{
|
||||||
_timeZoneContentManager = new TimeZoneContentManager();
|
_timeZoneContentManager = new TimeZoneContentManager();
|
||||||
|
|
||||||
|
@ -344,21 +358,34 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
|
|
||||||
string abbr2 = abbr.StartsWith('+') || abbr.StartsWith('-') ? string.Empty : abbr;
|
string abbr2 = abbr.StartsWith('+') || abbr.StartsWith('-') ? string.Empty : abbr;
|
||||||
|
|
||||||
TimeZones.Add(new TimeZone($"UTC{hours:+0#;-0#;+00}:{minutes:D2}", location, abbr2));
|
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
TimeZones.Add(new TimeZone($"UTC{hours:+0#;-0#;+00}:{minutes:D2}", location, abbr2));
|
||||||
|
|
||||||
_validTzRegions.Add(location);
|
_validTzRegions.Add(location);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Dispatcher.UIThread.Post(() => OnPropertyChanged(nameof(TimeZone)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PopulateNetworkInterfaces()
|
private async Task PopulateNetworkInterfaces()
|
||||||
{
|
{
|
||||||
_networkInterfaces.Clear();
|
_networkInterfaces.Clear();
|
||||||
_networkInterfaces.Add(LocaleManager.Instance[LocaleKeys.NetworkInterfaceDefault], "0");
|
_networkInterfaces.Add(LocaleManager.Instance[LocaleKeys.NetworkInterfaceDefault], "0");
|
||||||
|
|
||||||
foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
|
foreach (NetworkInterface networkInterface in NetworkInterface.GetAllNetworkInterfaces())
|
||||||
{
|
{
|
||||||
_networkInterfaces.Add(networkInterface.Name, networkInterface.Id);
|
await Dispatcher.UIThread.InvokeAsync(() =>
|
||||||
|
{
|
||||||
|
_networkInterfaces.Add(networkInterface.Name, networkInterface.Id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Network interface index needs to be loaded during the async method or it will always return 0.
|
||||||
|
NetworkInterfaceIndex = _networkInterfaces.Values.ToList().IndexOf(ConfigurationState.Instance.Multiplayer.LanInterfaceId.Value);
|
||||||
|
|
||||||
|
Dispatcher.UIThread.Post(() => OnPropertyChanged(nameof(NetworkInterfaceIndex)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ValidateAndSetTimeZone(string location)
|
public void ValidateAndSetTimeZone(string location)
|
||||||
|
@ -416,7 +443,7 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
|
|
||||||
// Graphics
|
// Graphics
|
||||||
GraphicsBackendIndex = (int)config.Graphics.GraphicsBackend.Value;
|
GraphicsBackendIndex = (int)config.Graphics.GraphicsBackend.Value;
|
||||||
PreferredGpuIndex = _gpuIds.Contains(config.Graphics.PreferredGpu) ? _gpuIds.IndexOf(config.Graphics.PreferredGpu) : 0;
|
// Physical devices are queried asynchronously hence the prefered index config value is loaded in LoadAvailableGpus().
|
||||||
EnableShaderCache = config.Graphics.EnableShaderCache;
|
EnableShaderCache = config.Graphics.EnableShaderCache;
|
||||||
EnableTextureRecompression = config.Graphics.EnableTextureRecompression;
|
EnableTextureRecompression = config.Graphics.EnableTextureRecompression;
|
||||||
EnableMacroHLE = config.Graphics.EnableMacroHLE;
|
EnableMacroHLE = config.Graphics.EnableMacroHLE;
|
||||||
|
@ -437,6 +464,7 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
|
|
||||||
// Network
|
// Network
|
||||||
EnableInternetAccess = config.System.EnableInternetAccess;
|
EnableInternetAccess = config.System.EnableInternetAccess;
|
||||||
|
// LAN interface index is loaded asynchronously in PopulateNetworkInterfaces()
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
EnableFileLog = config.Logger.EnableFileLog;
|
EnableFileLog = config.Logger.EnableFileLog;
|
||||||
|
@ -450,8 +478,6 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
EnableFsAccessLog = config.Logger.EnableFsAccessLog;
|
EnableFsAccessLog = config.Logger.EnableFsAccessLog;
|
||||||
FsGlobalAccessLogMode = config.System.FsGlobalAccessLogMode;
|
FsGlobalAccessLogMode = config.System.FsGlobalAccessLogMode;
|
||||||
OpenglDebugLevel = (int)config.Logger.GraphicsDebugLevel.Value;
|
OpenglDebugLevel = (int)config.Logger.GraphicsDebugLevel.Value;
|
||||||
|
|
||||||
NetworkInterfaceIndex = _networkInterfaces.Values.ToList().IndexOf(config.Multiplayer.LanInterfaceId.Value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveSettings()
|
public void SaveSettings()
|
||||||
|
|
Loading…
Reference in a new issue