Skip to content

Commit 94db3a1

Browse files
committed
Actualize Saucer v8 API
1 parent 93e8470 commit 94db3a1

File tree

9 files changed

+358
-228
lines changed

9 files changed

+358
-228
lines changed

resources/stubs/saucer.stub.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Boson\Internal\WebView {
44

5+
use Boson\Component\Saucer\Policy;
56
use Boson\Component\Saucer\State;
7+
use Boson\Component\Saucer\Status;
68
use FFI\CData;
79

810
/**
@@ -14,18 +16,28 @@
1416
*/
1517
final class CSaucerWebViewEventsStruct extends CData
1618
{
19+
/**
20+
* @var null|\Closure(CData, CData, CData):(Status::SAUCER_STATE_*)
21+
*/
22+
public null|\Closure $onPermissionRequested;
23+
24+
/**
25+
* @var null|\Closure(CData, bool, CData):(Policy::SAUCER_POLICY_*)
26+
*/
27+
public null|\Closure $onFullscreen;
28+
1729
/**
1830
* @var null|\Closure(CData, CData):void
1931
*/
2032
public null|\Closure $onDomReady;
2133

2234
/**
23-
* @var null|\Closure(CData, string, CData):void
35+
* @var null|\Closure(CData, CData, CData):void
2436
*/
2537
public null|\Closure $onNavigated;
2638

2739
/**
28-
* @var null|\Closure(CData, CData, CData):void
40+
* @var null|\Closure(CData, CData, CData):(Policy::SAUCER_POLICY_*)
2941
*/
3042
public null|\Closure $onNavigating;
3143

@@ -35,7 +47,7 @@ final class CSaucerWebViewEventsStruct extends CData
3547
public null|\Closure $onFaviconChanged;
3648

3749
/**
38-
* @var null|\Closure(CData, string, CData):void
50+
* @var null|\Closure(CData, string, int<0, max>, CData):void
3951
*/
4052
public null|\Closure $onTitleChanged;
4153

@@ -45,7 +57,7 @@ final class CSaucerWebViewEventsStruct extends CData
4557
public null|\Closure $onLoad;
4658

4759
/**
48-
* @var null|\Closure(CData, string, int<0, max>, CData):void
60+
* @var null|\Closure(CData, string, int<0, max>, CData):(Status::SAUCER_STATE_*)
4961
*/
5062
public null|\Closure $onMessage;
5163
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Boson\Api\Dialog\Exception;
6+
7+
use Boson\Exception\ApplicationApiException;
8+
9+
class DialogException extends ApplicationApiException {}
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\Api\Dialog\Exception;
6+
7+
class InternalErrorDialogException extends DialogException {}

src/Api/Dialog/SaucerDialogApi.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
use Boson\Api\Dialog\Event\FilesSelecting;
1212
use Boson\Api\Dialog\Event\UriOpened;
1313
use Boson\Api\Dialog\Event\UriOpening;
14+
use Boson\Api\Dialog\Exception\InternalErrorDialogException;
1415
use Boson\Api\LoadedApplicationExtension;
16+
use Boson\Application;
17+
use Boson\Dispatcher\EventListener;
1518
use Boson\Shared\Marker\RequiresDealloc;
1619
use FFI\CData;
1720

@@ -27,6 +30,15 @@ final class SaucerDialogApi extends LoadedApplicationExtension implements
2730
get => $this->app->saucer->saucer_desktop_new(parent::$ptr::get());
2831
}
2932

33+
private readonly int $isCanceledCode;
34+
35+
public function __construct(Application $app, EventListener $listener)
36+
{
37+
parent::__construct($app, $listener);
38+
39+
$this->isCanceledCode = $this->app->saucer->boson_error_code_canceled();
40+
}
41+
3042
private function applyDirectory(CData $options, ?string $directory): void
3143
{
3244
$directory ??= \getcwd();
@@ -79,8 +91,14 @@ private function selectOne(?string $directory, array $filter, \Closure $selector
7991
$options = $this->createOptions($directory, $filter);
8092

8193
try {
94+
$error = $this->saucer->new('int');
95+
8296
$length = $this->saucer->new('size_t');
83-
$selector($this->ptr, $options, null, \FFI::addr($length), null);
97+
$selector($this->ptr, $options, null, \FFI::addr($length), \FFI::addr($error));
98+
99+
if ($error->cdata !== 0 && $error->cdata !== $this->isCanceledCode) {
100+
throw new InternalErrorDialogException('An error occurred while selecting a file/directory', $error->cdata);
101+
}
84102

85103
if ($length->cdata === 0) {
86104
return null;
@@ -106,8 +124,14 @@ private function selectMany(?string $directory, array $filter, \Closure $selecto
106124
$options = $this->createOptions($directory, $filter);
107125

108126
try {
127+
$error = $this->saucer->new('int');
128+
109129
$length = $this->saucer->new('size_t');
110-
$selector($this->ptr, $options, null, \FFI::addr($length), null);
130+
$selector($this->ptr, $options, null, \FFI::addr($length), \FFI::addr($error));
131+
132+
if ($error->cdata !== 0 && $error->cdata !== $this->isCanceledCode) {
133+
throw new InternalErrorDialogException('An error occurred while selecting a files/directories', $error->cdata);
134+
}
111135

112136
if ($length->cdata === 0) {
113137
return [];

0 commit comments

Comments
 (0)