2024-07-14 11:24:10 +00:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using CommunityToolkit.Mvvm.Input;
|
|
|
|
|
|
|
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
|
|
|
|
|
using RustTools.Contracts.Services;
|
|
|
|
|
using RustTools.Helpers;
|
|
|
|
|
|
|
|
|
|
using Windows.ApplicationModel;
|
2024-07-28 13:33:21 +00:00
|
|
|
|
using Windows.Storage.AccessCache;
|
|
|
|
|
using Windows.Storage.Pickers;
|
|
|
|
|
using Windows.Storage;
|
2024-08-05 11:38:55 +00:00
|
|
|
|
using RustTools.muqing;
|
2024-07-14 11:24:10 +00:00
|
|
|
|
|
|
|
|
|
namespace RustTools.ViewModels;
|
|
|
|
|
|
|
|
|
|
public partial class SettingsViewModel : ObservableRecipient
|
|
|
|
|
{
|
|
|
|
|
private readonly IThemeSelectorService _themeSelectorService;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private ElementTheme _elementTheme;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private string _versionDescription;
|
|
|
|
|
|
|
|
|
|
public ICommand SwitchThemeCommand
|
|
|
|
|
{
|
|
|
|
|
get;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-28 13:33:21 +00:00
|
|
|
|
|
2024-07-14 11:24:10 +00:00
|
|
|
|
public SettingsViewModel(IThemeSelectorService themeSelectorService)
|
|
|
|
|
{
|
|
|
|
|
_themeSelectorService = themeSelectorService;
|
|
|
|
|
_elementTheme = _themeSelectorService.Theme;
|
|
|
|
|
_versionDescription = GetVersionDescription();
|
|
|
|
|
|
|
|
|
|
SwitchThemeCommand = new RelayCommand<ElementTheme>(
|
|
|
|
|
async (param) =>
|
|
|
|
|
{
|
|
|
|
|
if (ElementTheme != param)
|
|
|
|
|
{
|
|
|
|
|
ElementTheme = param;
|
|
|
|
|
await _themeSelectorService.SetThemeAsync(param);
|
|
|
|
|
}
|
|
|
|
|
});
|
2024-07-28 13:33:21 +00:00
|
|
|
|
|
|
|
|
|
|
2024-07-14 11:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetVersionDescription()
|
|
|
|
|
{
|
|
|
|
|
Version version;
|
|
|
|
|
|
|
|
|
|
if (RuntimeHelper.IsMSIX)
|
|
|
|
|
{
|
|
|
|
|
var packageVersion = Package.Current.Id.Version;
|
|
|
|
|
|
|
|
|
|
version = new(packageVersion.Major, packageVersion.Minor, packageVersion.Build, packageVersion.Revision);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
version = Assembly.GetExecutingAssembly().GetName().Version!;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $"{"AppDisplayName".GetLocalized()} - {version.Major}.{version.Minor}.{version.Build}.{version.Revision}";
|
|
|
|
|
}
|
2024-07-28 13:33:21 +00:00
|
|
|
|
|
2024-07-14 11:24:10 +00:00
|
|
|
|
}
|