diff --git a/src/Windows/PendingOpenWindow.php b/src/Windows/PendingOpenWindow.php index 46175d4..5027953 100644 --- a/src/Windows/PendingOpenWindow.php +++ b/src/Windows/PendingOpenWindow.php @@ -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); + } } } diff --git a/src/Windows/Window.php b/src/Windows/Window.php index 67308af..a96fd2b 100644 --- a/src/Windows/Window.php +++ b/src/Windows/Window.php @@ -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 { @@ -53,6 +54,8 @@ class Window protected Client $client; + protected array $afterOpenCallbacks = []; + public function __construct(string $id) { $this->id = $id; @@ -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; @@ -261,4 +274,11 @@ public function toArray() 'autoHideMenuBar' => $this->autoHideMenuBar, ]; } + + public function afterOpen(callable $cb): static + { + $this->afterOpenCallbacks[] = $cb; + + return $this; + } }