You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.2 KiB
67 lines
2.2 KiB
using System.Linq; |
|
using System.Threading.Tasks; |
|
using AsyncAwaitBestPractices; |
|
using CommunityToolkit.Mvvm.ComponentModel; |
|
using StabilityMatrix.Avalonia.Styles; |
|
using StabilityMatrix.Avalonia.ViewModels.Base; |
|
using StabilityMatrix.Avalonia.Views; |
|
using StabilityMatrix.Core.Attributes; |
|
using StabilityMatrix.Core.Helper; |
|
using StabilityMatrix.Core.Helper.HardwareInfo; |
|
|
|
namespace StabilityMatrix.Avalonia.ViewModels; |
|
|
|
[View(typeof(FirstLaunchSetupWindow))] |
|
[ManagedService] |
|
[Singleton] |
|
public partial class FirstLaunchSetupViewModel : ViewModelBase |
|
{ |
|
[ObservableProperty] |
|
private bool eulaAccepted; |
|
|
|
[ObservableProperty] |
|
private string gpuInfoText = string.Empty; |
|
|
|
[ObservableProperty] |
|
private RefreshBadgeViewModel checkHardwareBadge = |
|
new() |
|
{ |
|
WorkingToolTipText = "We're checking some hardware specifications to determine compatibility.", |
|
SuccessToolTipText = "Everything looks good!", |
|
FailToolTipText = |
|
"We recommend a GPU with CUDA support for the best experience. " |
|
+ "You can continue without one, but some packages may not work, and inference may be slower.", |
|
FailColorBrush = ThemeColors.ThemeYellow, |
|
}; |
|
|
|
public FirstLaunchSetupViewModel() |
|
{ |
|
CheckHardwareBadge.RefreshFunc = SetGpuInfo; |
|
} |
|
|
|
private async Task<bool> SetGpuInfo() |
|
{ |
|
GpuInfo[] gpuInfo; |
|
await using (new MinimumDelay(800, 1200)) |
|
{ |
|
// Query GPU info |
|
gpuInfo = await Task.Run(() => HardwareHelper.IterGpuInfo().ToArray()); |
|
} |
|
// First Nvidia GPU |
|
var activeGpu = gpuInfo.FirstOrDefault(gpu => gpu.Name?.ToLowerInvariant().Contains("nvidia") ?? false); |
|
var isNvidia = activeGpu is not null; |
|
// Otherwise first GPU |
|
activeGpu ??= gpuInfo.FirstOrDefault(); |
|
GpuInfoText = activeGpu is null |
|
? "No GPU detected" |
|
: $"{activeGpu.Name} ({Size.FormatBytes(activeGpu.MemoryBytes)})"; |
|
|
|
return isNvidia; |
|
} |
|
|
|
public override void OnLoaded() |
|
{ |
|
base.OnLoaded(); |
|
CheckHardwareBadge.RefreshCommand.ExecuteAsync(null).SafeFireAndForget(); |
|
} |
|
}
|
|
|