Skip to content

Commit ad103f8

Browse files
committed
Added OnServiceWorkerUpdateFound event to WebWorkerService to address issue #5.
1 parent 7e6ba43 commit ad103f8

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

SpawnDev.BlazorJS.WebWorkers/WebWorkerService.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ public void SendEventToParents(string eventName, params object?[]? data)
388388
}
389389
}
390390
/// <summary>
391+
/// The updatefound event of the ServiceWorkerRegistration interface is fired any time the ServiceWorkerRegistration.installing property acquires a new service worker.
392+
/// </summary>
393+
public event Action OnServiceWorkerUpdateFound;
394+
/// <summary>
391395
/// This event fires if this instance is running in a WebWorker when the connection to the parent has been established
392396
/// </summary>
393397
public event Action OnDedicatedWorkerParentReady;
@@ -507,13 +511,6 @@ private string GetName()
507511
if (JS.SharedWorkerThis != null) return JS.SharedWorkerThis.Name ?? "";
508512
return "";
509513
}
510-
private string GetParentInstanceId()
511-
{
512-
if (JS.WindowThis != null) return JS.WindowThis.Name ?? "";
513-
if (JS.DedicateWorkerThis != null) return JS.DedicateWorkerThis.Name ?? "";
514-
if (JS.SharedWorkerThis != null) return JS.SharedWorkerThis.Name ?? "";
515-
return "";
516-
}
517514
/// <summary>
518515
/// Called by BlazorJSRuntime at startup
519516
/// </summary>
@@ -659,8 +656,13 @@ public async Task RegisterServiceWorker()
659656
workerUrl += $"?{queryStr}";
660657
}
661658
using var registration = await serviceWorker.Register(workerUrl, ServiceWorkerConfig.Options);
659+
registration.OnUpdateFound += ServiceWorker_OnUpdateFound;
662660
}
663661
}
662+
void ServiceWorker_OnUpdateFound()
663+
{
664+
OnServiceWorkerUpdateFound?.Invoke();
665+
}
664666
/// <summary>
665667
/// Unregisters a registered service worker
666668
/// </summary>

0 commit comments

Comments
 (0)