Skip to content

Commit cdc04d0

Browse files
committed
bk/2025-05-08-1721-OK
1 parent f96e189 commit cdc04d0

11 files changed

Lines changed: 872 additions & 4 deletions

WebClient/Src/Client.Main.View.dfm

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
object ClientMainView: TClientMainView
2+
Width = 640
3+
Height = 480
4+
Font.Charset = DEFAULT_CHARSET
5+
Font.Color = clWindowText
6+
Font.Height = -13
7+
Font.Name = 'Tahoma'
8+
Font.Style = []
9+
FormContainer = 'appcontent'
10+
ParentFont = False
11+
OnCreate = WebFormCreate
12+
OnExit = WebFormExit
13+
object WebLabel1: TWebLabel
14+
Left = 8
15+
Top = 11
16+
Width = 43
17+
Height = 16
18+
Caption = 'UserID:'
19+
HeightPercent = 100.000000000000000000
20+
WidthPercent = 100.000000000000000000
21+
end
22+
object WebLabel3: TWebLabel
23+
Left = 312
24+
Top = 33
25+
Width = 130
26+
Height = 16
27+
Caption = 'Push Notification demo'
28+
ElementID = 'title'
29+
HeightPercent = 100.000000000000000000
30+
WidthPercent = 100.000000000000000000
31+
end
32+
object WebLabel4: TWebLabel
33+
Left = 312
34+
Top = 65
35+
Width = 184
36+
Height = 16
37+
Caption = 'Usage of TWebPushNotifications'
38+
ElementID = 'description'
39+
HeightPercent = 100.000000000000000000
40+
WidthPercent = 100.000000000000000000
41+
end
42+
object WebEdit1: TWebEdit
43+
Left = 57
44+
Top = 8
45+
Width = 216
46+
Height = 19
47+
HeightPercent = 100.000000000000000000
48+
WidthPercent = 100.000000000000000000
49+
OnChange = WebEdit1Change
50+
end
51+
object WebButton1: TWebButton
52+
Left = 8
53+
Top = 33
54+
Width = 265
55+
Height = 25
56+
Caption = 'Subscribe for push notifications'
57+
ChildOrder = 1
58+
HeightPercent = 100.000000000000000000
59+
WidthPercent = 100.000000000000000000
60+
OnClick = WebButton1Click
61+
end
62+
object WebButton2: TWebButton
63+
Left = 8
64+
Top = 64
65+
Width = 265
66+
Height = 25
67+
Caption = 'Unsubscribe from push notifications'
68+
ChildOrder = 2
69+
HeightPercent = 100.000000000000000000
70+
WidthPercent = 100.000000000000000000
71+
OnClick = WebButton2Click
72+
end
73+
object WebPushNotifications1: TWebPushNotifications
74+
RegisterSubscriptionURL = 'http://localhost:8081/registerSubscription'
75+
UnregisterSubscriptionURL = 'http://localhost:8081/unregisterSubscription'
76+
VapidPublickeyURL = 'http://localhost:8081/vapidPublicKey'
77+
Left = 168
78+
Top = 120
79+
end
80+
end

WebClient/Src/Client.Main.View.pas

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
unit Client.Main.View;
2+
3+
interface
4+
5+
uses
6+
System.SysUtils,
7+
System.Classes,
8+
JS,
9+
Web,
10+
WEBLib.Graphics,
11+
WEBLib.Controls,
12+
WEBLib.StdCtrls,
13+
WEBLib.Forms,
14+
WEBLib.Dialogs,
15+
WEBLib.PushNotifications,
16+
WEBLib.Storage,
17+
Vcl.StdCtrls,
18+
Vcl.Controls;
19+
20+
type
21+
TClientMainView = class(TWebForm)
22+
WebEdit1: TWebEdit;
23+
WebButton1: TWebButton;
24+
WebButton2: TWebButton;
25+
WebLabel1: TWebLabel;
26+
WebPushNotifications1: TWebPushNotifications;
27+
WebLabel3: TWebLabel;
28+
WebLabel4: TWebLabel;
29+
procedure WebButton1Click(Sender: TObject);
30+
procedure WebButton2Click(Sender: TObject);
31+
procedure WebEdit1Change(Sender: TObject);
32+
procedure WebFormCreate(Sender: TObject);
33+
procedure WebFormExit(Sender: TObject);
34+
private
35+
LLocalStorage: TLocalStorage;
36+
procedure DoAddToLocalStorage;
37+
procedure DoRemoveFromLocalStorage;
38+
procedure SetButtonState;
39+
procedure ValidUserID;
40+
end;
41+
42+
var
43+
ClientMainView: TClientMainView;
44+
45+
implementation
46+
47+
{$R *.dfm}
48+
49+
const
50+
STORAGE_KEY = 'pushUserID';
51+
52+
procedure TClientMainView.WebFormCreate(Sender: TObject);
53+
begin
54+
LLocalStorage := TLocalStorage.Create(Self);
55+
if LLocalStorage.Count > 0 then
56+
begin
57+
WebEdit1.Text := TLocalStorage.GetValue(STORAGE_KEY);
58+
end;
59+
60+
Self.SetButtonState;
61+
end;
62+
63+
procedure TClientMainView.WebFormExit(Sender: TObject);
64+
begin
65+
LLocalStorage.Free;
66+
end;
67+
68+
procedure TClientMainView.WebEdit1Change(Sender: TObject);
69+
begin
70+
Self.SetButtonState;
71+
end;
72+
73+
procedure TClientMainView.SetButtonState;
74+
begin
75+
if Trim(WebEdit1.Text).IsEmpty then
76+
begin
77+
WebButton1.Enabled := False;
78+
WebButton2.Enabled := False;
79+
Exit;
80+
end;
81+
82+
if TLocalStorage.GetValue(STORAGE_KEY) = WebEdit1.Text then
83+
begin
84+
WebButton1.Enabled := False;
85+
WebButton2.Enabled := True;
86+
end
87+
else if not TLocalStorage.GetValue(STORAGE_KEY).Trim.IsEmpty then
88+
begin
89+
WebButton1.Enabled := False;
90+
WebButton2.Enabled := False;
91+
end
92+
else
93+
begin
94+
WebButton1.Enabled := True;
95+
WebButton2.Enabled := False;
96+
end;
97+
end;
98+
99+
procedure TClientMainView.ValidUserID;
100+
begin
101+
if Trim(WebEdit1.Text).IsEmpty then
102+
raise Exception.Create('UserID cannot be empty!');
103+
end;
104+
105+
procedure TClientMainView.WebButton1Click(Sender: TObject);
106+
begin
107+
Self.ValidUserID;
108+
109+
WebPushNotifications1.RegistrationUserID := WebEdit1.Text;
110+
WebPushNotifications1.RegisterServiceWorker;
111+
112+
DoAddToLocalStorage;
113+
end;
114+
115+
procedure TClientMainView.WebButton2Click(Sender: TObject);
116+
begin
117+
Self.ValidUserID;
118+
119+
WebPushNotifications1.RegistrationUserID := WebEdit1.Text;
120+
WebPushNotifications1.Unsubscribe;
121+
122+
DoRemoveFromLocalStorage;
123+
end;
124+
125+
procedure TClientMainView.DoRemoveFromLocalStorage;
126+
begin
127+
TWebLocalStorage.RemoveKey(STORAGE_KEY);
128+
SetButtonState;
129+
end;
130+
131+
procedure TClientMainView.DoAddToLocalStorage;
132+
begin
133+
TWebLocalStorage.SetValue(STORAGE_KEY, WebEdit1.Text);
134+
SetButtonState;
135+
end;
136+
137+
end.

WebClient/Src/Client.Main.dfm

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
object ClienteMainView: TClienteMainView
2+
Width = 640
3+
Height = 480
4+
Font.Charset = DEFAULT_CHARSET
5+
Font.Color = clWindowText
6+
Font.Height = -13
7+
Font.Name = 'Tahoma'
8+
Font.Style = []
9+
FormContainer = 'appcontent'
10+
ParentFont = False
11+
OnCreate = WebFormCreate
12+
OnExit = WebFormExit
13+
object WebLabel1: TWebLabel
14+
Left = 8
15+
Top = 11
16+
Width = 43
17+
Height = 16
18+
Caption = 'UserID:'
19+
HeightPercent = 100.000000000000000000
20+
WidthPercent = 100.000000000000000000
21+
end
22+
object WebLabel3: TWebLabel
23+
Left = 312
24+
Top = 33
25+
Width = 130
26+
Height = 16
27+
Caption = 'Push Notification demo'
28+
ElementID = 'title'
29+
HeightPercent = 100.000000000000000000
30+
WidthPercent = 100.000000000000000000
31+
end
32+
object WebLabel4: TWebLabel
33+
Left = 312
34+
Top = 65
35+
Width = 184
36+
Height = 16
37+
Caption = 'Usage of TWebPushNotifications'
38+
ElementID = 'description'
39+
HeightPercent = 100.000000000000000000
40+
WidthPercent = 100.000000000000000000
41+
end
42+
object WebEdit1: TWebEdit
43+
Left = 57
44+
Top = 8
45+
Width = 216
46+
Height = 19
47+
HeightPercent = 100.000000000000000000
48+
WidthPercent = 100.000000000000000000
49+
OnChange = WebEdit1Change
50+
end
51+
object WebButton1: TWebButton
52+
Left = 8
53+
Top = 33
54+
Width = 265
55+
Height = 25
56+
Caption = 'Subscribe for push notifications'
57+
ChildOrder = 1
58+
HeightPercent = 100.000000000000000000
59+
WidthPercent = 100.000000000000000000
60+
OnClick = WebButton1Click
61+
end
62+
object WebButton2: TWebButton
63+
Left = 8
64+
Top = 64
65+
Width = 265
66+
Height = 25
67+
Caption = 'Unsubscribe from push notifications'
68+
ChildOrder = 2
69+
HeightPercent = 100.000000000000000000
70+
WidthPercent = 100.000000000000000000
71+
OnClick = WebButton2Click
72+
end
73+
object WebPushNotifications1: TWebPushNotifications
74+
RegisterSubscriptionURL = 'http://localhost:8081/registerSubscription'
75+
UnregisterSubscriptionURL = 'http://localhost:8081/unregisterSubscription'
76+
VapidPublickeyURL = 'http://localhost:8081/vapidPublicKey'
77+
Left = 168
78+
Top = 120
79+
end
80+
end

0 commit comments

Comments
 (0)