using System.Windows.Input; using CommunityToolkit.Mvvm.Input; namespace Bit.App.Utilities { // TODO: [MAUI-Migration] DELETE WHEN MIGRATION IS DONE /// /// Wrapper of just to ease with the MAUI migration process. /// After the process is done, remove this and use AsyncRelayCommand directly /// public class AsyncCommand : ICommand { readonly AsyncRelayCommand _relayCommand; public AsyncCommand(Func execute, Func canExecute = null, Action onException = null, bool allowsMultipleExecutions = true) { async Task doAsync() { try { await execute?.Invoke(); } catch (Exception ex) { onException?.Invoke(ex); } } _relayCommand = new AsyncRelayCommand(doAsync, canExecute, allowsMultipleExecutions ? AsyncRelayCommandOptions.AllowConcurrentExecutions : AsyncRelayCommandOptions.None); } public event EventHandler CanExecuteChanged; public bool CanExecute(object parameter) => _relayCommand.CanExecute(parameter); public void Execute(object parameter) => _relayCommand.Execute(parameter); public void RaiseCanExecuteChanged() => _relayCommand.NotifyCanExecuteChanged(); } /// Wrapper of just to ease with the MAUI migration process. /// After the process is done, remove this and use AsyncRelayCommand directly /// public class AsyncCommand : ICommand { readonly AsyncRelayCommand _relayCommand; public AsyncCommand(Func execute, Predicate canExecute = null, Action onException = null, bool allowsMultipleExecutions = true) { async Task doAsync(T foo) { try { await execute?.Invoke(foo); } catch (Exception ex) { onException?.Invoke(ex); } } _relayCommand = new AsyncRelayCommand(doAsync, canExecute, allowsMultipleExecutions ? AsyncRelayCommandOptions.AllowConcurrentExecutions : AsyncRelayCommandOptions.None); } public event EventHandler CanExecuteChanged; public bool CanExecute(object parameter) => _relayCommand.CanExecute(parameter); public void Execute(object parameter) => _relayCommand.Execute(parameter); public void RaiseCanExecuteChanged() => _relayCommand.NotifyCanExecuteChanged(); } }