mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-06-28 15:26:24 +02:00

* misc: Move Ryujinx project to Ryujinx.Gtk3 This breaks release CI for now but that's fine. Signed-off-by: Mary Guillemard <mary@mary.zone> * misc: Move Ryujinx.Ava project to Ryujinx This breaks CI for now, but it's fine. Signed-off-by: Mary Guillemard <mary@mary.zone> * infra: Make Avalonia the default UI Should fix CI after the previous changes. GTK3 isn't build by the release job anymore, only by PR CI. This also ensure that the test-ava update package is still generated to allow update from the old testing channel. Signed-off-by: Mary Guillemard <mary@mary.zone> * Fix missing copy in create_app_bundle.sh Signed-off-by: Mary Guillemard <mary@mary.zone> * Fix syntax error Signed-off-by: Mary Guillemard <mary@mary.zone> --------- Signed-off-by: Mary Guillemard <mary@mary.zone>
71 lines
1.9 KiB
C#
71 lines
1.9 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Input;
|
|
|
|
namespace Ryujinx.Ava.UI.Helpers
|
|
{
|
|
public sealed class MiniCommand<T> : MiniCommand, ICommand
|
|
{
|
|
private readonly Action<T> _callback;
|
|
private bool _busy;
|
|
private readonly Func<T, Task> _asyncCallback;
|
|
|
|
public MiniCommand(Action<T> callback)
|
|
{
|
|
_callback = callback;
|
|
}
|
|
|
|
public MiniCommand(Func<T, Task> callback)
|
|
{
|
|
_asyncCallback = callback;
|
|
}
|
|
|
|
private bool Busy
|
|
{
|
|
get => _busy;
|
|
set
|
|
{
|
|
_busy = value;
|
|
CanExecuteChanged?.Invoke(this, EventArgs.Empty);
|
|
}
|
|
}
|
|
|
|
public override event EventHandler CanExecuteChanged;
|
|
public override bool CanExecute(object parameter) => !_busy;
|
|
|
|
public override async void Execute(object parameter)
|
|
{
|
|
if (Busy)
|
|
{
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
Busy = true;
|
|
if (_callback != null)
|
|
{
|
|
_callback((T)parameter);
|
|
}
|
|
else
|
|
{
|
|
await _asyncCallback((T)parameter);
|
|
}
|
|
}
|
|
finally
|
|
{
|
|
Busy = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
public abstract class MiniCommand : ICommand
|
|
{
|
|
public static MiniCommand Create(Action callback) => new MiniCommand<object>(_ => callback());
|
|
public static MiniCommand Create<TArg>(Action<TArg> callback) => new MiniCommand<TArg>(callback);
|
|
public static MiniCommand CreateFromTask(Func<Task> callback) => new MiniCommand<object>(_ => callback());
|
|
|
|
public abstract bool CanExecute(object parameter);
|
|
public abstract void Execute(object parameter);
|
|
public abstract event EventHandler CanExecuteChanged;
|
|
}
|
|
}
|