Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
プログレスバーを更新できるように修正
Browse files Browse the repository at this point in the history
  • Loading branch information
miyaji255 committed Feb 21, 2024
1 parent 4dd4144 commit 5bbfa1c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 31 deletions.
16 changes: 16 additions & 0 deletions KoeBook.Core/Contracts/Services/IDisplayStateChangeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using KoeBook.Core.Models;

namespace KoeBook.Core.Contracts.Services;

public interface IDisplayStateChangeService
{
/// <summary>
/// 状態を更新します
/// </summary>
void UpdateState(BookProperties bookProperties, GenerationState state);

/// <summary>
/// プログレスバーを更新します
/// </summary>
void UpdateProgress(BookProperties bookProperties, int progress, int maximum);
}
11 changes: 0 additions & 11 deletions KoeBook.Core/Contracts/Services/INotifyStateChangedService.cs

This file was deleted.

2 changes: 1 addition & 1 deletion KoeBook/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public App()
services.AddSingleton<IPageService, PageService>();
services.AddSingleton<INavigationService, NavigationService>();
services.AddSingleton<IDialogService, DialogService>();
services.AddSingleton<INotifyStateChangedService, NotifyStateChangedService>();
services.AddSingleton<IDisplayStateChangeService, DisplayStateChangeService>();

// Core Services
services.AddSingleton<IFileService, FileService>();
Expand Down
4 changes: 4 additions & 0 deletions KoeBook/KoeBook.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>

<ItemGroup>
<Folder Include="Services\CoreMocks\" />
</ItemGroup>

<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
Expand Down
30 changes: 30 additions & 0 deletions KoeBook/Services/DisplayStateChangeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using KoeBook.Contracts.Services;
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Models;

namespace KoeBook.Services;

internal class DisplayStateChangeService(IGenerationTaskService taskService) : IDisplayStateChangeService
{
private readonly IGenerationTaskService _taskService = taskService;

public void UpdateProgress(BookProperties bookProperties, int progress, int maximum)
{
var taskService = _taskService; // thisをキャプチャしないようにする
_ = App.MainWindow.DispatcherQueue.TryEnqueue(() =>
{
var task = taskService.GetProcessingTask(bookProperties.Id);
task.MaximumProgress = maximum;
task.Progress = progress;
});
}

public void UpdateState(BookProperties bookProperties, GenerationState state)
{
var taskService = _taskService; // thisをキャプチャしないようにする
_ = App.MainWindow.DispatcherQueue.TryEnqueue(() =>
{
taskService.GetProcessingTask(bookProperties.Id).State = state;
});
}
}
19 changes: 0 additions & 19 deletions KoeBook/Services/NotifyStateChangedService.cs

This file was deleted.

0 comments on commit 5bbfa1c

Please sign in to comment.