mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 11:14:45 +00:00
[Refactor] Update commands to use asynchronous patterns with ReactiveCommand
This commit is contained in:
@@ -117,6 +117,6 @@ public class App : Application
|
||||
})
|
||||
return;
|
||||
|
||||
mainWindowViewModel.ExecuteSettingsCommand();
|
||||
_ = mainWindowViewModel.ExecuteSettingsCommandAsync();
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
using System;
|
||||
using System.Reactive;
|
||||
using System.Threading.Tasks;
|
||||
using ReactiveUI;
|
||||
using RomRepoMgr.Core.EventArgs;
|
||||
using RomRepoMgr.Core.Models;
|
||||
@@ -61,7 +62,7 @@ public class EditDatViewModel : ViewModelBase
|
||||
_date = romSet.Date;
|
||||
_description = romSet.Description;
|
||||
_homepage = romSet.Homepage;
|
||||
SaveCommand = ReactiveCommand.Create(ExecuteSaveCommand);
|
||||
SaveCommand = ReactiveCommand.CreateFromTask(ExecuteSaveCommandAsync);
|
||||
CancelCommand = ReactiveCommand.Create(ExecuteCloseCommand);
|
||||
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
|
||||
}
|
||||
@@ -193,9 +194,9 @@ public class EditDatViewModel : ViewModelBase
|
||||
|
||||
void ExecuteCloseCommand() => _view.Close();
|
||||
|
||||
async void ExecuteSaveCommand()
|
||||
async Task ExecuteSaveCommandAsync()
|
||||
{
|
||||
using var ctx = Context.Create(Settings.Settings.Current.DatabasePath);
|
||||
await using var ctx = Context.Create(Settings.Settings.Current.DatabasePath);
|
||||
|
||||
RomSet romSetDb = await ctx.RomSets.FindAsync(_romSet.Id);
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
@@ -54,18 +55,18 @@ public class MainWindowViewModel : ViewModelBase
|
||||
{
|
||||
_view = view;
|
||||
ExitCommand = ReactiveCommand.Create(ExecuteExitCommand);
|
||||
SettingsCommand = ReactiveCommand.Create(ExecuteSettingsCommand);
|
||||
SettingsCommand = ReactiveCommand.CreateFromTask(ExecuteSettingsCommandAsync);
|
||||
AboutCommand = ReactiveCommand.Create(ExecuteAboutCommand);
|
||||
ImportDatCommand = ReactiveCommand.Create(ExecuteImportDatCommand);
|
||||
ImportDatFolderCommand = ReactiveCommand.Create(ExecuteImportDatFolderCommand);
|
||||
ImportRomFolderCommand = ReactiveCommand.Create(ExecuteImportRomFolderCommand);
|
||||
DeleteRomSetCommand = ReactiveCommand.Create(ExecuteDeleteRomSetCommand);
|
||||
ImportDatCommand = ReactiveCommand.CreateFromTask(ExecuteImportDatCommandAsync);
|
||||
ImportDatFolderCommand = ReactiveCommand.CreateFromTask(ExecuteImportDatFolderCommandAsync);
|
||||
ImportRomFolderCommand = ReactiveCommand.CreateFromTask(ExecuteImportRomFolderCommandAsync);
|
||||
DeleteRomSetCommand = ReactiveCommand.CreateFromTask(ExecuteDeleteRomSetCommandAsync);
|
||||
EditRomSetCommand = ReactiveCommand.Create(ExecuteEditRomSetCommand);
|
||||
ExportDatCommand = ReactiveCommand.Create(ExecuteExportDatCommand);
|
||||
ExportRomsCommand = ReactiveCommand.Create(ExecuteExportRomsCommand);
|
||||
MountCommand = ReactiveCommand.Create(ExecuteMountCommand);
|
||||
ExportDatCommand = ReactiveCommand.CreateFromTask(ExecuteExportDatCommandAsync);
|
||||
ExportRomsCommand = ReactiveCommand.CreateFromTask(ExecuteExportRomsCommandAsync);
|
||||
MountCommand = ReactiveCommand.CreateFromTask(ExecuteMountCommandAsync);
|
||||
UmountCommand = ReactiveCommand.Create(ExecuteUmountCommand);
|
||||
UpdateStatsCommand = ReactiveCommand.Create(ExecuteUpdateStatsCommand);
|
||||
UpdateStatsCommand = ReactiveCommand.CreateFromTask(ExecuteUpdateStatsCommandAsync);
|
||||
RomSets = new ObservableCollection<RomSetModel>(romSets);
|
||||
}
|
||||
|
||||
@@ -135,11 +136,12 @@ public class MainWindowViewModel : ViewModelBase
|
||||
set => this.RaiseAndSetIfChanged(ref _selectedRomSet, value);
|
||||
}
|
||||
|
||||
internal async void ExecuteSettingsCommand()
|
||||
internal Task ExecuteSettingsCommandAsync()
|
||||
{
|
||||
var dialog = new SettingsDialog();
|
||||
dialog.DataContext = new SettingsViewModel(dialog);
|
||||
await dialog.ShowDialog(_view);
|
||||
|
||||
return dialog.ShowDialog(_view);
|
||||
}
|
||||
|
||||
internal void ExecuteExitCommand() =>
|
||||
@@ -152,7 +154,7 @@ public class MainWindowViewModel : ViewModelBase
|
||||
_ = dialog.ShowDialog(_view);
|
||||
}
|
||||
|
||||
async void ExecuteImportDatCommand()
|
||||
async Task ExecuteImportDatCommandAsync()
|
||||
{
|
||||
var dlgOpen = new OpenFileDialog
|
||||
{
|
||||
@@ -180,13 +182,13 @@ public class MainWindowViewModel : ViewModelBase
|
||||
var importDatViewModel = new ImportDatViewModel(dialog, result[0]);
|
||||
importDatViewModel.RomSetAdded += ImportDatViewModelOnRomSetAdded;
|
||||
dialog.DataContext = importDatViewModel;
|
||||
await dialog.ShowDialog(_view);
|
||||
_ = dialog.ShowDialog(_view);
|
||||
}
|
||||
|
||||
void ImportDatViewModelOnRomSetAdded(object sender, RomSetEventArgs e) =>
|
||||
Dispatcher.UIThread.Post(() => RomSets.Add(e.RomSet));
|
||||
|
||||
async void ExecuteImportDatFolderCommand()
|
||||
async Task ExecuteImportDatFolderCommandAsync()
|
||||
{
|
||||
var dlgOpen = new OpenFolderDialog
|
||||
{
|
||||
@@ -201,10 +203,10 @@ public class MainWindowViewModel : ViewModelBase
|
||||
var importDatFolderViewModel = new ImportDatFolderViewModel(dialog, result);
|
||||
importDatFolderViewModel.RomSetAdded += ImportDatViewModelOnRomSetAdded;
|
||||
dialog.DataContext = importDatFolderViewModel;
|
||||
await dialog.ShowDialog(_view);
|
||||
_ = dialog.ShowDialog(_view);
|
||||
}
|
||||
|
||||
async void ExecuteImportRomFolderCommand()
|
||||
async Task ExecuteImportRomFolderCommandAsync()
|
||||
{
|
||||
var dlgOpen = new OpenFolderDialog
|
||||
{
|
||||
@@ -218,10 +220,10 @@ public class MainWindowViewModel : ViewModelBase
|
||||
var dialog = new ImportRomFolder();
|
||||
var importRomFolderViewModel = new ImportRomFolderViewModel(dialog, result);
|
||||
dialog.DataContext = importRomFolderViewModel;
|
||||
await dialog.ShowDialog(_view);
|
||||
_ = dialog.ShowDialog(_view);
|
||||
}
|
||||
|
||||
async void ExecuteDeleteRomSetCommand()
|
||||
async Task ExecuteDeleteRomSetCommandAsync()
|
||||
{
|
||||
if(SelectedRomSet == null) return;
|
||||
|
||||
@@ -266,7 +268,7 @@ public class MainWindowViewModel : ViewModelBase
|
||||
window.Show();
|
||||
}
|
||||
|
||||
async void ExecuteExportDatCommand()
|
||||
async Task ExecuteExportDatCommandAsync()
|
||||
{
|
||||
if(SelectedRomSet == null) return;
|
||||
|
||||
@@ -282,10 +284,10 @@ public class MainWindowViewModel : ViewModelBase
|
||||
var dialog = new ExportDat();
|
||||
var viewModel = new ExportDatViewModel(dialog, SelectedRomSet.Sha384, result);
|
||||
dialog.DataContext = viewModel;
|
||||
await dialog.ShowDialog(_view);
|
||||
_ = dialog.ShowDialog(_view);
|
||||
}
|
||||
|
||||
async void ExecuteExportRomsCommand()
|
||||
async Task ExecuteExportRomsCommandAsync()
|
||||
{
|
||||
var dlgOpen = new OpenFolderDialog
|
||||
{
|
||||
@@ -299,10 +301,10 @@ public class MainWindowViewModel : ViewModelBase
|
||||
var dialog = new ExportRoms();
|
||||
var viewModel = new ExportRomsViewModel(dialog, result, SelectedRomSet.Id);
|
||||
dialog.DataContext = viewModel;
|
||||
await dialog.ShowDialog(_view);
|
||||
_ = dialog.ShowDialog(_view);
|
||||
}
|
||||
|
||||
async void ExecuteMountCommand()
|
||||
async Task ExecuteMountCommandAsync()
|
||||
{
|
||||
if(Vfs != null) return;
|
||||
|
||||
@@ -333,7 +335,7 @@ public class MainWindowViewModel : ViewModelBase
|
||||
|
||||
void ExecuteUmountCommand() => Vfs?.Umount();
|
||||
|
||||
async void ExecuteUpdateStatsCommand()
|
||||
async Task ExecuteUpdateStatsCommandAsync()
|
||||
{
|
||||
ButtonResult result = await MessageBoxManager
|
||||
.GetMessageBoxStandard(Localization.DatabaseMenuUpdateStatsText,
|
||||
@@ -347,6 +349,6 @@ public class MainWindowViewModel : ViewModelBase
|
||||
var view = new UpdateStats();
|
||||
var viewModel = new UpdateStatsViewModel(view);
|
||||
view.DataContext = viewModel;
|
||||
await view.ShowDialog(_view);
|
||||
_ = view.ShowDialog(_view);
|
||||
}
|
||||
}
|
||||
@@ -64,10 +64,10 @@ public sealed class SettingsViewModel : ViewModelBase
|
||||
_unArChanged = false;
|
||||
|
||||
CloseCommand = ReactiveCommand.Create(ExecuteCloseCommand);
|
||||
UnArCommand = ReactiveCommand.Create(ExecuteUnArCommand);
|
||||
TemporaryCommand = ReactiveCommand.Create(ExecuteTemporaryCommand);
|
||||
RepositoryCommand = ReactiveCommand.Create(ExecuteRepositoryCommand);
|
||||
DatabaseCommand = ReactiveCommand.Create(ExecuteDatabaseCommand);
|
||||
UnArCommand = ReactiveCommand.CreateFromTask(ExecuteUnArCommandAsync);
|
||||
TemporaryCommand = ReactiveCommand.CreateFromTask(ExecuteTemporaryCommandAsync);
|
||||
RepositoryCommand = ReactiveCommand.CreateFromTask(ExecuteRepositoryCommandAsync);
|
||||
DatabaseCommand = ReactiveCommand.CreateFromTask(ExecuteDatabaseCommandAsync);
|
||||
SaveCommand = ReactiveCommand.Create(ExecuteSaveCommand);
|
||||
|
||||
DatabasePath = Settings.Settings.Current.DatabasePath;
|
||||
@@ -149,13 +149,13 @@ public sealed class SettingsViewModel : ViewModelBase
|
||||
_ = Task.Run(() => worker.CheckUnAr(UnArPath));
|
||||
}
|
||||
|
||||
async void CheckUnArFailed(object sender, ErrorEventArgs args)
|
||||
void CheckUnArFailed(object sender, ErrorEventArgs args)
|
||||
{
|
||||
UnArVersion = "";
|
||||
UnArPath = "";
|
||||
|
||||
await MessageBoxManager.GetMessageBoxStandard(Localization.Error, $"{args.Message}", ButtonEnum.Ok, Icon.Error)
|
||||
.ShowWindowDialogAsync(_view);
|
||||
_ = MessageBoxManager.GetMessageBoxStandard(Localization.Error, $"{args.Message}", ButtonEnum.Ok, Icon.Error)
|
||||
.ShowWindowDialogAsync(_view);
|
||||
}
|
||||
|
||||
void CheckUnArFinished(object sender, MessageEventArgs args) => Dispatcher.UIThread.Post(() =>
|
||||
@@ -166,7 +166,7 @@ public sealed class SettingsViewModel : ViewModelBase
|
||||
|
||||
void ExecuteCloseCommand() => _view.Close();
|
||||
|
||||
async void ExecuteUnArCommand()
|
||||
async Task ExecuteUnArCommandAsync()
|
||||
{
|
||||
var dlgFile = new OpenFileDialog
|
||||
{
|
||||
@@ -185,7 +185,7 @@ public sealed class SettingsViewModel : ViewModelBase
|
||||
CheckUnAr();
|
||||
}
|
||||
|
||||
async void ExecuteTemporaryCommand()
|
||||
async Task ExecuteTemporaryCommandAsync()
|
||||
{
|
||||
var dlgFolder = new OpenFolderDialog
|
||||
{
|
||||
@@ -199,7 +199,7 @@ public sealed class SettingsViewModel : ViewModelBase
|
||||
TemporaryPath = result;
|
||||
}
|
||||
|
||||
async void ExecuteRepositoryCommand()
|
||||
async Task ExecuteRepositoryCommandAsync()
|
||||
{
|
||||
var dlgFolder = new OpenFolderDialog
|
||||
{
|
||||
@@ -213,7 +213,7 @@ public sealed class SettingsViewModel : ViewModelBase
|
||||
RepositoryPath = result;
|
||||
}
|
||||
|
||||
async void ExecuteDatabaseCommand()
|
||||
async Task ExecuteDatabaseCommandAsync()
|
||||
{
|
||||
var dlgFile = new SaveFileDialog
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user