using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using InABox.Avalonia.Platform.Barcodes; using Microsoft.Maui.Devices; using PRS.Avalonia.Modules; using System; using System.Collections.Generic; using System.Threading.Tasks; namespace PRS.Avalonia.Components; public partial class ScannerViewModel : ModuleViewModel { public override string Title => "Equipment Scanner"; [ObservableProperty] private bool _cameraEnabled; [ObservableProperty] private bool _processing; [ObservableProperty] private Func, Task>? _itemScanned; public ScannerViewModel() { } protected override Task OnActivated() { CameraEnabled = true; return base.OnActivated(); } protected override Task OnDeactivated() { CameraEnabled = false; return base.OnDeactivated(); } [RelayCommand] private async Task DetectionFinished(IReadOnlySet result) { if(result.Count > 0) { if (Processing || !CameraEnabled) return; Processing = true; if(ItemScanned != null) { if(await ItemScanned.Invoke(result)) { CameraEnabled = false; } } Processing = false; } } }