Skip to content

Commit

Permalink
Fluent API for opening windows maximized/minimized (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhamp authored Aug 24, 2024
1 parent 7397d15 commit 5446156
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Windows/PendingOpenWindow.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ public function __destruct()
protected function open(): void
{
$this->client->post('window/open', $this->toArray());

foreach ($this->afterOpenCallbacks as $cb) {
$cb($this);
}
}
}
20 changes: 20 additions & 0 deletions src/Windows/Window.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Native\Laravel\Concerns\HasDimensions;
use Native\Laravel\Concerns\HasUrl;
use Native\Laravel\Concerns\HasVibrancy;
use Native\Laravel\Facades\Window as WindowFacade;

class Window
{
Expand Down Expand Up @@ -53,6 +54,8 @@ class Window

protected Client $client;

protected array $afterOpenCallbacks = [];

public function __construct(string $id)
{
$this->id = $id;
Expand Down Expand Up @@ -181,6 +184,16 @@ public function maximizable($maximizable = true): static
return $this;
}

public function minimized(): static
{
$this->afterOpen(fn () => WindowFacade::minimize($this->id));
}

public function maximized(): static
{
$this->afterOpen(fn () => WindowFacade::maximize($this->id));
}

public function closable($closable = true): static
{
$this->closable = $closable;
Expand Down Expand Up @@ -261,4 +274,11 @@ public function toArray()
'autoHideMenuBar' => $this->autoHideMenuBar,
];
}

public function afterOpen(callable $cb): static
{
$this->afterOpenCallbacks[] = $cb;

return $this;
}
}

0 comments on commit 5446156

Please sign in to comment.