client(ui): migrate to mvvm
This commit is contained in:
51
ModpackUpdater.Apps.Client.Gui/MainView.axaml.cs
Normal file
51
ModpackUpdater.Apps.Client.Gui/MainView.axaml.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System.Reflection;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.Threading;
|
||||
using ModpackUpdater.Apps.Client.Gui.LangRes;
|
||||
using Pilz.Extensions;
|
||||
using Pilz.UI.Symbols;
|
||||
|
||||
namespace ModpackUpdater.Apps.Client.Gui;
|
||||
|
||||
public partial class MainView : Window
|
||||
{
|
||||
public MainViewModel Model => DataContext as MainViewModel ?? throw new NullReferenceException();
|
||||
|
||||
public MainView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Title = $"{Title} (v{Assembly.GetExecutingAssembly().GetAppVersion().ToShortString()})";
|
||||
|
||||
ButtonSearchProfileFolder.ImageSource = AppGlobals.Symbols.GetImageSource(AppSymbols.opened_folder);
|
||||
ButtonCheckForUpdates.ImageSource = AppGlobals.Symbols.GetImageSource(AppSymbols.update_done);
|
||||
ButtonInstall.ImageSource = AppGlobals.Symbols.GetImageSource(AppSymbols.software_installer);
|
||||
MenuItemRepair.Icon = AppGlobals.Symbols.GetImage(AppSymbols.wrench, SymbolSize.Small);
|
||||
}
|
||||
|
||||
private async void InitializeViewModel()
|
||||
{
|
||||
await Model.CheckForUpdates(this);
|
||||
await Model.Initialize();
|
||||
}
|
||||
|
||||
private void Control_OnLoaded(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Post(InitializeViewModel, DispatcherPriority.Background);
|
||||
}
|
||||
|
||||
private async void ButtonSearchProfileFolder_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
var filePaths = await StorageProvider.OpenFolderPickerAsync(new FolderPickerOpenOptions
|
||||
{
|
||||
Title = GeneralLangRes.SelectMinecraftProfileFolder,
|
||||
SuggestedStartLocation = await StorageProvider.TryGetFolderFromPathAsync(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)),
|
||||
AllowMultiple = false,
|
||||
});
|
||||
|
||||
if (filePaths.Count >= 1)
|
||||
Model.MinecraftProfileFolder = filePaths[0].Path.AbsolutePath;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user