mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-08-22 16:29:10 +02:00
demo pwa: using TBrowserApplication
This commit is contained in:
parent
49e4bf63ab
commit
8341d054b3
@ -3,14 +3,32 @@ program SimplePWA1;
|
|||||||
{$mode objfpc}
|
{$mode objfpc}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
JS, Classes, SysUtils, Web;
|
Web, BrowserApp;
|
||||||
|
|
||||||
const
|
const
|
||||||
GreekLetters: array[1..9] of string = (
|
GreekLetters: array[1..9] of string = (
|
||||||
'Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta', 'Theta', 'Iota'
|
'Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta', 'Theta', 'Iota'
|
||||||
);
|
);
|
||||||
|
|
||||||
procedure ShowLetters;
|
type
|
||||||
|
|
||||||
|
{ TWebApp }
|
||||||
|
|
||||||
|
TWebApp = class(TBrowserApplication)
|
||||||
|
protected
|
||||||
|
procedure DoRun; override;
|
||||||
|
public
|
||||||
|
procedure ShowLetters;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TWebApp.DoRun;
|
||||||
|
begin
|
||||||
|
inherited DoRun;
|
||||||
|
document.addEventListener('DOMContentLoaded', @ShowLetters);
|
||||||
|
RegisterServiceWorker('/ServiceWorker.js');
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TWebApp.ShowLetters;
|
||||||
var
|
var
|
||||||
h, Letter: String;
|
h, Letter: String;
|
||||||
container: TJSElement;
|
container: TJSElement;
|
||||||
@ -28,25 +46,9 @@ begin
|
|||||||
container.innerHTML := h;
|
container.innerHTML := h;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
App: TWebApp;
|
||||||
begin
|
begin
|
||||||
// Your code here
|
App:=TWebApp.Create(nil);
|
||||||
document.addEventListener('DOMContentLoaded', @ShowLetters);
|
App.Run;
|
||||||
|
|
||||||
// register service worker
|
|
||||||
if IsServiceWorker then
|
|
||||||
Window.addEventListener('load',
|
|
||||||
procedure()
|
|
||||||
begin
|
|
||||||
Window.navigator.serviceWorker
|
|
||||||
.register('/ServiceWorker.js')
|
|
||||||
._then(TJSPromiseResolver(procedure(Registration: TJSServiceWorkerRegistration)
|
|
||||||
begin
|
|
||||||
console.log('service worker registered');
|
|
||||||
if IsDefined(Registration.installing) then ;
|
|
||||||
end))
|
|
||||||
.catch(TJSPromiseResolver(procedure(err: JSValue)
|
|
||||||
begin
|
|
||||||
console.log('service worker not registered: '+String(err));
|
|
||||||
end));
|
|
||||||
end);
|
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user