1111class Window
1212{
1313 use HasDimensions;
14- use HasUrl;
14+ use HasUrl {
15+ HasUrl::url as defaultUrl;
16+ }
1517 use HasVibrancy;
1618
1719 protected bool $ autoHideMenuBar = false ;
@@ -28,6 +30,8 @@ class Window
2830
2931 protected bool $ showDevTools = false ;
3032
33+ protected bool $ devToolsOpen = false ;
34+
3135 protected bool $ resizable = true ;
3236
3337 protected bool $ movable = true ;
@@ -40,6 +44,8 @@ class Window
4044
4145 protected bool $ focusable = true ;
4246
47+ protected bool $ focused = false ;
48+
4349 protected bool $ hasShadow = true ;
4450
4551 protected bool $ frame = true ;
@@ -56,6 +62,8 @@ class Window
5662
5763 protected array $ afterOpenCallbacks = [];
5864
65+ protected array $ webPreferences = [];
66+
5967 public function __construct (string $ id )
6068 {
6169 $ this ->id = $ id ;
@@ -71,10 +79,36 @@ public function id(string $id = 'main'): self
7179 return $ this ;
7280 }
7381
82+ public function getId (): string
83+ {
84+ return $ this ->id ;
85+ }
86+
7487 public function title (string $ title ): self
7588 {
7689 $ this ->title = $ title ;
7790
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+
78112 return $ this ;
79113 }
80114
@@ -142,21 +176,43 @@ public function setClient(Client $client): self
142176 return $ this ;
143177 }
144178
145- public function alwaysOnTop ($ alwaysOnTop = true ): self
179+ public function alwaysOnTop (bool $ alwaysOnTop = true ): self
146180 {
147181 $ this ->alwaysOnTop = $ alwaysOnTop ;
148182
149183 return $ this ;
150184 }
151185
152- public function showDevTools ($ showDevTools = true ): self
186+ public function showDevTools (bool $ showDevTools = true ): self
153187 {
154188 $ this ->showDevTools = $ showDevTools ;
155189
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+
156207 return $ this ;
157208 }
158209
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
160216 {
161217 $ this ->resizable = $ resizable ;
162218
@@ -194,10 +250,17 @@ public function maximized(): static
194250 return $ this ->afterOpen (fn () => WindowFacade::maximize ($ this ->id ));
195251 }
196252
197- public function closable ($ closable = true ): static
253+ public function closable (bool $ closable = true ): static
198254 {
199255 $ this ->closable = $ closable ;
200256
257+ if (! $ this instanceof PendingOpenWindow) {
258+ $ this ->client ->post ('window/closable ' , [
259+ 'id ' => $ this ->id ,
260+ 'closable ' => $ closable ,
261+ ]);
262+ }
263+
201264 return $ this ;
202265 }
203266
@@ -231,13 +294,20 @@ public function fullscreenable($fullscreenable = true): static
231294 return $ this ;
232295 }
233296
234- public function kiosk ($ kiosk = false ): static
297+ public function kiosk ($ kiosk = true ): static
235298 {
236299 $ this ->kiosk = $ kiosk ;
237300
238301 return $ this ;
239302 }
240303
304+ public function webPreferences (array $ preferences ): static
305+ {
306+ $ this ->webPreferences = $ preferences ;
307+
308+ return $ this ;
309+ }
310+
241311 public function toArray ()
242312 {
243313 return [
@@ -273,6 +343,7 @@ public function toArray()
273343 'kiosk ' => $ this ->kiosk ,
274344 'autoHideMenuBar ' => $ this ->autoHideMenuBar ,
275345 'transparent ' => $ this ->transparent ,
346+ 'webPreferences ' => $ this ->webPreferences ,
276347 ];
277348 }
278349
@@ -282,4 +353,13 @@ public function afterOpen(callable $cb): static
282353
283354 return $ this ;
284355 }
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+ }
285365}
0 commit comments