From bf4b63a6397479b6038a7a69bd594b76d48d3df0 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Wed, 18 Dec 2024 18:01:06 +0700 Subject: [PATCH] introduce DurableInvoke helper which uses a method defined on window in index which will always be there, to call methods which might not always be there --- backend/FwLite/FwLiteDesktop/wwwroot/index.html | 9 ++++++--- backend/FwLite/FwLiteShared/JsInteropInvokeHelper.cs | 11 +++++++++++ backend/FwLite/FwLiteShared/Routes.razor | 2 +- .../FwLite/FwLiteShared/Services/FwLiteProvider.cs | 4 ++-- backend/FwLite/LocalWebApp/Components/App.razor | 10 ++++++++++ 5 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 backend/FwLite/FwLiteShared/JsInteropInvokeHelper.cs diff --git a/backend/FwLite/FwLiteDesktop/wwwroot/index.html b/backend/FwLite/FwLiteDesktop/wwwroot/index.html index cd909c837..7822cd2e9 100644 --- a/backend/FwLite/FwLiteDesktop/wwwroot/index.html +++ b/backend/FwLite/FwLiteDesktop/wwwroot/index.html @@ -7,10 +7,13 @@ diff --git a/backend/FwLite/FwLiteShared/JsInteropInvokeHelper.cs b/backend/FwLite/FwLiteShared/JsInteropInvokeHelper.cs new file mode 100644 index 000000000..2380fd9b4 --- /dev/null +++ b/backend/FwLite/FwLiteShared/JsInteropInvokeHelper.cs @@ -0,0 +1,11 @@ +using Microsoft.JSInterop; + +namespace FwLiteShared; + +public static class JsInteropInvokeHelper +{ + public static async ValueTask DurableInvokeVoidAsync(this IJSRuntime jsRuntime, string identifier, params object?[] args) + { + await jsRuntime.InvokeVoidAsync("invokeOnWindow", identifier, args); + } +} diff --git a/backend/FwLite/FwLiteShared/Routes.razor b/backend/FwLite/FwLiteShared/Routes.razor index 2613ad901..00e759ac5 100644 --- a/backend/FwLite/FwLiteShared/Routes.razor +++ b/backend/FwLite/FwLiteShared/Routes.razor @@ -2,7 +2,7 @@ @code { private async Task OnNavigateAsync(NavigationContext context) { - await jsRuntime.InvokeVoidAsync("onBlazorNavigate", context.Path); + await jsRuntime.DurableInvokeVoidAsync("svelteNavigate", context.Path); } } diff --git a/backend/FwLite/FwLiteShared/Services/FwLiteProvider.cs b/backend/FwLite/FwLiteShared/Services/FwLiteProvider.cs index d7408d26b..cfd2ad81a 100644 --- a/backend/FwLite/FwLiteShared/Services/FwLiteProvider.cs +++ b/backend/FwLite/FwLiteShared/Services/FwLiteProvider.cs @@ -66,7 +66,7 @@ public object GetService(DotnetService service) logger.LogInformation("Clearing Service {Service}", service); } - await jsRuntime.InvokeVoidAsync(OverrideServiceFunctionName, service.ToString(), reference); + await jsRuntime.DurableInvokeVoidAsync(OverrideServiceFunctionName, service.ToString(), reference); return reference; } @@ -79,7 +79,7 @@ public async Task InjectCrdtProject(IJSRuntime jsRuntime, await lexboxProjectService.ListenForProjectChanges(projectData, CancellationToken.None); var entryUpdatedSubscription = changeEventBus.OnProjectEntryUpdated(project).Subscribe(entry => { - _ = jsRuntime.InvokeVoidAsync("notifyEntryUpdated", projectName, entry); + _ = jsRuntime.DurableInvokeVoidAsync("notifyEntryUpdated", projectName, entry); }); var service = ActivatorUtilities.CreateInstance(scopedServices, project); var reference = await SetService(jsRuntime,DotnetService.MiniLcmApi, service); diff --git a/backend/FwLite/LocalWebApp/Components/App.razor b/backend/FwLite/LocalWebApp/Components/App.razor index 3e74742c0..61ad16ed7 100644 --- a/backend/FwLite/LocalWebApp/Components/App.razor +++ b/backend/FwLite/LocalWebApp/Components/App.razor @@ -7,6 +7,16 @@ +