Skip to content

Commit

Permalink
Fix calling update notification from JS
Browse files Browse the repository at this point in the history
  • Loading branch information
codemonkey85 committed Nov 22, 2024
1 parent 989f1e8 commit f0df813
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 5 additions & 1 deletion Pkmds.Web/Services/AppService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace Pkmds.Web.Services;

public record AppService(IAppState AppState, IRefreshService RefreshService) : IAppService
public class AppService(IAppState appState, IRefreshService refreshService) : IAppService
{
private IAppState AppState { get; } = appState;

private IRefreshService RefreshService { get; } = refreshService;

private const string EnglishLang = "en";
private const string DefaultPkmFileName = "pkm.bin";

Expand Down
14 changes: 10 additions & 4 deletions Pkmds.Web/Services/RefreshService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
namespace Pkmds.Web.Services;

public record RefreshService(IAppState AppState) : IRefreshService
public class RefreshService : IRefreshService
{
public static RefreshService? Instance { get; private set; }

public event Action? OnAppStateChanged;
public event Action? OnBoxStateChanged;
public event Action? OnPartyStateChanged;
public event Action? OnUpdateAvailable;

public RefreshService() => Instance = this; // Set the singleton instance

[JSInvokable(nameof(ShowUpdateMessage))]
public static void ShowUpdateMessage() => Instance?.OnUpdateAvailable?.Invoke();

void IRefreshService.ShowUpdateMessage() => ShowUpdateMessage();

public void Refresh() => OnAppStateChanged?.Invoke();

public void RefreshBoxState() => OnBoxStateChanged?.Invoke();
Expand All @@ -18,7 +27,4 @@ public void RefreshBoxAndPartyState()
RefreshBoxState();
RefreshPartyState();
}

[JSInvokable("ShowUpdateMessage")]
public void ShowUpdateMessage() => OnUpdateAvailable?.Invoke();
}

0 comments on commit f0df813

Please sign in to comment.