Skip to content

Commit 021360d

Browse files
committed
Add new API classes
1 parent cf6a369 commit 021360d

File tree

16 files changed

+266
-5
lines changed

16 files changed

+266
-5
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
"ContextMenu": "Native\\Laravel\\Facades\\ContextMenu",
6969
"Dock": "Native\\Laravel\\Facades\\Dock",
7070
"Process": "Native\\Laravel\\Facades\\Process",
71-
"Window": "Native\\Laravel\\Facades\\Window"
71+
"Window": "Native\\Laravel\\Facades\\Window",
72+
"Clipboard": "Native\\Laravel\\Facades\\Clipboard"
7273
}
7374
}
7475
},

config/native-php.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
'secret' => env('NATIVE_PHP_SECRET'),
1111

1212
'api_url' => env('NATIVE_PHP_API_URL', 'http://localhost:4000/api/'),
13+
14+
'app_id' => env('NATIVEPHP_APP_ID'),
1315

1416
'provider' => \App\Providers\NativeAppServiceProvider::class,
1517
];

src/App.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Native\Laravel;
4+
5+
use Native\Laravel\Client\Client;
6+
7+
class App
8+
{
9+
10+
public function __construct(protected Client $client)
11+
{
12+
}
13+
14+
public function focus(): void
15+
{
16+
$this->client->post('app/focus');
17+
}
18+
19+
public function hide(): void
20+
{
21+
$this->client->post('app/hide');
22+
}
23+
24+
public function isHidden(): bool
25+
{
26+
return $this->client->get('app/is-hidden')->json('is_hidden');
27+
}
28+
29+
public function version(): string
30+
{
31+
return $this->client->get('app/version')->json('version');
32+
}
33+
34+
public function badgeCount($count = null): int
35+
{
36+
if ($count === null) {
37+
return $this->client->get('app/badge-count')->json('count');
38+
}
39+
40+
$this->client->post('app/badge-count', [
41+
'count' => $count,
42+
]);
43+
44+
return $count;
45+
}
46+
47+
public function addRecentDocument(string $path): void
48+
{
49+
$this->client->post('app/recent-documents', [
50+
'path' => $path,
51+
]);
52+
}
53+
54+
public function recentDocuments(): array
55+
{
56+
return $this->client->get('app/recent-documents')->json('documents');
57+
}
58+
59+
public function clearRecentDocuments(): void
60+
{
61+
$this->client->delete('app/recent-documents');
62+
}
63+
}

src/Client/Client.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function __construct()
1414
{
1515
$this->client = Http::asJson()
1616
->baseUrl(config('native-php.api_url', ''))
17-
->timeout(2)
17+
->timeout(60 * 60)
1818
->withHeaders([
1919
'X-Native-PHP-Secret' => config('native-php.secret'),
2020
])
@@ -30,4 +30,9 @@ public function post(string $endpoint, array $data = []): Response
3030
{
3131
return $this->client->post($endpoint, $data);
3232
}
33+
34+
public function delete(string $endpoint, array $data = []): Response
35+
{
36+
return $this->client->delete($endpoint, $data);
37+
}
3338
}

src/Clipboard.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Native\Laravel;
4+
5+
use Native\Laravel\Client\Client;
6+
7+
class Clipboard
8+
{
9+
10+
public function __construct(protected Client $client)
11+
{
12+
}
13+
14+
public function text($text = null): string
15+
{
16+
if (is_null($text)) {
17+
return $this->client->get('clipboard/text')->json('text');
18+
}
19+
20+
$this->client->post('clipboard/text', [
21+
'text' => $text,
22+
]);
23+
24+
return $text;
25+
}
26+
}

src/Compactor/Php.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PhpToken;
66

7+
78
class Php
89
{
910
public function canProcessFile(string $path): bool

src/Dialog.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Dialog
1010

1111
protected $defaultPath;
1212

13-
protected $buttonLabel;
13+
protected $buttonLabel = 'Select';
1414

1515
protected $properties = [
1616
'openFile',
@@ -88,7 +88,7 @@ public function properties(array $properties): self
8888

8989
public function show()
9090
{
91-
$result = $this->client->post('dialog', [
91+
$result = $this->client->post('dialog/open', [
9292
'title' => $this->title,
9393
'defaultPath' => $this->defaultPath,
9494
'filters' => $this->filters,
@@ -102,4 +102,15 @@ public function show()
102102

103103
return $result;
104104
}
105+
106+
public function save()
107+
{
108+
return $this->client->post('dialog/save', [
109+
'title' => $this->title,
110+
'defaultPath' => $this->defaultPath,
111+
'filters' => $this->filters,
112+
'buttonLabel' => $this->buttonLabel,
113+
'properties' => array_unique($this->properties),
114+
])->json('result');
115+
}
105116
}

src/Events/App/OpenFile.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Native\Laravel\Events\App;
4+
5+
use Illuminate\Broadcasting\Channel;
6+
use Illuminate\Broadcasting\InteractsWithSockets;
7+
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
8+
use Illuminate\Foundation\Events\Dispatchable;
9+
use Illuminate\Queue\SerializesModels;
10+
11+
class OpenFile implements ShouldBroadcastNow
12+
{
13+
use Dispatchable, InteractsWithSockets, SerializesModels;
14+
15+
public function __construct(public $path)
16+
{
17+
18+
}
19+
20+
public function broadcastOn()
21+
{
22+
return [
23+
new Channel('nativephp'),
24+
];
25+
}
26+
}

src/Events/App/OpenedFromURL.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Native\Laravel\Events\App;
4+
5+
use Illuminate\Broadcasting\Channel;
6+
use Illuminate\Broadcasting\InteractsWithSockets;
7+
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
8+
use Illuminate\Foundation\Events\Dispatchable;
9+
use Illuminate\Queue\SerializesModels;
10+
11+
class OpenedFromURL implements ShouldBroadcastNow
12+
{
13+
use Dispatchable, InteractsWithSockets, SerializesModels;
14+
15+
public function __construct(public $url)
16+
{
17+
18+
}
19+
20+
public function broadcastOn()
21+
{
22+
return [
23+
new Channel('nativephp'),
24+
];
25+
}
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Native\Laravel\Events\Notifications;
4+
5+
use Illuminate\Broadcasting\Channel;
6+
use Illuminate\Broadcasting\InteractsWithSockets;
7+
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
8+
use Illuminate\Foundation\Events\Dispatchable;
9+
use Illuminate\Queue\SerializesModels;
10+
11+
class NotificationClicked implements ShouldBroadcastNow
12+
{
13+
use Dispatchable, InteractsWithSockets, SerializesModels;
14+
15+
public function broadcastOn()
16+
{
17+
return [
18+
new Channel('nativephp'),
19+
];
20+
}
21+
}

0 commit comments

Comments
 (0)