From 7824b5cff3ba91acde619a6692895b4ba6df4ad2 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Thu, 24 Oct 2024 15:41:15 +0100 Subject: [PATCH 01/11] consistency --- src/Windows/WindowManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Windows/WindowManager.php b/src/Windows/WindowManager.php index 9378c5f..ec5d6bd 100644 --- a/src/Windows/WindowManager.php +++ b/src/Windows/WindowManager.php @@ -25,7 +25,7 @@ public function close($id = null) public function hide($id = null) { - return $this->client->post('window/hide', [ + $this->client->post('window/hide', [ 'id' => $id ?? $this->detectId(), ]); } From 462c9ab6990ab7349407a1fa4786b53b120ccbd3 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Thu, 24 Oct 2024 15:42:20 +0100 Subject: [PATCH 02/11] Use the Window class --- src/Windows/Window.php | 11 +++++++++++ src/Windows/WindowManager.php | 17 +++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Windows/Window.php b/src/Windows/Window.php index cc430ca..c55319e 100644 --- a/src/Windows/Window.php +++ b/src/Windows/Window.php @@ -40,6 +40,8 @@ class Window protected bool $focusable = true; + protected bool $focused = false; + protected bool $hasShadow = true; protected bool $frame = true; @@ -282,4 +284,13 @@ public function afterOpen(callable $cb): static return $this; } + + public function fromRuntimeWindow(object $window): static + { + foreach ($window as $key => $value) { + $this->{$key} = $value; + } + + return $this; + } } diff --git a/src/Windows/WindowManager.php b/src/Windows/WindowManager.php index ec5d6bd..f2ee7b7 100644 --- a/src/Windows/WindowManager.php +++ b/src/Windows/WindowManager.php @@ -30,9 +30,22 @@ public function hide($id = null) ]); } - public function current() + public function current(): Window { - return (object) $this->client->get('window/current')->json(); + $window = (object) $this->client->get('window/current')->json(); + + return (new Window($window->id)) + ->setClient($this->client) + ->fromRuntimeWindow($window); + } + + public function get(string $id): Window + { + $window = (object) $this->client->get("window/get/{$id}")->json(); + + return (new Window($window->id)) + ->setClient($this->client) + ->fromRuntimeWindow($window); } public function resize($width, $height, $id = null) From a20ac2ee67b445b83d738216370be01832a769a7 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Thu, 24 Oct 2024 15:42:44 +0100 Subject: [PATCH 03/11] Sensible default --- src/Windows/Window.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Windows/Window.php b/src/Windows/Window.php index c55319e..cd6eeab 100644 --- a/src/Windows/Window.php +++ b/src/Windows/Window.php @@ -233,7 +233,7 @@ public function fullscreenable($fullscreenable = true): static return $this; } - public function kiosk($kiosk = false): static + public function kiosk($kiosk = true): static { $this->kiosk = $kiosk; From a29f2b6bde8dd07ab607021d1cc6bb580aa5b0a5 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Thu, 24 Oct 2024 15:43:17 +0100 Subject: [PATCH 04/11] Allow setting title and URL --- src/Windows/Window.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Windows/Window.php b/src/Windows/Window.php index cd6eeab..0f83c3a 100644 --- a/src/Windows/Window.php +++ b/src/Windows/Window.php @@ -11,7 +11,9 @@ class Window { use HasDimensions; - use HasUrl; + use HasUrl { + HasUrl::url as defaultUrl; + } use HasVibrancy; protected bool $autoHideMenuBar = false; @@ -77,6 +79,27 @@ public function title(string $title): self { $this->title = $title; + if (! $this instanceof PendingOpenWindow) { + $this->client->post('window/title', [ + 'id' => $this->id, + 'title' => $title, + ]); + } + + return $this; + } + + public function url(string $url) + { + $this->defaultUrl($url); + + if (! $this instanceof PendingOpenWindow) { + $this->client->post('window/url', [ + 'id' => $this->id, + 'url' => $url, + ]); + } + return $this; } From e4e66564f652545b3f3211933169def5537e9c88 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Thu, 24 Oct 2024 15:43:25 +0100 Subject: [PATCH 05/11] Use setter --- src/Concerns/HasUrl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Concerns/HasUrl.php b/src/Concerns/HasUrl.php index bb98b01..0a642c2 100644 --- a/src/Concerns/HasUrl.php +++ b/src/Concerns/HasUrl.php @@ -15,7 +15,7 @@ public function url(string $url): self public function route(string $route, array $parameters = []): self { - $this->url = route($route, $parameters); + $this->url(route($route, $parameters)); return $this; } From 840f88dfd33f631094148be9988922ee15aecd0a Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 30 Oct 2024 00:33:17 +0000 Subject: [PATCH 06/11] Add closable --- src/Windows/Window.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Windows/Window.php b/src/Windows/Window.php index 0f83c3a..588957c 100644 --- a/src/Windows/Window.php +++ b/src/Windows/Window.php @@ -219,10 +219,17 @@ public function maximized(): static return $this->afterOpen(fn () => WindowFacade::maximize($this->id)); } - public function closable($closable = true): static + public function closable(bool $closable = true): static { $this->closable = $closable; + if (! $this instanceof PendingOpenWindow) { + $this->client->post('window/closable', [ + 'id' => $this->id, + 'closable' => $closable, + ]); + } + return $this; } From a968651c44b1fb99676052a070fa92cfca70e267 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 30 Oct 2024 01:26:28 +0000 Subject: [PATCH 07/11] Add webPreferences support --- src/Windows/Window.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Windows/Window.php b/src/Windows/Window.php index 588957c..9616578 100644 --- a/src/Windows/Window.php +++ b/src/Windows/Window.php @@ -60,6 +60,8 @@ class Window protected array $afterOpenCallbacks = []; + protected array $webPreferences = []; + public function __construct(string $id) { $this->id = $id; @@ -270,6 +272,13 @@ public function kiosk($kiosk = true): static return $this; } + public function webPreferences(array $preferences): static + { + $this->webPreferences = $preferences; + + return $this; + } + public function toArray() { return [ @@ -305,6 +314,7 @@ public function toArray() 'kiosk' => $this->kiosk, 'autoHideMenuBar' => $this->autoHideMenuBar, 'transparent' => $this->transparent, + 'webPreferences' => $this->webPreferences, ]; } From 6dd4dae707a0c39b1eef3d80575ac8db10b87c6a Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 30 Oct 2024 01:28:24 +0000 Subject: [PATCH 08/11] Dynamic DevTools --- src/Windows/Window.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Windows/Window.php b/src/Windows/Window.php index 9616578..5f81664 100644 --- a/src/Windows/Window.php +++ b/src/Windows/Window.php @@ -30,6 +30,8 @@ class Window protected bool $showDevTools = false; + protected bool $devToolsOpen = false; + protected bool $resizable = true; protected bool $movable = true; @@ -176,14 +178,36 @@ public function alwaysOnTop($alwaysOnTop = true): self return $this; } - public function showDevTools($showDevTools = true): self + public function showDevTools(bool $showDevTools = true): self { $this->showDevTools = $showDevTools; + if (! $this instanceof PendingOpenWindow) { + $this->client->post('window/show-dev-tools', [ + 'id' => $this->id, + ]); + } + + return $this; + } + + public function hideDevTools(): self + { + if (! $this instanceof PendingOpenWindow) { + $this->client->post('window/hide-dev-tools', [ + 'id' => $this->id, + ]); + } + return $this; } - public function resizable($resizable = true): static + public function devToolsOpen(): bool + { + return $this->devToolsOpen; + } + + public function resizable(bool $resizable = true): static { $this->resizable = $resizable; From 1cc456bf80911ebc92ab93a7ac82e5c5d5d2f88b Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 30 Oct 2024 01:30:51 +0000 Subject: [PATCH 09/11] Type hint --- src/Windows/Window.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Windows/Window.php b/src/Windows/Window.php index 5f81664..4f24696 100644 --- a/src/Windows/Window.php +++ b/src/Windows/Window.php @@ -171,7 +171,7 @@ public function setClient(Client $client): self return $this; } - public function alwaysOnTop($alwaysOnTop = true): self + public function alwaysOnTop(bool $alwaysOnTop = true): self { $this->alwaysOnTop = $alwaysOnTop; From 913990699e1058a7dd4593bccf70376fe190c4c0 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 30 Oct 2024 01:31:50 +0000 Subject: [PATCH 10/11] Use passed ID --- src/Windows/WindowManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Windows/WindowManager.php b/src/Windows/WindowManager.php index f2ee7b7..9890708 100644 --- a/src/Windows/WindowManager.php +++ b/src/Windows/WindowManager.php @@ -43,7 +43,7 @@ public function get(string $id): Window { $window = (object) $this->client->get("window/get/{$id}")->json(); - return (new Window($window->id)) + return (new Window($id)) ->setClient($this->client) ->fromRuntimeWindow($window); } From 817cb77c631698829138923bfe5f02fcb26b0c3e Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Wed, 30 Oct 2024 01:59:17 +0000 Subject: [PATCH 11/11] Fix dialog loading --- src/Dialog.php | 6 +----- src/Windows/Window.php | 5 +++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Dialog.php b/src/Dialog.php index 223c853..6188efa 100644 --- a/src/Dialog.php +++ b/src/Dialog.php @@ -110,11 +110,7 @@ public function properties(array $properties): self public function asSheet(?string $windowId = null): self { - if (is_null($windowId)) { - $this->windowReference = Window::current()->id; - } else { - $this->windowReference = $windowId; - } + $this->windowReference = $windowId ?? Window::current()->getId(); return $this; } diff --git a/src/Windows/Window.php b/src/Windows/Window.php index 4f24696..17b3ecb 100644 --- a/src/Windows/Window.php +++ b/src/Windows/Window.php @@ -79,6 +79,11 @@ public function id(string $id = 'main'): self return $this; } + public function getId(): string + { + return $this->id; + } + public function title(string $title): self { $this->title = $title;