Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
fix(engines): let other engines queue while one installs (#819)
cre8ive-marketing8ce1b7e5c883
diff --git a/src/Filee.App/Services/EngineDownloadService.cs b/src/Filee.App/Services/EngineDownloadService.csindex 23ba1e95..d8572332 100644--- a/src/Filee.App/Services/EngineDownloadService.cs+++ b/src/Filee.App/Services/EngineDownloadService.cs@@ -180,6 +180,9 @@ public sealed class EngineDownloadServiceprivate readonly SemaphoreSlim _oneAtATime = new(1, 1);private int _warmingUp;+ /// <summary>Downloads and unpacks one package; tests swap it to hold an install open.</summary>+ internal Func<EnginePackage, IProgress<EngineInstallProgress>, CancellationToken, Task> InstallPackage { get; set; }+public EngineDownloadService(ConverterCatalog catalog, ILocalizer loc, ILogger<EngineDownloadService> logger){_catalog = catalog;@@ -189,6 +192,7 @@ public sealed class EngineDownloadServicevar http = new HttpClient(new SocketsHttpHandler { AllowAutoRedirect = false }) { Timeout = Timeout.InfiniteTimeSpan };http.DefaultRequestHeaders.UserAgent.ParseAdd($"Filee/{typeof(EngineDownloadService).Assembly.GetName().Version}");_installer = new EngineInstaller(http, logger: logger);+ InstallPackage = _installer.InstallAsync;Packages = EngineDownloads.Packages.Select(p => new EnginePackageState(p, loc)).ToList();if (loc is LocalizationService localization)localization.LanguageChanged += (_, _) => Packages.ToList().ForEach(p => p.Relocalize());@@ -278,7 +282,7 @@ public sealed class EngineDownloadServicestate.ProgressDetail = "";}});- await Task.Run(() => _installer.InstallAsync(state.Package, progress, cancellation.Token), cancellation.Token);+ await Task.Run(() => InstallPackage(state.Package, progress, cancellation.Token), cancellation.Token);}finally{diff --git a/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs b/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.csindex f04bbdce..65c8ccaf 100644--- a/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs+++ b/src/Filee.App/ViewModels/Pages/EnginesPageViewModel.cs@@ -112,7 +112,8 @@ public sealed partial class EnginesPageViewModel : ObservableObject, IDisposablepublic ObservableCollection<EngineItemViewModel> Engines { get; } = [];- [RelayCommand]+ // Any number of rows can be clicked; the service queues them and installs one at a time (#819).+ [RelayCommand(AllowConcurrentExecutions = true)]private Task Install(EnginePackageState package) => _downloads.InstallAsync(package);[RelayCommand]diff --git a/tests/Filee.App.Tests/EnginesPageTests.cs b/tests/Filee.App.Tests/EnginesPageTests.csindex bc6df23e..60d32033 100644--- a/tests/Filee.App.Tests/EnginesPageTests.cs+++ b/tests/Filee.App.Tests/EnginesPageTests.cs@@ -12,8 +12,11 @@ using Filee.App.ViewModels;using Filee.App.ViewModels.Pages;using Filee.App.Views;using Filee.App.Views.Pages;+using Filee.Core.Conversion;using Filee.Core.Localization;using Filee.Core.Settings;+using Filee.Engines.Infrastructure;+using Microsoft.Extensions.Logging.Abstractions;namespace Filee.App.Tests;@@ -169,4 +172,55 @@ public class EnginesPageTestsvm.Dispose();}}++ [AvaloniaFact]+ public void A_second_engine_can_be_installed_while_one_downloads_and_waits_its_turn()+ {+ // #819: one install running must not turn off the Install button on the other cards.+ TestServices.EnsureInitialized("en");+ var downloads = new EngineDownloadService(AppHost.Get<ConverterCatalog>(), AppHost.Get<ILocalizer>(), NullLogger<EngineDownloadService>.Instance);+ var started = new List<string>();+ downloads.InstallPackage = (package, _, token) =>+ {+ Dispatcher.UIThread.Post(() => started.Add(package.Id));+ return Task.Delay(Timeout.Infinite, token);+ };+ var vm = new EnginesPageViewModel(AppHost.Get<UserDataStore>(), AppHost.Get<ConverterCatalog>(), AppHost.Get<ILocalizer>(), downloads);+ var (first, second) = (downloads.Packages.Where(p => p.CanInstall).ElementAt(0), downloads.Packages.Where(p => p.CanInstall).ElementAt(1));+ try+ {+ vm.InstallCommand.Execute(first);+ for (var i = 0; i < 200 && started.Count == 0; i++)+ {+ Thread.Sleep(10);+ Pump();+ }+ Assert.Equal([first.Package.Id], started);+ Assert.True(first.IsBusy);++ Assert.True(vm.InstallCommand.CanExecute(second));+ vm.InstallCommand.Execute(second);+ Pump();+ Assert.Equal(EnginePackageStatus.Queued, second.Status);+ Assert.Equal([first.Package.Id], started); // waits for the first one++ // Cancel on the first card stops only the first; the second then gets its turn.+ vm.CancelCommand.Execute(first);+ for (var i = 0; i < 200 && started.Count < 2; i++)+ {+ Thread.Sleep(10);+ Pump();+ }+ Assert.False(first.IsBusy);+ Assert.True(second.IsBusy);+ Assert.Equal([first.Package.Id, second.Package.Id], started);+ }+ finally+ {+ downloads.Cancel(first);+ downloads.Cancel(second);+ Pump();+ vm.Dispose();+ }+ }}