From f41b417f2a838c9b71acf34de070619e23294d09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Van=20Canneyt?= Date: Wed, 18 May 2022 21:16:44 +0200 Subject: [PATCH] * Corrections to serviceworker object --- packages/fcl-base/serviceworkerapp.pas | 10 ++++----- packages/rtl/web.pas | 2 +- packages/rtl/weborworker.pas | 2 +- packages/rtl/webworker.pas | 28 ++++++++++++++++++++++++-- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/packages/fcl-base/serviceworkerapp.pas b/packages/fcl-base/serviceworkerapp.pas index 397c5b1..dcbd3f6 100644 --- a/packages/fcl-base/serviceworkerapp.pas +++ b/packages/fcl-base/serviceworkerapp.pas @@ -162,9 +162,9 @@ end; function TServiceWorkerApplication.EnableNavigationPreload: jsvalue; begin Result:=nil; - if jsvalue(serviceWorker.registration.navigationPreload) then + if jsvalue(self_.registration.navigationPreload) then // Enable navigation preloads! - await(serviceWorker.registration.navigationPreload.enable()); + await(self_.registration.navigationPreload.enable()); end; procedure TServiceWorkerApplication.DeleteCache(key: string); @@ -189,9 +189,9 @@ end; procedure TServiceWorkerApplication.DoRun; begin - ServiceWorker.addEventListener('activate', @Activate); - ServiceWorker.addEventListener('install', @Install); - ServiceWorker.addEventListener('fetch', @Fetch); + self_.addEventListener('activate', @Activate); + self_.addEventListener('install', @Install); + self_.addEventListener('fetch', @Fetch); end; procedure TServiceWorkerApplication.Activate(Event: TJSExtendableEvent); diff --git a/packages/rtl/web.pas b/packages/rtl/web.pas index 6392257..8dd438a 100644 --- a/packages/rtl/web.pas +++ b/packages/rtl/web.pas @@ -3414,7 +3414,7 @@ var window : TJSWindow; external name 'window'; console : TJSConsole; external name 'window.console'; caches : TJSCacheStorage; external name 'caches'; - serviceWorker : TJSServiceWorker; external name 'self'; + serviceWorker : TJSServiceWorker; external name 'window.navigator.serviceWorker'; Function HasServiceWorker : Boolean; diff --git a/packages/rtl/weborworker.pas b/packages/rtl/weborworker.pas index 25c8041..0450ca6 100644 --- a/packages/rtl/weborworker.pas +++ b/packages/rtl/weborworker.pas @@ -956,7 +956,7 @@ type { TWindowOrWorkerGlobalScope } - TWindowOrWorkerGlobalScope = Class external name 'Object' (TJSObject) + TWindowOrWorkerGlobalScope = Class external name 'Object' (TJSEventTarget) Private FCrypto: TJSCrypto; external name 'crypto'; FisSecureContext : boolean; external name 'isSecureContext'; diff --git a/packages/rtl/webworker.pas b/packages/rtl/webworker.pas index a2d1499..241932f 100644 --- a/packages/rtl/webworker.pas +++ b/packages/rtl/webworker.pas @@ -70,12 +70,36 @@ Type Property Self_ : TJSWorkerGlobalScope Read FSelf; end; + TJSClientsMatchAllOptions = class external name 'Object' + includeUncontrolled : Boolean; + type_ : string; external name 'type'; + end; + + TJSClients = class external name 'Clients' (TJSObject) + function claim : TJSPromise; + function get(ID : String) : TJSPromise; + function matchAll : TJSPromise; + function matchAll(Options : TJSClientsMatchAllOptions) : TJSPromise; + function matchAll(Options : TJSObject) : TJSPromise; + function openWindow(url : string) : TJSPromise; + end; + + { TJSServiceworkerGlobalScope } + + TJSServiceworkerGlobalScope = class external name 'ServiceWorkerGlobalScope' (TJSWorkerGlobalScope) + private + FClients: TJSClients; external name 'clients'; + FRegistration: TJSServiceWorkerRegistration; external name 'registration'; + Public + property registration : TJSServiceWorkerRegistration Read FRegistration; + property clients : TJSClients Read FClients; + end; + Var - Self_ : TJSWorkerGlobalScope; external name 'self'; + Self_ : TJSServiceWorkerGlobalScope; external name 'self'; location : TJSWorkerLocation; console : TJSConsole; navigator : TJSWorkerNavigator; - serviceWorker : TJSServiceWorker; caches : TJSCacheStorage; function fetch(resource: String; init: TJSObject): TJSPromise; overload; external name 'fetch';