Crunchy-Downloader/CRD/ViewModels/MainWindowViewModel.cs
2024-05-05 18:03:07 +02:00

50 lines
1.4 KiB
C#

using System;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Media;
using Avalonia.Styling;
using CommunityToolkit.Mvvm.ComponentModel;
using CRD.Downloader;
using CRD.Utils.Updater;
using FluentAvalonia.Styling;
using Newtonsoft.Json;
namespace CRD.ViewModels;
public partial class MainWindowViewModel : ViewModelBase{
private readonly FluentAvaloniaTheme _faTheme;
[ObservableProperty]
private bool _updateAvailable = true;
public MainWindowViewModel(){
_faTheme = App.Current.Styles[0] as FluentAvaloniaTheme;
Init();
}
public async void Init(){
UpdateAvailable = await Updater.Instance.CheckForUpdatesAsync();
await Crunchyroll.Instance.Init();
if (Crunchyroll.Instance.CrunOptions.AccentColor != null){
_faTheme.CustomAccentColor = Color.Parse(Crunchyroll.Instance.CrunOptions.AccentColor);
}
if (Crunchyroll.Instance.CrunOptions.Theme == "System"){
_faTheme.PreferSystemTheme = true;
} else if (Crunchyroll.Instance.CrunOptions.Theme == "Dark"){
_faTheme.PreferSystemTheme = false;
Application.Current.RequestedThemeVariant = ThemeVariant.Dark;
} else{
_faTheme.PreferSystemTheme = false;
Application.Current.RequestedThemeVariant = ThemeVariant.Light;
}
}
}