Skip to content

Commit

Permalink
WIP: Add the Tauri client
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhamp committed Feb 2, 2024
1 parent 92fd6cf commit 9684a97
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Clients/Tauri.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Native\Laravel\Environments;

use Native\Laravel\Contracts\Environment;

class Tauri implements Environment
{
public function __construct()
{
}

public function get(string $resource)
{
return $this->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;
}
}
2 changes: 2 additions & 0 deletions src/NativeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,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;
Expand Down Expand Up @@ -73,6 +74,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(),
};
});
Expand Down

0 comments on commit 9684a97

Please sign in to comment.