Skip to content

Commit

Permalink
Minor code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sungaila committed Sep 6, 2023
1 parent 78de437 commit 09ca297
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/WebConverter/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using KristofferStrube.Blazor.FileSystem;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -14,7 +13,7 @@ namespace PDFtoImage.WebConverter
{
public class Program
{
public static event EventHandler<HandledFileArgs>? FilesHandled;
public static event EventHandler<HandledFileEventArgs>? FilesHandled;

public static async Task Main(string[] args)
{
Expand All @@ -27,7 +26,6 @@ public static async Task Main(string[] args)
builder.Services.AddWebShareService();

var host = builder.Build();
var navigationManager = host.Services.GetService<NavigationManager>()!;

if (host.Services.GetService<FileHandlingService>() is FileHandlingService service && await service.IsSupportedAsync())
{
Expand All @@ -38,19 +36,19 @@ await service.SetConsumerAsync(async (launchParams) =>
if (launchParams.Files[0] is FileSystemFileHandle fileSystemFileHandle)
{
FilesHandled?.Invoke(null, new HandledFileArgs(await fileSystemFileHandle.GetFileAsync()));
FilesHandled?.Invoke(null, new HandledFileEventArgs(await fileSystemFileHandle.GetFileAsync()));
}
});
}

await host.RunAsync();
}

public class HandledFileArgs : EventArgs
public class HandledFileEventArgs : EventArgs
{
public KristofferStrube.Blazor.FileAPI.File File { get; }

public HandledFileArgs(KristofferStrube.Blazor.FileAPI.File file)
public HandledFileEventArgs(KristofferStrube.Blazor.FileAPI.File file)
{
File = file;
}
Expand Down
3 changes: 1 addition & 2 deletions src/WebConverter/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
@using Thinktecture.Blazor.WebShare.Models;
@inject ILogger<Index> Logger
@inject IJSRuntime JS
@inject NavigationManager NavigationManager;
@inject WebShareService WebShareService;
@inject WebShareService WebShareService

<PageTitle>Conversion</PageTitle>

Expand Down
6 changes: 3 additions & 3 deletions src/WebConverter/Pages/Index.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private async Task SetupDotNetHelper()
await JS.InvokeAsync<string>("setDotNetHelper", _objRef);
}

private async void OnFilesHandled(object? sender, Program.HandledFileArgs args)
private async void OnFilesHandled(object? sender, Program.HandledFileEventArgs args)
{
if (args.File == null)
return;
Expand Down Expand Up @@ -136,7 +136,7 @@ private async Task Submit()
SKBitmap? bitmap = null;
bool encodeSuccess = false;

await Task.Run(() =>
await Task.Factory.StartNew(() =>
{
bitmap = PDFtoImage.Conversion.ToImage(
Model.Input,
Expand All @@ -153,7 +153,7 @@ await Task.Run(() =>
);
encodeSuccess = bitmap!.Encode(Model.Output, Model.Format, Model.Quality);
});
}, TaskCreationOptions.LongRunning);

if (!encodeSuccess)
{
Expand Down

0 comments on commit 09ca297

Please sign in to comment.