Skip to content

Commit 8330e4d

Browse files
committed
Fix windows sizes update (before get) and a little typos
1 parent d29a2c8 commit 8330e4d

13 files changed

Lines changed: 139 additions & 151 deletions

src/Api/CentralProcessor/CentralProcessorInfo.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,16 @@ public function isSupports(InstructionSetInterface $instructionSet): bool
4646
{
4747
return $this->cpu->isSupports($instructionSet);
4848
}
49+
50+
public function __debugInfo(): array
51+
{
52+
return [
53+
'arch' => $this->arch,
54+
'vendor' => $this->vendor,
55+
'name' => $this->name,
56+
'cores' => $this->cores,
57+
'threads' => $this->threads,
58+
'instructionSets' => $this->instructionSets,
59+
];
60+
}
4961
}

src/Api/Console/ConsoleExtension.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
use Boson\Component\OsInfo\Family;
1515
use Boson\Contracts\Id\IdentifiableInterface;
1616
use Boson\Dispatcher\EventListener;
17-
use Boson\Extension\Attribute\AvailableAs;
1817
use Boson\Extension\Attribute\DependsOn;
1918
use Boson\Extension\Extension;
2019
use FFI\Env\Runtime;
2120

2221
/**
2322
* @template-extends Extension<Application>
2423
*/
25-
#[AvailableAs('console', ConsoleApiInterface::class)]
2624
#[DependsOn(OperatingSystemExtension::class)]
2725
final class ConsoleExtension extends Extension
2826
{

src/Api/Dialog/DialogApiInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@
99
*/
1010
interface DialogApiInterface extends
1111
FileOpenerInterface,
12-
FileSelectorInterface,
13-
DirectorySelectorInterface {}
12+
FileSelectorInterface {}

src/Api/Dialog/DirectorySelectorInterface.php

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/Api/Dialog/Event/DirectoriesSelecting.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Api/Dialog/FileSelectorInterface.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,30 @@ interface FileSelectorInterface
99
/**
1010
* Opens a system dialog to open a specific file.
1111
*
12-
* @param non-empty-string|null $directory
12+
* @param non-empty-string|null $path
1313
* @param iterable<mixed, non-empty-string> $filter
1414
*
1515
* @return non-empty-string|null
1616
*/
17-
public function selectFile(?string $directory = null, iterable $filter = []): ?string;
17+
public function selectFile(?string $path = null, iterable $filter = []): ?string;
1818

1919
/**
20-
* Opens a system dialog to open list of specific files.
20+
* Opens a system dialog to open a specific directory.
2121
*
22-
* @param non-empty-string|null $directory
22+
* @param non-empty-string|null $path
23+
* @param iterable<mixed, non-empty-string> $filter
24+
*
25+
* @return non-empty-string|null
26+
*/
27+
public function selectDirectory(?string $path = null, iterable $filter = []): ?string;
28+
29+
/**
30+
* Opens a system dialog to open a list of specific files.
31+
*
32+
* @param non-empty-string|null $path
2333
* @param iterable<mixed, non-empty-string> $filter
2434
*
2535
* @return iterable<array-key, non-empty-string>
2636
*/
27-
public function selectFiles(?string $directory = null, iterable $filter = []): iterable;
37+
public function selectFiles(?string $path = null, iterable $filter = []): iterable;
2838
}

src/Api/Dialog/SaucerDialogApi.php

Lines changed: 41 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Boson\Api\Dialog;
66

7-
use Boson\Api\Dialog\Event\DirectoriesSelecting;
87
use Boson\Api\Dialog\Event\DirectorySelected;
98
use Boson\Api\Dialog\Event\DirectorySelecting;
109
use Boson\Api\Dialog\Event\FileSelected;
@@ -13,6 +12,7 @@
1312
use Boson\Api\Dialog\Event\UriOpened;
1413
use Boson\Api\Dialog\Event\UriOpening;
1514
use Boson\Api\LoadedApplicationExtension;
15+
use Boson\Shared\Marker\RequiresDealloc;
1616
use FFI\CData;
1717

1818
/**
@@ -31,36 +31,33 @@ private function applyDirectory(CData $options, ?string $directory): void
3131
{
3232
$directory ??= \getcwd();
3333

34-
if (\is_string($directory) && $directory !== '') {
35-
$this->app->saucer->saucer_picker_options_set_initial($options, $directory);
34+
if (!\is_string($directory) || $directory === '') {
35+
return;
3636
}
37+
38+
$this->app->saucer->saucer_picker_options_set_initial($options, $directory);
3739
}
3840

3941
/**
40-
* @param iterable<mixed, mixed> $filter
42+
* @param list<non-empty-string> $filter
4143
*/
42-
private function applyFilter(CData $options, iterable $filter): void
44+
private function applyFilter(CData $options, array $filter): void
4345
{
44-
$index = 0;
45-
46-
foreach ($filter as $item) {
47-
++$index;
48-
49-
if (\is_string($item) && $item !== '') {
50-
$this->app->saucer->saucer_picker_options_add_filter($options, $item);
51-
continue;
52-
}
53-
54-
throw new \InvalidArgumentException(\sprintf(
55-
'Filter #%d element must be a non empty string',
56-
$index - 1,
57-
));
46+
if ($filter === []) {
47+
return;
5848
}
49+
50+
$this->app->saucer->saucer_picker_options_set_filters(
51+
$options,
52+
$filterAsString = \implode("\0", $filter),
53+
\strlen($filterAsString),
54+
);
5955
}
6056

6157
/**
6258
* @param list<non-empty-string> $filter
6359
*/
60+
#[RequiresDealloc]
6461
private function createOptions(?string $directory, array $filter): CData
6562
{
6663
$options = $this->app->saucer->saucer_picker_options_new();
@@ -73,7 +70,7 @@ private function createOptions(?string $directory, array $filter): CData
7370

7471
/**
7572
* @param list<non-empty-string> $filter
76-
* @param \Closure(CData, CData): ?CData $selector
73+
* @param \Closure(CData, CData, CData|null, CData|null, CData|null): ?CData $selector
7774
*
7875
* @return non-empty-string|null
7976
*/
@@ -82,15 +79,17 @@ private function selectOne(?string $directory, array $filter, \Closure $selector
8279
$options = $this->createOptions($directory, $filter);
8380

8481
try {
85-
$pointer = $selector($this->ptr, $options);
82+
$length = $this->saucer->new('size_t');
83+
$selector($this->ptr, $options, null, \FFI::addr($length), null);
8684

87-
if ($pointer === null || \FFI::isNull($pointer)) {
85+
if ($length->cdata === 0) {
8886
return null;
8987
}
9088

91-
$result = \FFI::string($pointer);
89+
$result = $this->saucer->new("char[{$length->cdata}]");
90+
$selector($this->ptr, $options, \FFI::addr($result[0]), \FFI::addr($length), null);
9291

93-
return $result === '' ? null : $result;
92+
return \FFI::string(\FFI::addr($result[0]), $length->cdata);
9493
} finally {
9594
$this->app->saucer->saucer_picker_options_free($options);
9695
}
@@ -106,25 +105,18 @@ private function selectMany(?string $directory, array $filter, \Closure $selecto
106105
{
107106
$options = $this->createOptions($directory, $filter);
108107

109-
$result = [];
110108
try {
111-
$pointer = $selector($this->ptr, $options);
109+
$length = $this->saucer->new('size_t');
110+
$selector($this->ptr, $options, null, \FFI::addr($length), null);
112111

113-
if ($pointer === null || \FFI::isNull($pointer)) {
112+
if ($length->cdata === 0) {
114113
return [];
115114
}
116115

117-
/** @phpstan-ignore-next-line : The $pointer[$i] is CData|null */
118-
for ($i = 0; !\FFI::isNull($pointer[$i]); ++$i) {
119-
/** @phpstan-ignore-next-line : The $pointer[$i] is CData */
120-
$item = \FFI::string($pointer[$i]);
116+
$result = $this->saucer->new("char[{$length->cdata}]");
117+
$selector($this->ptr, $options, \FFI::addr($result[0]), \FFI::addr($length), null);
121118

122-
if ($item !== '') {
123-
$result[] = $item;
124-
}
125-
}
126-
127-
return $result;
119+
return \explode("\0", \FFI::string(\FFI::addr($result[0]), $length->cdata));
128120
} finally {
129121
$this->app->saucer->saucer_picker_options_free($options);
130122
}
@@ -145,55 +137,35 @@ public function open(string|\Stringable $uri): void
145137
$this->dispatch(new UriOpened($this->app, $uri));
146138
}
147139

148-
public function selectDirectory(?string $directory = null, iterable $filter = []): ?string
140+
public function selectDirectory(?string $path = null, iterable $filter = []): ?string
149141
{
150-
if (!$this->intent(new DirectorySelecting($this->app, $directory, $filter))) {
142+
if (!$this->intent(new DirectorySelecting($this->app, $path, $filter))) {
151143
return null;
152144
}
153145

154146
$filter = \iterator_to_array($filter, false);
155147

156-
$result = $this->selectOne($directory, $filter, $this->app->saucer->saucer_desktop_pick_folder(...));
148+
$result = $this->selectOne($path, $filter, $this->app->saucer->saucer_picker_pick_folder(...));
157149

158150
if ($result !== null) {
159-
$this->dispatch(new DirectorySelected($this->app, $result, $directory, $filter));
151+
$this->dispatch(new DirectorySelected($this->app, $result, $path, $filter));
160152
}
161153

162154
return $result;
163155
}
164156

165-
public function selectFile(?string $directory = null, iterable $filter = []): ?string
157+
public function selectFile(?string $path = null, iterable $filter = []): ?string
166158
{
167-
if (!$this->intent(new FileSelecting($this->app, $directory, $filter))) {
159+
if (!$this->intent(new FileSelecting($this->app, $path, $filter))) {
168160
return null;
169161
}
170162

171163
$filter = \iterator_to_array($filter, false);
172164

173-
$result = $this->selectOne($directory, $filter, $this->app->saucer->saucer_desktop_pick_file(...));
165+
$result = $this->selectOne($path, $filter, $this->app->saucer->saucer_picker_pick_file(...));
174166

175167
if ($result !== null) {
176-
$this->dispatch(new FileSelected($this->app, $result, $directory, $filter));
177-
}
178-
179-
return $result;
180-
}
181-
182-
/**
183-
* @return list<non-empty-string>
184-
*/
185-
public function selectFiles(?string $directory = null, iterable $filter = []): array
186-
{
187-
if (!$this->intent(new FilesSelecting($this->app, $directory, $filter))) {
188-
return [];
189-
}
190-
191-
$filter = \iterator_to_array($filter, false);
192-
193-
$result = $this->selectMany($directory, $filter, $this->app->saucer->saucer_desktop_pick_files(...));
194-
195-
foreach ($result as $selection) {
196-
$this->dispatch(new FileSelected($this->app, $selection, $directory, $filter));
168+
$this->dispatch(new FileSelected($this->app, $result, $path, $filter));
197169
}
198170

199171
return $result;
@@ -202,18 +174,18 @@ public function selectFiles(?string $directory = null, iterable $filter = []): a
202174
/**
203175
* @return list<non-empty-string>
204176
*/
205-
public function selectDirectories(?string $directory = null, iterable $filter = []): array
177+
public function selectFiles(?string $path = null, iterable $filter = []): array
206178
{
207-
if (!$this->intent(new DirectoriesSelecting($this->app, $directory, $filter))) {
179+
if (!$this->intent(new FilesSelecting($this->app, $path, $filter))) {
208180
return [];
209181
}
210182

211183
$filter = \iterator_to_array($filter, false);
212184

213-
$result = $this->selectMany($directory, $filter, $this->app->saucer->saucer_desktop_pick_folders(...));
185+
$result = $this->selectMany($path, $filter, $this->app->saucer->saucer_picker_pick_files(...));
214186

215187
foreach ($result as $selection) {
216-
$this->dispatch(new DirectorySelected($this->app, $selection, $directory, $filter));
188+
$this->dispatch(new FileSelected($this->app, $selection, $path, $filter));
217189
}
218190

219191
return $result;

src/Api/OperatingSystem/OperatingSystemInfo.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,15 @@ public function isSupports(StandardInterface $standard): bool
4646
{
4747
return $this->os->isSupports($standard);
4848
}
49+
50+
public function __debugInfo(): array
51+
{
52+
return [
53+
'name' => $this->name,
54+
'version' => $this->version,
55+
'edition' => $this->edition,
56+
'family' => $this->family,
57+
'standards' => $this->standards,
58+
];
59+
}
4960
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\Exception;
6+
7+
class ApplicationApiException extends ApplicationException {}

src/WebView/Api/LifecycleEvents/LifecycleEventsListener.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Boson\WebView\Event\WebViewMessageReceived;
1818
use Boson\WebView\Event\WebViewNavigated;
1919
use Boson\WebView\Event\WebViewNavigating;
20+
use Boson\WebView\Event\WebViewStateChanged;
2021
use Boson\WebView\Event\WebViewTitleChanged;
2122
use Boson\WebView\Event\WebViewTitleChanging;
2223
use Boson\WebView\WebView;
@@ -85,7 +86,18 @@ public function __construct(
8586

8687
private function changeState(WebViewState $state): void
8788
{
89+
$before = $this->state->getRawValue($this->webview);
90+
91+
if ($before === $state) {
92+
return;
93+
}
94+
8895
$this->state->setRawValue($this->webview, $state);
96+
97+
$this->dispatch(new WebViewStateChanged(
98+
subject: $this->webview,
99+
state: $state,
100+
));
89101
}
90102

91103
private function createEventHandlers(): CData

0 commit comments

Comments
 (0)