From ef51379e34dd72976652c2822762c0ada3ce8994 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 2 Feb 2024 15:28:54 +0000 Subject: [PATCH 01/11] Move the Electron client class and rename So we can make space for the new Tauri client class --- src/{Client/Client.php => Clients/Electron.php} | 3 ++- src/Contracts/Client.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) rename src/{Client/Client.php => Clients/Electron.php} (92%) create mode 100644 src/Contracts/Client.php diff --git a/src/Client/Client.php b/src/Clients/Electron.php similarity index 92% rename from src/Client/Client.php rename to src/Clients/Electron.php index e444ea4a..338f8638 100644 --- a/src/Client/Client.php +++ b/src/Clients/Electron.php @@ -5,8 +5,9 @@ use Illuminate\Http\Client\PendingRequest; use Illuminate\Http\Client\Response; use Illuminate\Support\Facades\Http; +use Native\Laravel\Contracts\Client; -class Client +class Electron implements Client { protected PendingRequest $client; diff --git a/src/Contracts/Client.php b/src/Contracts/Client.php new file mode 100644 index 00000000..898cfe39 --- /dev/null +++ b/src/Contracts/Client.php @@ -0,0 +1,12 @@ + Date: Fri, 2 Feb 2024 15:31:05 +0000 Subject: [PATCH 02/11] Add the environment variable/config This allows us to decide which client class to load --- config/nativephp-internal.php | 5 +++++ src/NativeServiceProvider.php | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/config/nativephp-internal.php b/config/nativephp-internal.php index 4210df92..84893661 100644 --- a/config/nativephp-internal.php +++ b/config/nativephp-internal.php @@ -1,6 +1,11 @@ env('NATIVEPHP_ENVIRONMENT', 'electron'), + /** * An internal flag to indicate if the app is running in the NativePHP * environment. This is used to determine if the app should use the diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index 396478a5..3e3fbe7d 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -9,7 +9,9 @@ use Native\Laravel\Commands\LoadStartupConfigurationCommand; use Native\Laravel\Commands\MigrateCommand; use Native\Laravel\Commands\MinifyApplicationCommand; +use Native\Laravel\Clients\Electron; use Native\Laravel\Commands\SeedDatabaseCommand; +use Native\Laravel\Contracts\Client; use Native\Laravel\Logging\LogWatcher; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -57,6 +59,8 @@ protected function configureApp() app(LogWatcher::class)->register(); } + $this->registerNativeClient(); + $this->rewriteStoragePath(); $this->rewriteDatabase(); @@ -67,6 +71,15 @@ protected function configureApp() config(['queue.default' => 'database']); } + protected function registerNativeClient() + { + $this->app->singleton(Client::class, function ($app) { + return match($app['config']->get('nativephp-internal.environment')) { + 'electron' => new Electron(), + }; + }); + } + protected function rewriteStoragePath() { if (config('app.debug')) { From d90af5b1e15559705dd30561b526af3bd9bc6126 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 2 Feb 2024 15:31:30 +0000 Subject: [PATCH 03/11] WIP: Add the Tauri client --- src/Clients/Tauri.php | 41 +++++++++++++++++++++++++++++++++++ src/NativeServiceProvider.php | 2 ++ 2 files changed, 43 insertions(+) create mode 100644 src/Clients/Tauri.php diff --git a/src/Clients/Tauri.php b/src/Clients/Tauri.php new file mode 100644 index 00000000..8631f516 --- /dev/null +++ b/src/Clients/Tauri.php @@ -0,0 +1,41 @@ +request([ + 'invoke' => $resource + ]); + } + + public function post(string $resource, array $data = []) + { + return $this->request([ + 'invoke' => $resource, + 'data' => $data, + ]); + } + + protected function request($message) + { + // Connect to the socket, send the data and get a response and shutdown + $client = stream_socket_client('tcp://127.0.0.1:9000'); + + stream_socket_sendto($client, json_encode($message)); + + $response = base_convert(stream_socket_recvfrom($client, 1500000), 2, 10); + + stream_socket_shutdown($client, STREAM_SHUT_RDWR); + + return $response; + } +} diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index 3e3fbe7d..29307602 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -10,6 +10,7 @@ use Native\Laravel\Commands\MigrateCommand; use Native\Laravel\Commands\MinifyApplicationCommand; use Native\Laravel\Clients\Electron; +use Native\Laravel\Clients\Tauri; use Native\Laravel\Commands\SeedDatabaseCommand; use Native\Laravel\Contracts\Client; use Native\Laravel\Logging\LogWatcher; @@ -75,6 +76,7 @@ protected function registerNativeClient() { $this->app->singleton(Client::class, function ($app) { return match($app['config']->get('nativephp-internal.environment')) { + 'tauri' => new Tauri(), 'electron' => new Electron(), }; }); From 3242f0dfcfe2016c029244100a7331bfabed53e8 Mon Sep 17 00:00:00 2001 From: simonhamp Date: Fri, 2 Feb 2024 15:32:12 +0000 Subject: [PATCH 04/11] Fix styling --- src/Clients/Tauri.php | 2 +- src/Contracts/Client.php | 2 ++ src/NativeServiceProvider.php | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Clients/Tauri.php b/src/Clients/Tauri.php index 8631f516..546306bd 100644 --- a/src/Clients/Tauri.php +++ b/src/Clients/Tauri.php @@ -13,7 +13,7 @@ public function __construct() public function get(string $resource) { return $this->request([ - 'invoke' => $resource + 'invoke' => $resource, ]); } diff --git a/src/Contracts/Client.php b/src/Contracts/Client.php index 898cfe39..1515345f 100644 --- a/src/Contracts/Client.php +++ b/src/Contracts/Client.php @@ -7,6 +7,8 @@ interface Client { public function get(string $resource): Response; + public function post(string $resource, array $data = []): Response; + public function delete(string $resource, array $data = []): Response; } diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index 29307602..620b8dd4 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -4,13 +4,13 @@ use Illuminate\Console\Application as Artisan; use Illuminate\Support\Arr; +use Native\Laravel\Clients\Electron; +use Native\Laravel\Clients\Tauri; use Native\Laravel\Commands\FreshCommand; use Native\Laravel\Commands\LoadPHPConfigurationCommand; use Native\Laravel\Commands\LoadStartupConfigurationCommand; use Native\Laravel\Commands\MigrateCommand; use Native\Laravel\Commands\MinifyApplicationCommand; -use Native\Laravel\Clients\Electron; -use Native\Laravel\Clients\Tauri; use Native\Laravel\Commands\SeedDatabaseCommand; use Native\Laravel\Contracts\Client; use Native\Laravel\Logging\LogWatcher; @@ -75,7 +75,7 @@ protected function configureApp() protected function registerNativeClient() { $this->app->singleton(Client::class, function ($app) { - return match($app['config']->get('nativephp-internal.environment')) { + return match ($app['config']->get('nativephp-internal.environment')) { 'tauri' => new Tauri(), 'electron' => new Electron(), }; From 4e7931f5ade8c97bacb6e57a7a0013d7f1ce9d2a Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 2 Feb 2024 16:50:49 +0000 Subject: [PATCH 05/11] Fix the Tauri client --- src/Clients/Tauri.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Clients/Tauri.php b/src/Clients/Tauri.php index 546306bd..49e603a6 100644 --- a/src/Clients/Tauri.php +++ b/src/Clients/Tauri.php @@ -2,22 +2,26 @@ namespace Native\Laravel\Environments; -use Native\Laravel\Contracts\Environment; +use Native\Laravel\Contracts\Client; -class Tauri implements Environment +class Tauri implements Client { - public function __construct() + public function get(string $resource) { + return $this->request([ + 'invoke' => $resource, + ]); } - public function get(string $resource) + public function post(string $resource, array $data = []) { return $this->request([ 'invoke' => $resource, + 'data' => $data, ]); } - public function post(string $resource, array $data = []) + public function delete(string $resource, array $data = []) { return $this->request([ 'invoke' => $resource, From 9cbeb1886ca338fbba22b6dbdb119e8c53af71d6 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 2 Feb 2024 16:51:44 +0000 Subject: [PATCH 06/11] Simplify the interface --- src/Contracts/Client.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Contracts/Client.php b/src/Contracts/Client.php index 1515345f..044a5368 100644 --- a/src/Contracts/Client.php +++ b/src/Contracts/Client.php @@ -2,13 +2,9 @@ namespace Native\Laravel\Contracts; -use Illuminate\Http\Client\Response; - interface Client { - public function get(string $resource): Response; - - public function post(string $resource, array $data = []): Response; - - public function delete(string $resource, array $data = []): Response; + public function get(string $resource); + public function post(string $resource, array $data = []); + public function delete(string $resource, array $data = []); } From 44e087442f0ef1f4448594fef50ed13497e25623 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 2 Feb 2024 17:08:18 +0000 Subject: [PATCH 07/11] Fix namespaces --- src/Clients/Electron.php | 2 +- src/Clients/Tauri.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Clients/Electron.php b/src/Clients/Electron.php index 338f8638..36ff3182 100644 --- a/src/Clients/Electron.php +++ b/src/Clients/Electron.php @@ -1,6 +1,6 @@ Date: Sun, 28 Apr 2024 16:38:37 +0000 Subject: [PATCH 08/11] Fix styling --- src/Contracts/Client.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Contracts/Client.php b/src/Contracts/Client.php index 044a5368..51f9963b 100644 --- a/src/Contracts/Client.php +++ b/src/Contracts/Client.php @@ -5,6 +5,8 @@ interface Client { public function get(string $resource); + public function post(string $resource, array $data = []); + public function delete(string $resource, array $data = []); } From 784b29f7738bf494549b67f385a25e6b0462703b Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 28 Apr 2024 17:42:46 +0100 Subject: [PATCH 09/11] Update references to interface --- src/App.php | 2 +- src/Clipboard.php | 2 +- src/ContextMenu.php | 2 +- src/Dialog.php | 2 +- src/Dock.php | 2 +- src/GlobalShortcut.php | 2 +- src/Logging/LogWatcher.php | 2 +- src/Menu/Menu.php | 2 +- src/MenuBar/MenuBar.php | 2 +- src/MenuBar/MenuBarManager.php | 2 +- src/Notification.php | 4 ++-- src/Process.php | 2 +- src/ProgressBar.php | 2 +- src/Screen.php | 2 +- src/Settings.php | 2 +- src/Shell.php | 2 +- src/System.php | 2 +- src/Windows/Window.php | 2 +- src/Windows/WindowManager.php | 2 +- 19 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/App.php b/src/App.php index 15fba4e6..a1b6e1ec 100644 --- a/src/App.php +++ b/src/App.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; class App { diff --git a/src/Clipboard.php b/src/Clipboard.php index a6d73268..12117aa7 100644 --- a/src/Clipboard.php +++ b/src/Clipboard.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; class Clipboard { diff --git a/src/ContextMenu.php b/src/ContextMenu.php index e0e8fa72..36a20d65 100644 --- a/src/ContextMenu.php +++ b/src/ContextMenu.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; use Native\Laravel\Menu\Menu; class ContextMenu diff --git a/src/Dialog.php b/src/Dialog.php index 153976f3..40aec5ea 100644 --- a/src/Dialog.php +++ b/src/Dialog.php @@ -4,7 +4,7 @@ use Illuminate\Support\Traits\Conditionable; use Illuminate\Support\Traits\Macroable; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; use Native\Laravel\Facades\Window; class Dialog diff --git a/src/Dock.php b/src/Dock.php index 63a7a49f..0ff6c48c 100644 --- a/src/Dock.php +++ b/src/Dock.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; use Native\Laravel\Menu\Menu; class Dock diff --git a/src/GlobalShortcut.php b/src/GlobalShortcut.php index 24020cf9..56f0d6dc 100644 --- a/src/GlobalShortcut.php +++ b/src/GlobalShortcut.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; class GlobalShortcut { diff --git a/src/Logging/LogWatcher.php b/src/Logging/LogWatcher.php index 650882b0..3ba15019 100644 --- a/src/Logging/LogWatcher.php +++ b/src/Logging/LogWatcher.php @@ -4,7 +4,7 @@ use Illuminate\Log\Events\MessageLogged; use Illuminate\Support\Facades\Event; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; class LogWatcher { diff --git a/src/Menu/Menu.php b/src/Menu/Menu.php index 7709a41d..1fed4151 100644 --- a/src/Menu/Menu.php +++ b/src/Menu/Menu.php @@ -3,7 +3,7 @@ namespace Native\Laravel\Menu; use Illuminate\Support\Traits\Conditionable; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; use Native\Laravel\Contracts\MenuItem; use Native\Laravel\Enums\RolesEnum; use Native\Laravel\Menu\Items\Checkbox; diff --git a/src/MenuBar/MenuBar.php b/src/MenuBar/MenuBar.php index 9885233b..fa2ebd7f 100644 --- a/src/MenuBar/MenuBar.php +++ b/src/MenuBar/MenuBar.php @@ -2,7 +2,7 @@ namespace Native\Laravel\MenuBar; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; use Native\Laravel\Concerns\HasDimensions; use Native\Laravel\Concerns\HasPositioner; use Native\Laravel\Concerns\HasUrl; diff --git a/src/MenuBar/MenuBarManager.php b/src/MenuBar/MenuBarManager.php index a7877ae6..18369703 100644 --- a/src/MenuBar/MenuBarManager.php +++ b/src/MenuBar/MenuBarManager.php @@ -2,7 +2,7 @@ namespace Native\Laravel\MenuBar; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; use Native\Laravel\Menu\Menu; class MenuBarManager diff --git a/src/Notification.php b/src/Notification.php index fd4d023a..319c2dee 100644 --- a/src/Notification.php +++ b/src/Notification.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; class Notification { @@ -18,7 +18,7 @@ public function __construct(protected Client $client) public static function new() { - return new static(new Client()); + return new static(app(Client::class)); } public function title(string $title): self diff --git a/src/Process.php b/src/Process.php index 7a189f9b..0efc68f2 100644 --- a/src/Process.php +++ b/src/Process.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; class Process { diff --git a/src/ProgressBar.php b/src/ProgressBar.php index b4a67607..2ff1a242 100644 --- a/src/ProgressBar.php +++ b/src/ProgressBar.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; class ProgressBar { diff --git a/src/Screen.php b/src/Screen.php index b0f4e7f2..ab9dbddd 100644 --- a/src/Screen.php +++ b/src/Screen.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; class Screen { diff --git a/src/Settings.php b/src/Settings.php index 0c7b6eec..bc27116e 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; class Settings { diff --git a/src/Shell.php b/src/Shell.php index 38dedca0..963b3ea6 100644 --- a/src/Shell.php +++ b/src/Shell.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; class Shell { diff --git a/src/System.php b/src/System.php index 65a2c0c4..cd0b1a79 100644 --- a/src/System.php +++ b/src/System.php @@ -2,7 +2,7 @@ namespace Native\Laravel; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; use Native\Laravel\DataObjects\Printer; class System diff --git a/src/Windows/Window.php b/src/Windows/Window.php index b8f5926c..9423c9f6 100644 --- a/src/Windows/Window.php +++ b/src/Windows/Window.php @@ -2,7 +2,7 @@ namespace Native\Laravel\Windows; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; use Native\Laravel\Concerns\HasDimensions; use Native\Laravel\Concerns\HasUrl; use Native\Laravel\Concerns\HasVibrancy; diff --git a/src/Windows/WindowManager.php b/src/Windows/WindowManager.php index 6216f74c..4c0c217e 100644 --- a/src/Windows/WindowManager.php +++ b/src/Windows/WindowManager.php @@ -2,7 +2,7 @@ namespace Native\Laravel\Windows; -use Native\Laravel\Client\Client; +use Native\Laravel\Contracts\Client; use Native\Laravel\Concerns\DetectsWindowId; class WindowManager From e102da636a4d12bd019062e363f80275ebdcea21 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Sun, 28 Apr 2024 17:43:04 +0100 Subject: [PATCH 10/11] Register client first --- src/NativeServiceProvider.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/NativeServiceProvider.php b/src/NativeServiceProvider.php index 620b8dd4..41cb2837 100644 --- a/src/NativeServiceProvider.php +++ b/src/NativeServiceProvider.php @@ -56,12 +56,12 @@ public function packageRegistered() protected function configureApp() { + $this->registerNativeClient(); + if (config('app.debug')) { app(LogWatcher::class)->register(); } - $this->registerNativeClient(); - $this->rewriteStoragePath(); $this->rewriteDatabase(); From 667a9eb013d1220556572e0c8754fd68fc57b301 Mon Sep 17 00:00:00 2001 From: simonhamp Date: Sun, 28 Apr 2024 16:43:19 +0000 Subject: [PATCH 11/11] Fix styling --- src/MenuBar/MenuBar.php | 2 +- src/Windows/Window.php | 2 +- src/Windows/WindowManager.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/MenuBar/MenuBar.php b/src/MenuBar/MenuBar.php index fa2ebd7f..919295b0 100644 --- a/src/MenuBar/MenuBar.php +++ b/src/MenuBar/MenuBar.php @@ -2,11 +2,11 @@ namespace Native\Laravel\MenuBar; -use Native\Laravel\Contracts\Client; use Native\Laravel\Concerns\HasDimensions; use Native\Laravel\Concerns\HasPositioner; use Native\Laravel\Concerns\HasUrl; use Native\Laravel\Concerns\HasVibrancy; +use Native\Laravel\Contracts\Client; use Native\Laravel\Menu\Menu; class MenuBar diff --git a/src/Windows/Window.php b/src/Windows/Window.php index 9423c9f6..a70d8bd3 100644 --- a/src/Windows/Window.php +++ b/src/Windows/Window.php @@ -2,10 +2,10 @@ namespace Native\Laravel\Windows; -use Native\Laravel\Contracts\Client; use Native\Laravel\Concerns\HasDimensions; use Native\Laravel\Concerns\HasUrl; use Native\Laravel\Concerns\HasVibrancy; +use Native\Laravel\Contracts\Client; class Window { diff --git a/src/Windows/WindowManager.php b/src/Windows/WindowManager.php index 4c0c217e..5fb0bd2f 100644 --- a/src/Windows/WindowManager.php +++ b/src/Windows/WindowManager.php @@ -2,8 +2,8 @@ namespace Native\Laravel\Windows; -use Native\Laravel\Contracts\Client; use Native\Laravel\Concerns\DetectsWindowId; +use Native\Laravel\Contracts\Client; class WindowManager {