11
11
class Window
12
12
{
13
13
use HasDimensions;
14
- use HasUrl;
14
+ use HasUrl {
15
+ HasUrl::url as defaultUrl;
16
+ }
15
17
use HasVibrancy;
16
18
17
19
protected bool $ autoHideMenuBar = false ;
@@ -28,6 +30,8 @@ class Window
28
30
29
31
protected bool $ showDevTools = false ;
30
32
33
+ protected bool $ devToolsOpen = false ;
34
+
31
35
protected bool $ resizable = true ;
32
36
33
37
protected bool $ movable = true ;
@@ -40,6 +44,8 @@ class Window
40
44
41
45
protected bool $ focusable = true ;
42
46
47
+ protected bool $ focused = false ;
48
+
43
49
protected bool $ hasShadow = true ;
44
50
45
51
protected bool $ frame = true ;
@@ -56,6 +62,8 @@ class Window
56
62
57
63
protected array $ afterOpenCallbacks = [];
58
64
65
+ protected array $ webPreferences = [];
66
+
59
67
public function __construct (string $ id )
60
68
{
61
69
$ this ->id = $ id ;
@@ -71,10 +79,36 @@ public function id(string $id = 'main'): self
71
79
return $ this ;
72
80
}
73
81
82
+ public function getId (): string
83
+ {
84
+ return $ this ->id ;
85
+ }
86
+
74
87
public function title (string $ title ): self
75
88
{
76
89
$ this ->title = $ title ;
77
90
91
+ if (! $ this instanceof PendingOpenWindow) {
92
+ $ this ->client ->post ('window/title ' , [
93
+ 'id ' => $ this ->id ,
94
+ 'title ' => $ title ,
95
+ ]);
96
+ }
97
+
98
+ return $ this ;
99
+ }
100
+
101
+ public function url (string $ url )
102
+ {
103
+ $ this ->defaultUrl ($ url );
104
+
105
+ if (! $ this instanceof PendingOpenWindow) {
106
+ $ this ->client ->post ('window/url ' , [
107
+ 'id ' => $ this ->id ,
108
+ 'url ' => $ url ,
109
+ ]);
110
+ }
111
+
78
112
return $ this ;
79
113
}
80
114
@@ -142,21 +176,43 @@ public function setClient(Client $client): self
142
176
return $ this ;
143
177
}
144
178
145
- public function alwaysOnTop ($ alwaysOnTop = true ): self
179
+ public function alwaysOnTop (bool $ alwaysOnTop = true ): self
146
180
{
147
181
$ this ->alwaysOnTop = $ alwaysOnTop ;
148
182
149
183
return $ this ;
150
184
}
151
185
152
- public function showDevTools ($ showDevTools = true ): self
186
+ public function showDevTools (bool $ showDevTools = true ): self
153
187
{
154
188
$ this ->showDevTools = $ showDevTools ;
155
189
190
+ if (! $ this instanceof PendingOpenWindow) {
191
+ $ this ->client ->post ('window/show-dev-tools ' , [
192
+ 'id ' => $ this ->id ,
193
+ ]);
194
+ }
195
+
196
+ return $ this ;
197
+ }
198
+
199
+ public function hideDevTools (): self
200
+ {
201
+ if (! $ this instanceof PendingOpenWindow) {
202
+ $ this ->client ->post ('window/hide-dev-tools ' , [
203
+ 'id ' => $ this ->id ,
204
+ ]);
205
+ }
206
+
156
207
return $ this ;
157
208
}
158
209
159
- public function resizable ($ resizable = true ): static
210
+ public function devToolsOpen (): bool
211
+ {
212
+ return $ this ->devToolsOpen ;
213
+ }
214
+
215
+ public function resizable (bool $ resizable = true ): static
160
216
{
161
217
$ this ->resizable = $ resizable ;
162
218
@@ -194,10 +250,17 @@ public function maximized(): static
194
250
return $ this ->afterOpen (fn () => WindowFacade::maximize ($ this ->id ));
195
251
}
196
252
197
- public function closable ($ closable = true ): static
253
+ public function closable (bool $ closable = true ): static
198
254
{
199
255
$ this ->closable = $ closable ;
200
256
257
+ if (! $ this instanceof PendingOpenWindow) {
258
+ $ this ->client ->post ('window/closable ' , [
259
+ 'id ' => $ this ->id ,
260
+ 'closable ' => $ closable ,
261
+ ]);
262
+ }
263
+
201
264
return $ this ;
202
265
}
203
266
@@ -231,13 +294,20 @@ public function fullscreenable($fullscreenable = true): static
231
294
return $ this ;
232
295
}
233
296
234
- public function kiosk ($ kiosk = false ): static
297
+ public function kiosk ($ kiosk = true ): static
235
298
{
236
299
$ this ->kiosk = $ kiosk ;
237
300
238
301
return $ this ;
239
302
}
240
303
304
+ public function webPreferences (array $ preferences ): static
305
+ {
306
+ $ this ->webPreferences = $ preferences ;
307
+
308
+ return $ this ;
309
+ }
310
+
241
311
public function toArray ()
242
312
{
243
313
return [
@@ -273,6 +343,7 @@ public function toArray()
273
343
'kiosk ' => $ this ->kiosk ,
274
344
'autoHideMenuBar ' => $ this ->autoHideMenuBar ,
275
345
'transparent ' => $ this ->transparent ,
346
+ 'webPreferences ' => $ this ->webPreferences ,
276
347
];
277
348
}
278
349
@@ -282,4 +353,13 @@ public function afterOpen(callable $cb): static
282
353
283
354
return $ this ;
284
355
}
356
+
357
+ public function fromRuntimeWindow (object $ window ): static
358
+ {
359
+ foreach ($ window as $ key => $ value ) {
360
+ $ this ->{$ key } = $ value ;
361
+ }
362
+
363
+ return $ this ;
364
+ }
285
365
}
0 commit comments