Skip to content

Commit 68ff56c

Browse files
committed
refactoring
1 parent 13c709a commit 68ff56c

22 files changed

+616
-213
lines changed

config/nativephp.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<?php
22

33
return [
4+
/**
5+
* The version of your app.
6+
* It is used to determine if the app needs to be updated.
7+
* Increment this value every time you release a new version of your app.
8+
*/
49
'version' => env('NATIVEPHP_APP_VERSION', '1.0.0'),
510

611
'app_id' => env('NATIVEPHP_APP_ID'),

resources/stubs/NativeAppServiceProvider.php.stub

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ namespace App\Providers;
44

55
use Native\Laravel\Facades\ContextMenu;
66
use Native\Laravel\Facades\Dock;
7+
use Native\Laravel\Facades\Window;
78
use Native\Laravel\GlobalShortcut;
89
use Native\Laravel\Menu\Menu;
9-
use Native\Laravel\Window as AppWindow;
1010

1111
class NativeAppServiceProvider
1212
{
@@ -29,12 +29,9 @@ class NativeAppServiceProvider
2929
)
3030
->register();
3131

32-
AppWindow::new()
33-
->url(url('/'))
34-
->title('Laravel Native App')
32+
Window::open()
3533
->width(800)
36-
->height(800)
37-
->open();
34+
->height(800);
3835

3936
/**
4037
Dock::menu(

src/Clipboard.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ public function __construct(protected Client $client)
1010
{
1111
}
1212

13+
public function clear()
14+
{
15+
$this->client->delete('clipboard');
16+
}
17+
1318
public function text($text = null): string
1419
{
1520
if (is_null($text)) {
@@ -22,4 +27,38 @@ public function text($text = null): string
2227

2328
return $text;
2429
}
30+
31+
public function html($html = null): string
32+
{
33+
if (is_null($html)) {
34+
return $this->client->get('clipboard/html')->json('html');
35+
}
36+
37+
$this->client->post('clipboard/html', [
38+
'html' => $html,
39+
]);
40+
41+
return $html;
42+
}
43+
44+
public function image($image = null): string
45+
{
46+
if (is_null($image)) {
47+
return $this->client->get('clipboard/image')->json('image');
48+
}
49+
50+
$dataUri = $image;
51+
52+
if (is_string($image) && file_exists($image)) {
53+
$type = pathinfo($image, PATHINFO_EXTENSION);
54+
$data = file_get_contents($image);
55+
$dataUri = "data:image/{$type};base64," . base64_encode($data);
56+
}
57+
58+
$this->client->post('clipboard/image', [
59+
'image' => $dataUri,
60+
]);
61+
62+
return $image;
63+
}
2564
}

src/Concerns/DetectsWindowId.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Native\Laravel\Concerns;
4+
5+
use Illuminate\Support\Facades\URL;
6+
7+
trait DetectsWindowId
8+
{
9+
protected function detectId(): ?string
10+
{
11+
$previousUrl = request()->headers->get('Referer');
12+
$currentUrl = URL::current();
13+
14+
// Return the _windowId query parameter from either the previous or current URL.
15+
$parsedUrl = parse_url($previousUrl ?? $currentUrl);
16+
parse_str($parsedUrl['query'] ?? '', $query);
17+
18+
return $query['_windowId'] ?? null;
19+
}
20+
}

src/Concerns/HasDimensions.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Native\Laravel\Concerns;
4+
5+
trait HasDimensions
6+
{
7+
protected int $width = 400;
8+
9+
protected int $height = 400;
10+
11+
protected int $minWidth = 0;
12+
13+
protected int $minHeight = 0;
14+
15+
protected $x;
16+
17+
protected $y;
18+
19+
public function width($width): self
20+
{
21+
$this->width = $width;
22+
23+
return $this;
24+
}
25+
26+
public function height($height): self
27+
{
28+
$this->height = $height;
29+
30+
return $this;
31+
}
32+
33+
public function minWidth($width): self
34+
{
35+
$this->minWidth = $width;
36+
37+
return $this;
38+
}
39+
40+
public function minHeight($height): self
41+
{
42+
$this->minHeight = $height;
43+
44+
return $this;
45+
}
46+
47+
public function position($x, $y): self
48+
{
49+
$this->x = $x;
50+
$this->y = $y;
51+
52+
return $this;
53+
}
54+
}

src/Concerns/HasVibrancy.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Native\Laravel\Concerns;
4+
5+
trait HasVibrancy
6+
{
7+
protected string $vibrancy = 'appearance-based';
8+
9+
protected string $backgroundColor = '#FFFFFF';
10+
11+
protected bool $transparent = false;
12+
13+
public function transparent($value = true): self
14+
{
15+
$this->transparent = $value;
16+
if ($value === true) {
17+
$this->backgroundColor = '#00000000';
18+
}
19+
20+
return $this;
21+
}
22+
23+
public function vibrancy(string $vibrancy): self
24+
{
25+
$this->vibrancy = $vibrancy;
26+
27+
return $this;
28+
}
29+
30+
public function lightVibrancy(): self
31+
{
32+
return $this->vibrancy('light');
33+
}
34+
35+
public function blendBackgroundBehindWindow(): self
36+
{
37+
$this->transparent();
38+
39+
return $this->vibrancy('under-window');
40+
}
41+
42+
public function darkVibrancy(): self
43+
{
44+
return $this->vibrancy('dark');
45+
}
46+
}

src/Events/App/ApplicationBooted.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ApplicationBooted
1010
{
1111
use Dispatchable, InteractsWithSockets, SerializesModels;
1212

13-
public function __construct(public $path)
13+
public function __construct()
1414
{
1515

1616
}

src/Facades/MenuBar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ class MenuBar extends Facade
88
{
99
protected static function getFacadeAccessor()
1010
{
11-
return \Native\Laravel\MenuBar::class;
11+
return \Native\Laravel\MenuBar\MenuBarManager::class;
1212
}
1313
}

src/Facades/Window.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ class Window extends Facade
88
{
99
protected static function getFacadeAccessor()
1010
{
11-
self::clearResolvedInstance(\Native\Laravel\Window::class);
12-
13-
return \Native\Laravel\Window::class;
11+
return \Native\Laravel\Windows\WindowManager::class;
1412
}
1513
}

src/Http/Middleware/PreventRegularBrowserAccess.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public function handle(Request $request, Closure $next)
1717
$cookie = $request->cookie('_php_native');
1818
$header = $request->header('X-NativePHP-Secret');
1919

20-
if ($cookie && $cookie === config('nativephp.secret')) {
20+
if ($cookie && $cookie === config('nativephp-internal.secret')) {
2121
return $next($request);
2222
}
2323

24-
if ($header && $header === config('nativephp.secret')) {
24+
if ($header && $header === config('nativephp-internal.secret')) {
2525
return $next($request);
2626
}
2727

0 commit comments

Comments
 (0)