The AutoUpdater class provides methods to check for, download, and install application updates. It integrates with various update providers including GitHub Releases, AWS S3, and DigitalOcean Spaces.
Available Methods
checkForUpdates()
Check if a new version of your application is available.
use Native\Desktop\Facades\AutoUpdater;
AutoUpdater::checkForUpdates();
This method triggers the update check process. The updater compares your current application version (defined in config/nativephp.php) with the latest available version from your configured update provider.
You can listen for update events to respond to the check results:
use Native\Desktop\Events\Updates\UpdateAvailable;
use Native\Desktop\Events\Updates\NoUpdateAvailable;
Event::listen(UpdateAvailable::class, function ($event) {
// A new update is available
// Show notification to user
});
Event::listen(NoUpdateAvailable::class, function () {
// App is up to date
});
downloadUpdate()
Download the available update without installing it.
use Native\Desktop\Facades\AutoUpdater;
AutoUpdater::downloadUpdate();
This method downloads the update in the background. You can listen for download progress events:
use Native\Desktop\Events\Updates\UpdateDownloadProgress;
use Native\Desktop\Events\Updates\UpdateDownloaded;
Event::listen(UpdateDownloadProgress::class, function ($event) {
// $event->bytesPerSecond
// $event->percent
// $event->transferred
// $event->total
});
Event::listen(UpdateDownloaded::class, function () {
// Download complete, ready to install
});
quitAndInstall()
Quit the application and install the downloaded update.
use Native\Desktop\Facades\AutoUpdater;
AutoUpdater::quitAndInstall();
This method immediately closes your application and begins the update installation process. After installation, the application will restart automatically with the new version.
Make sure the update has been downloaded before calling this method. Otherwise, it will have no effect.
Configuration
The updater is configured in your config/nativephp.php file:
'updater' => [
'enabled' => env('NATIVEPHP_UPDATER_ENABLED', true),
'default' => env('NATIVEPHP_UPDATER_PROVIDER', 'spaces'),
'providers' => [
// Provider configurations
],
],
Updater Options
Whether the updater is enabled. The updater only works in production builds.
The default update provider to use. Supported values: github, s3, spaces.
GitHub Provider
Use GitHub Releases to distribute your updates:
'github' => [
'driver' => 'github',
'repo' => env('GITHUB_REPO'),
'owner' => env('GITHUB_OWNER'),
'token' => env('GITHUB_TOKEN'),
'vPrefixedTagName' => env('GITHUB_V_PREFIXED_TAG_NAME', true),
'private' => env('GITHUB_PRIVATE', false),
'autoupdate_token' => env('GITHUB_AUTOUPDATE_TOKEN'),
'channel' => env('GITHUB_CHANNEL', 'latest'),
'releaseType' => env('GITHUB_RELEASE_TYPE', 'draft'),
],
Your GitHub repository name.
The GitHub username or organization that owns the repository.
GitHub personal access token for accessing private repositories.
Whether your release tags are prefixed with ‘v’ (e.g., v1.0.0).
Whether the repository is private.
Read-only token used by the updater to access private repositories from installed apps.
The release channel to use (e.g., ‘latest’, ‘beta’).
The type of release to publish: ‘draft’ or ‘release’.
S3 Provider
Use AWS S3 or S3-compatible services (like Cloudflare R2):
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'endpoint' => env('AWS_ENDPOINT'),
'path' => env('NATIVEPHP_UPDATER_PATH', null),
'public_url' => env('AWS_PUBLIC_URL'),
],
AWS region (e.g., ‘us-east-1’).
Custom S3 endpoint URL (for S3-compatible services).
Optional path prefix within the bucket.
Optional public URL for serving updates (e.g., CDN or custom domain). When set, updates are downloaded from this URL instead of the S3 endpoint.
Spaces Provider
Use DigitalOcean Spaces:
'spaces' => [
'driver' => 'spaces',
'key' => env('DO_SPACES_KEY_ID'),
'secret' => env('DO_SPACES_SECRET_ACCESS_KEY'),
'name' => env('DO_SPACES_NAME'),
'region' => env('DO_SPACES_REGION'),
'path' => env('NATIVEPHP_UPDATER_PATH', null),
],
DigitalOcean Spaces access key.
DigitalOcean Spaces secret key.
Spaces region (e.g., ‘nyc3’).
Optional path prefix within the Space.
Complete Example
use Native\Desktop\Facades\AutoUpdater;
use Native\Desktop\Events\Updates\UpdateAvailable;
use Native\Desktop\Events\Updates\UpdateDownloaded;
use Illuminate\Support\Facades\Event;
// Check for updates on app startup
AutoUpdater::checkForUpdates();
// Listen for update available
Event::listen(UpdateAvailable::class, function ($event) {
// Show notification to user
Notification::make()
->title('Update Available')
->message('A new version is available. Would you like to download it?')
->show();
// Start downloading
AutoUpdater::downloadUpdate();
});
// Listen for download complete
Event::listen(UpdateDownloaded::class, function () {
// Ask user if they want to install now
Notification::make()
->title('Update Ready')
->message('Update downloaded. Click to install and restart.')
->show();
// When user clicks, call:
// AutoUpdater::quitAndInstall();
});