Skip to content

Commit 5446156

Browse files
authored
Fluent API for opening windows maximized/minimized (#349)
1 parent 7397d15 commit 5446156

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/Windows/PendingOpenWindow.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ public function __destruct()
1212
protected function open(): void
1313
{
1414
$this->client->post('window/open', $this->toArray());
15+
16+
foreach ($this->afterOpenCallbacks as $cb) {
17+
$cb($this);
18+
}
1519
}
1620
}

src/Windows/Window.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Native\Laravel\Concerns\HasDimensions;
77
use Native\Laravel\Concerns\HasUrl;
88
use Native\Laravel\Concerns\HasVibrancy;
9+
use Native\Laravel\Facades\Window as WindowFacade;
910

1011
class Window
1112
{
@@ -53,6 +54,8 @@ class Window
5354

5455
protected Client $client;
5556

57+
protected array $afterOpenCallbacks = [];
58+
5659
public function __construct(string $id)
5760
{
5861
$this->id = $id;
@@ -181,6 +184,16 @@ public function maximizable($maximizable = true): static
181184
return $this;
182185
}
183186

187+
public function minimized(): static
188+
{
189+
$this->afterOpen(fn () => WindowFacade::minimize($this->id));
190+
}
191+
192+
public function maximized(): static
193+
{
194+
$this->afterOpen(fn () => WindowFacade::maximize($this->id));
195+
}
196+
184197
public function closable($closable = true): static
185198
{
186199
$this->closable = $closable;
@@ -261,4 +274,11 @@ public function toArray()
261274
'autoHideMenuBar' => $this->autoHideMenuBar,
262275
];
263276
}
277+
278+
public function afterOpen(callable $cb): static
279+
{
280+
$this->afterOpenCallbacks[] = $cb;
281+
282+
return $this;
283+
}
264284
}

0 commit comments

Comments
 (0)