Skip to content

Commit ecc26ec

Browse files
committed
Add system api
1 parent a0ddcef commit ecc26ec

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

src/App.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ public function badgeCount($count = null): int
3838
}
3939

4040
$this->client->post('app/badge-count', [
41-
'count' => $count,
41+
'count' => (int)$count,
4242
]);
4343

44-
return $count;
44+
return (int)$count;
4545
}
4646

4747
public function addRecentDocument(string $path): void

src/Facades/System.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Native\Laravel\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class System extends Facade
8+
{
9+
protected static function getFacadeAccessor()
10+
{
11+
return \Native\Laravel\System::class;
12+
}
13+
}

src/System.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Native\Laravel;
4+
5+
use Native\Laravel\Client\Client;
6+
7+
class System
8+
{
9+
10+
public function __construct(protected Client $client)
11+
{
12+
}
13+
14+
public function canPromptTouchID(): bool
15+
{
16+
return $this->client->get('system/can-prompt-touch-id')->json('result');
17+
}
18+
19+
public function promptTouchID(string $reason): bool
20+
{
21+
return $this->client->post('system/prompt-touch-id', [
22+
'reason' => $reason,
23+
])->successful();
24+
}
25+
}

src/Window.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ class Window
1010
{
1111
protected string $url = '';
1212

13+
protected $x;
14+
protected $y;
15+
1316
protected int $width = 400;
1417

1518
protected int $height = 400;
@@ -20,6 +23,12 @@ class Window
2023

2124
protected bool $transparent = false;
2225

26+
protected bool $focusable = true;
27+
28+
protected bool $hasShadow = true;
29+
30+
protected bool $frame = true;
31+
2332
protected string $titleBarStyle = 'default';
2433

2534
protected string $vibrancy = 'appearance-based';
@@ -89,6 +98,27 @@ public function titleBarHiddenInset(): self
8998
return $this->titleBarStyle('hiddenInset');
9099
}
91100

101+
public function frameless(): self
102+
{
103+
$this->frame = false;
104+
105+
return $this;
106+
}
107+
108+
public function focusable($value = true): self
109+
{
110+
$this->focusable = $value;
111+
112+
return $this;
113+
}
114+
115+
public function hasShadow($value = true): self
116+
{
117+
$this->hasShadow = $value;
118+
119+
return $this;
120+
}
121+
92122
public function titleBarButtonsOnHover(): self
93123
{
94124
return $this->titleBarStyle('customButtonsOnHover');
@@ -139,13 +169,26 @@ public function resizable($resizable = true): static
139169
return $this;
140170
}
141171

172+
public function position($x, $y): self
173+
{
174+
$this->x = $x;
175+
$this->y = $y;
176+
177+
return $this;
178+
}
179+
142180
public function open(): void
143181
{
144182
$this->client->post('window/open', [
145183
'id' => $this->id,
146184
'url' => $this->url,
185+
'x' => $this->x,
186+
'y' => $this->y,
147187
'width' => $this->width,
148188
'height' => $this->height,
189+
'focusable' => $this->focusable,
190+
'hasShadow' => $this->hasShadow,
191+
'frame' => $this->frame,
149192
'titleBarStyle' => $this->titleBarStyle,
150193
'vibrancy' => $this->vibrancy,
151194
'transparency' => $this->transparent,
@@ -156,6 +199,20 @@ public function open(): void
156199
]);
157200
}
158201

202+
public function current()
203+
{
204+
return (object)$this->client->get('window/current')->json();
205+
}
206+
207+
public function invisibleFrameless(): self
208+
{
209+
return $this
210+
->frameless()
211+
->transparent()
212+
->focusable(false)
213+
->hasShadow(false);
214+
}
215+
159216
public function detectId(): ?string
160217
{
161218
$previousUrl = request()->headers->get('Referer');

0 commit comments

Comments
 (0)