0
0
mirror of https://github.com/sp-tarkov/launcher.git synced 2025-02-13 09:50:43 -05:00
launcher/project/SPT.Launcher/ViewModels/MainWindowViewModel.cs

94 lines
3.1 KiB
C#
Raw Normal View History

2023-03-03 19:25:33 +00:00
using Avalonia;
using ReactiveUI;
using System.Reactive.Disposables;
2024-05-21 20:15:19 +01:00
using SPT.Launcher.Models;
using SPT.Launcher.MiniCommon;
2023-03-03 19:25:33 +00:00
using System.IO;
using Splat;
2024-05-21 20:15:19 +01:00
using SPT.Launcher.Models.SPT;
using SPT.Launcher.Helpers;
using SPT.Launcher.ViewModels.Dialogs;
using Avalonia.Threading;
2024-07-06 11:48:16 -04:00
using DialogHostAvalonia;
2023-03-03 19:25:33 +00:00
2024-05-21 20:15:19 +01:00
namespace SPT.Launcher.ViewModels
2023-03-03 19:25:33 +00:00
{
public class MainWindowViewModel : ReactiveObject, IActivatableViewModel, IScreen
{
2024-05-21 20:15:19 +01:00
public SPTVersion VersionInfo { get; set; } = new SPTVersion();
2023-03-03 19:25:33 +00:00
public RoutingState Router { get; } = new RoutingState();
public ViewModelActivator Activator { get; } = new ViewModelActivator();
public ImageHelper Background { get; } = new ImageHelper()
{
Path = Path.Join(ImageRequest.ImageCacheFolder, "bg.png")
};
public MainWindowViewModel()
{
Locator.CurrentMutable.RegisterConstant<ImageHelper>(Background, "bgimage");
2024-05-21 20:15:19 +01:00
Locator.CurrentMutable.RegisterConstant<SPTVersion>(VersionInfo, "sptversion");
2024-06-02 14:46:53 -04:00
LauncherSettingsProvider.Instance.ResetDefaults();
2023-03-03 19:25:33 +00:00
LauncherSettingsProvider.Instance.AllowSettings = true;
if (LauncherSettingsProvider.Instance.FirstRun)
{
Dispatcher.UIThread.InvokeAsync(async () =>
{
LauncherSettingsProvider.Instance.FirstRun = false;
LocalizationProvider.TryAutoSetLocale();
var viewModel = new ConfirmationDialogViewModel(this,
LocalizationProvider.Instance.copy_live_settings_question,
LocalizationProvider.Instance.yes,
LocalizationProvider.Instance.no);
2024-07-06 11:48:16 -04:00
var confirmCopySettings = await DialogHost.Show(viewModel);
if (confirmCopySettings is bool and true)
{
var settingsVm = new SettingsViewModel(this);
await settingsVm.ResetGameSettingsCommand();
}
LauncherSettingsProvider.Instance.SaveSettings();
});
}
2023-03-03 19:25:33 +00:00
this.WhenActivated((CompositeDisposable disposables) =>
{
Router.Navigate.Execute(new ConnectServerViewModel(this));
});
}
public void CloseCommand()
{
if (Application.Current.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktopApp)
{
desktopApp.MainWindow.Close();
}
}
public void MinimizeCommand()
{
if (Application.Current.ApplicationLifetime is Avalonia.Controls.ApplicationLifetimes.IClassicDesktopStyleApplicationLifetime desktopApp)
{
desktopApp.MainWindow.WindowState = Avalonia.Controls.WindowState.Minimized;
}
}
public void GoToSettingsCommand()
{
LauncherSettingsProvider.Instance.AllowSettings = false;
Router.Navigate.Execute(new SettingsViewModel(this));
}
}
}