Skip to content

Commit 3b79aa9

Browse files
authored
Add support for detailed auto-updater event handling (#590)
Expanded event constructors to include more detailed update metadata such as version, files, release information, and system requirements. Added a `downloadUpdate` method to the AutoUpdater facade. These updates enhance event broadcasting and improve client interaction with the auto-updater.
1 parent 2aa5e4f commit 3b79aa9

File tree

8 files changed

+78
-4
lines changed

8 files changed

+78
-4
lines changed

src/AutoUpdater.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ public function quitAndInstall(): void
1717
{
1818
$this->client->post('auto-updater/quit-and-install');
1919
}
20+
21+
public function downloadUpdate(): void
22+
{
23+
$this->client->post('auto-updater/download-update');
24+
}
2025
}

src/Events/AutoUpdater/DownloadProgress.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ class DownloadProgress implements ShouldBroadcastNow
1212
{
1313
use Dispatchable, InteractsWithSockets, SerializesModels;
1414

15-
public function __construct(public int $total, public int $delta, public int $transferred, public float $percent, public int $bytesPerSecond) {}
15+
public function __construct(
16+
public int $total,
17+
public int $delta,
18+
public int $transferred,
19+
public float $percent,
20+
public int $bytesPerSecond
21+
) {}
1622

1723
public function broadcastOn()
1824
{

src/Events/AutoUpdater/Error.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ class Error implements ShouldBroadcastNow
1212
{
1313
use Dispatchable, InteractsWithSockets, SerializesModels;
1414

15-
public function __construct(public string $error) {}
15+
public function __construct(
16+
public string $name,
17+
public string $message,
18+
public ?string $stack,
19+
) {}
1620

1721
public function broadcastOn()
1822
{

src/Events/AutoUpdater/UpdateAvailable.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ class UpdateAvailable implements ShouldBroadcastNow
1212
{
1313
use Dispatchable, InteractsWithSockets, SerializesModels;
1414

15-
public function __construct() {}
15+
public function __construct(
16+
public string $version,
17+
public array $files,
18+
public string $releaseDate,
19+
public ?string $releaseName,
20+
public string|array|null $releaseNotes,
21+
public ?int $stagingPercentage,
22+
public ?string $minimumSystemVersion,
23+
) {}
1624

1725
public function broadcastOn()
1826
{
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Native\Laravel\Events\AutoUpdater;
4+
5+
use Illuminate\Broadcasting\Channel;
6+
use Illuminate\Broadcasting\InteractsWithSockets;
7+
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
8+
use Illuminate\Foundation\Events\Dispatchable;
9+
use Illuminate\Queue\SerializesModels;
10+
11+
class UpdateCancelled implements ShouldBroadcastNow
12+
{
13+
use Dispatchable, InteractsWithSockets, SerializesModels;
14+
15+
public function __construct(
16+
public string $version,
17+
public array $files,
18+
public string $releaseDate,
19+
public ?string $releaseName,
20+
public string|array|null $releaseNotes,
21+
public ?int $stagingPercentage,
22+
public ?string $minimumSystemVersion,
23+
) {}
24+
25+
public function broadcastOn()
26+
{
27+
return [
28+
new Channel('nativephp'),
29+
];
30+
}
31+
}

src/Events/AutoUpdater/UpdateDownloaded.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ class UpdateDownloaded implements ShouldBroadcastNow
1212
{
1313
use Dispatchable, InteractsWithSockets, SerializesModels;
1414

15-
public function __construct(public string $version, public string $downloadedFile, public string $releaseDate, public ?string $releaseNotes, public ?string $releaseName) {}
15+
public function __construct(
16+
public string $downloadedFile,
17+
public string $version,
18+
public array $files,
19+
public string $releaseDate,
20+
public ?string $releaseName,
21+
public string|array|null $releaseNotes,
22+
public ?int $stagingPercentage,
23+
public ?string $minimumSystemVersion
24+
) {}
1625

1726
public function broadcastOn()
1827
{

src/Events/AutoUpdater/UpdateNotAvailable.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ class UpdateNotAvailable implements ShouldBroadcastNow
1212
{
1313
use Dispatchable, InteractsWithSockets, SerializesModels;
1414

15+
public function __construct(
16+
public string $version,
17+
public array $files,
18+
public string $releaseDate,
19+
public ?string $releaseName,
20+
public string|array|null $releaseNotes,
21+
public ?int $stagingPercentage,
22+
public ?string $minimumSystemVersion,
23+
) {}
24+
1525
public function broadcastOn()
1626
{
1727
return [

src/Facades/AutoUpdater.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
/**
88
* @method static void checkForUpdates()
99
* @method static void quitAndInstall()
10+
* @method static void downloadUpdate()
1011
*/
1112
class AutoUpdater extends Facade
1213
{

0 commit comments

Comments
 (0)