Skip to content

Add AutoUpdater feature with events and facade support #570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/AutoUpdater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Native\Laravel;

use Native\Laravel\Client\Client;

class AutoUpdater
{
public function __construct(protected Client $client) {}

public function checkForUpdates(): void
{
$this->client->post('auto-updater/check-for-updates');
}

public function quitAndInstall(): void
{
$this->client->post('auto-updater/quit-and-install');
}
}
23 changes: 23 additions & 0 deletions src/Events/AutoUpdater/CheckingForUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Native\Laravel\Events\AutoUpdater;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class CheckingForUpdate implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct() {}

public function broadcastOn()
{
return [
new Channel('nativephp'),
];
}
}
23 changes: 23 additions & 0 deletions src/Events/AutoUpdater/DownloadProgress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Native\Laravel\Events\AutoUpdater;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class DownloadProgress implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct(public int $total, public int $delta, public int $transferred, public float $percent, public int $bytesPerSecond) {}

public function broadcastOn()
{
return [
new Channel('nativephp'),
];
}
}
23 changes: 23 additions & 0 deletions src/Events/AutoUpdater/Error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Native\Laravel\Events\AutoUpdater;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class Error implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct(public string $error) {}

public function broadcastOn()
{
return [
new Channel('nativephp'),
];
}
}
23 changes: 23 additions & 0 deletions src/Events/AutoUpdater/UpdateAvailable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Native\Laravel\Events\AutoUpdater;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class UpdateAvailable implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct() {}

public function broadcastOn()
{
return [
new Channel('nativephp'),
];
}
}
23 changes: 23 additions & 0 deletions src/Events/AutoUpdater/UpdateDownloaded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Native\Laravel\Events\AutoUpdater;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class UpdateDownloaded implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function __construct(public string $version, public string $downloadedFile, public string $releaseDate, public ?string $releaseNotes, public ?string $releaseName) {}

public function broadcastOn()
{
return [
new Channel('nativephp'),
];
}
}
21 changes: 21 additions & 0 deletions src/Events/AutoUpdater/UpdateNotAvailable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Native\Laravel\Events\AutoUpdater;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class UpdateNotAvailable implements ShouldBroadcastNow
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public function broadcastOn()
{
return [
new Channel('nativephp'),
];
}
}
17 changes: 17 additions & 0 deletions src/Facades/AutoUpdater.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Native\Laravel\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static void checkForUpdates()
* @method static void quitAndInstall()
*/
class AutoUpdater extends Facade
{
protected static function getFacadeAccessor()
{
return \Native\Laravel\AutoUpdater::class;
}
}
Loading