8000 Merge branch 'NativePHP:main' into main · MasterRO94/nativephp-laravel@46d896e · GitHub
[go: up one dir, main page]

Skip to content

Commit 46d896e

Browse files
Merge branch 'NativePHP:main' into main
2 parents 24a8dbb + a4605f0 commit 46d896e

10 files changed

+189
-42
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
All notable changes to `nativephp-laravel` will be documented in this file.
44

5+
## 0.3.0 - 2023-07-31
6+
7+
### What's Changed
8+
9+
- Add native:db:seed command by @phuclh in https://github.com/NativePHP/laravel/pull/82
10+
- Option to show/hide menu on Windows / Linux by @ShaneShipston in https://github.com/NativePHP/laravel/pull/84
11+
- Add tests for `MenuBar` by @milwad-dev in https://github.com/NativePHP/laravel/pull/31
12+
13+
### New Contributors
14+
15+
- @phuclh made their first contribution in https://github.com/NativePHP/laravel/pull/82
16+
- @ShaneShipston made their first contribution in https://github.com/NativePHP/laravel/pull/84
17+
18+
**Full Changelog**: https://github.com/NativePHP/laravel/compare/0.2.0...0.3.0
19+
520
## 0.2.0 - 2023-07-28
621

722
### What's changed

resources/stubs/NativeAppServiceProvider.php.stub

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,26 @@
22

33
namespace App\Providers;
44

5-
use Native\Laravel\Facades\ContextMenu;
6-
use Native\Laravel\Facades\Dock;
75
use Native\Laravel\Facades\Window;
8-
use Native\Laravel\Facades\GlobalShortcut;
9-
use Native\Laravel\Menu\Menu;
6+
use Native\Laravel\Contracts\ProvidesPhpIni;
107

11-
class NativeAppServiceProvider
8+
class NativeAppServiceProvider implements ProvidesPhpIni
129
{
1310
/**
1411
* Executed once the native application has been booted.
1512
* Use this method to open windows, register global shortcuts, etc.
1613
*/
1714
public function boot(): void
1815
{
19-
Menu::new()
20-
->appMenu()
21-
->submenu('About', Menu::new()
22-
->link('https://beyondco.de', 'Beyond Code')
23-
->link('https://simonhamp.me', 'Simon Hamp')
24-
)
25-
->submenu('View', Menu::new()
26-
->toggleFullscreen()
27-
->separator()
28-
->link('https://laravel.com', 'Learn More', 'CmdOrCtrl+L')
29-
)
30-
->register();
31-
32-
Window::open()
33-
->width(800)
34-
->height(800);
35-
36-
/**
37-
Dock::menu(
38-
Menu::new()
39-
->event(DockItemClicked::class, 'Settings')
40-
->submenu('Help',
41-
Menu::new()
42-
->event(DockItemClicked::class, 'About')
43-
->event(DockItemClicked::class, 'Learn More…')
44-
)
45-
);
46-
47-
ContextMenu::register(
48-
Menu::new()
49-
->event(ContextMenuClicked::class, 'Do something')
50-
);
16+
Window::open();
17+
}
5118

52-
GlobalShortcut::new()
53-
->key('CmdOrCtrl+Shift+I')
54-
->event(ShortcutPressed::class)
55-
->register();
56-
*/
19+
/**
20+
* Return an array of php.ini directives to be set.
21+
*/
22+
public function phpIni(): array
23+
{
24+
return [
25+
];
5726
}
5827
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Native\Laravel\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Native\Laravel\Contracts\ProvidesPhpIni;
7+
8+
class LoadPHPConfigurationCommand extends Command
9+
{
10+
protected $signature = 'native:php-ini';
11+
12+
public function handle()
13+
{
14+
/** @var ProvidesPhpIni $provider */
15+
$provider = app(config('nativephp.provider'));
16+
$phpIni = [];
17+
if (method_exists($provider, 'phpIni')) {
18+
$phpIni = $provider->phpIni();
19+
}
20+
echo json_encode($phpIni);
21+
}
22+
}

src/Commands/SeedDatabaseCommand.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\Commands;
4+
5+
use Illuminate\Database\Console\Seeds\SeedCommand as BaseSeedCommand;
6+
use Native\Laravel\NativeServiceProvider;
7+
8+
class SeedDatabaseCommand extends BaseSeedCommand
9+
{
10+
protected $name = 'native:db:seed';
11+
12+
protected $description = 'Run the database seeders in the NativePHP development environment';
13+
14+
public function handle()
15+
{
16+
(new NativeServiceProvider($this->laravel))->rewriteDatabase();
17+
18+
parent::handle();
19+
}
20+
}

src/Contracts/ProvidesPhpIni.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Native\Laravel\Contracts;
4+
5+
interface ProvidesPhpIni
6+
{
7+
public function phpIni(): array;
8+
}

src/DataObjects/Printer.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Native\Laravel\DataObjects;
4+
5+
class Printer
6+
{
7+
public function __construct(
8+
public string $name,
9+
public string $displayName,
10+
public string $description,
11+
public int $status,
12+
public bool $isDefault,
13+
public array $options
14+
) {
15+
16+
}
17+
}

src/NativeServiceProvider.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line number AE8F Diff line change
@@ -3,6 +3,7 @@
33
namespace Native\Laravel;
44

55
use Illuminate\Support\Arr;
6+
use Native\Laravel\Commands\LoadPHPConfigurationCommand;
67
use Native\Laravel\Commands\LoadStartupConfigurationCommand;
78
use Native\Laravel\Commands\MigrateCommand;
89
use Native\Laravel\Commands\MinifyApplicationCommand;
@@ -20,6 +21,7 @@ public function configurePackage(Package $package): void
2021
MigrateCommand::class,
2122
MinifyApplicationCommand::class,
2223
LoadStartupConfigurationCommand::class,
24+
LoadPHPConfigurationCommand::class,
2325
])
2426
->hasConfigFile()
2527
->hasRoute('api')
@@ -49,6 +51,8 @@ protected function configureApp()
4951

5052
$this->rewriteDatabase();
5153

54+
$this->configureDisks();
55+
5256
config(['session.driver' => 'file']);
5357
config(['queue.default' => 'database']);
5458
}
@@ -96,4 +100,32 @@ public function rewriteDatabase()
96100

97101
config(['database.default' => 'nativephp']);
98102
}
103+
104+
protected function configureDisks(): void
105+
{
106+
$disks = [
107+
'NATIVEPHP_USER_HOME_PATH' => 'user_home',
108+
'NATIVEPHP_APP_DATA_PATH' => 'app_data',
109+
'NATIVEPHP_USER_DATA_PATH' => 'user_data',
110+
'NATIVEPHP_DESKTOP_PATH' => 'desktop',
111+
'NATIVEPHP_DOCUMENTS_PATH' => 'documents',
112+
'NATIVEPHP_DOWNLOADS_PATH' => 'downloads',
113+
'NATIVEPHP_MUSIC_PATH' => 'music',
114+
'NATIVEPHP_PICTURES_PATH' => 'pictures',
115+
'NATIVEPHP_VIDEOS_PATH' => 'videos',
116+
'NATIVEPHP_RECENT_PATH' => 'recent',
117+
];
118+
119+
foreach ($disks as $env => $disk) {
120+
if (! env($env)) {
121+
continue;
122+
}
123+
124+
config(['filesystems.disks.'.$disk => [
125+
'driver' => 'local',
126+
'root' => env($env, ''),
127+
'throw' => false,
128+
]]);
129+
}
130+
}
99131
}

src/System.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Native\Laravel;
44

55
use Native\Laravel\Client\Client;
6+
use Native\Laravel\DataObjects\Printer;
67

78
class System
89
{
@@ -21,4 +22,31 @@ public function promptTouchID(string $reason): bool
2122
'reason' => $reason,
2223
])->successful();
2324
}
25+
26+
/**
27+
* @return array<\Native\Laravel\DataObjects\Printer>
28+
*/
29+
public function printers(): array
30+
{
31+
$printers = $this->client->get('system/printers')->json('printers');
32+
33+
return collect($printers)->map(function ($printer) {
34+
return new Printer(
35+
data_get($printer, 'name'),
36+
data_get($printer, 'displayName'),
37+
data_get($printer, 'description'),
38+
data_get($printer, 'status'),
39+
data_get($printer, 'isDefault'),
40+
data_get($printer, 'options'),
41+
);
42+
})->toArray();
43+
}
44+
45+
public function print(string $html, Printer $printer = null): void
46+
{
47+
$this->client->post('system/print', [
48+
'html' => $html,
49+
'printer' => $printer->name ?? '',
50+
]);
51+
}
2452
}

src/Windows/Window.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class Window
1313
use HasDimensions;
1414
use HasUrl;
1515

16+
protected bool $autoHideMenuBar = false;
17+
1618
protected bool $fullscreen = false;
1719

1820
protected bool $kiosk = false;
@@ -184,6 +186,13 @@ public function invisibleFrameless(): self
184186
->hasShadow(false);
185187
}
186188

189+
public function hideMenu($autoHideMenuBar = true): static
190+
{
191+
$this->autoHideMenuBar = $autoHideMenuBar;
192+
193+
return $this;
194+
}
195+
187196
public function fullscreen($fullscreen = false): static
188197
{
189198
$this->fullscreen = $fullscreen;
@@ -229,6 +238,7 @@ public function toArray()
229238
'title' => $this->title,
230239
'fullscreen' => $this->fullscreen,
231240
'kiosk' => $this->kiosk,
241+
'autoHideMenuBar' => $this->autoHideMenuBar,
232242
];
233243
}
234244
}

tests/MenuBar/MenuBarTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Native\Laravel\Facades\MenuBar;
4+
use Native\Laravel\Menu\Menu;
5+
6+
it('menubar with create', function () {
7+
config()->set('nativephp-internal.api_url', 'https://jsonplaceholder.typicode.com/todos/1');
8+
9+
$menuBar = MenuBar::create()
10+
->showDockIcon()
11+
->alwaysOnTop()
12+
->label('milwad')
13+
->icon('nativephp.png')
14+
->url('https://github.com/milwad-dev')
15+
->withContextMenu(
16+
Menu::new()->label('My Application')->quit(),
17+
);
18+
$menuBarArray = $menuBar->toArray();
19+
20+
$this->assertTrue($menuBarArray['showDockIcon']);
21+
$this->assertTrue($menuBarArray['alwaysOnTop']);
22+
$this->assertEquals('milwad', $menuBarArray['label']);
23+
$this->assertEquals('https://github.com/milwad-dev', $menuBarArray['url']);
24+
$this->assertEquals('nativephp.png', $menuBarArray['icon']);
25+
$this->assertIsArray($menuBarArray['contextMenu']);
26+
});

0 commit comments

Comments
 (0)
0