Skip to content

Commit 739a690

Browse files
committed
fixes
1 parent 88f9e01 commit 739a690

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

README.md

+103-1
Original file line numberDiff line numberDiff line change
@@ -395,4 +395,106 @@ Examples:
395395
- https://awesome-app-distribution.s3.amazonaws.com/ElectronReact.dmg
396396
- https://awesome-app-distribution.s3.amazonaws.com/Awesome+App.dmg
397397

398-
4. Share the URL with your users to download the signed and notarized executable. Hurray! 🎉
398+
4. Share the URL with your users to download the signed and notarized executable. Hurray! 🎉
399+
400+
### ❓ How to Set Up Auto Update for my Electron App?
401+
402+
Electron Builder's auto-update feature makes life much easier for your users by allowing you to push updates without requiring them to manually download and install the new version.
403+
404+
It's a must-have feature for any Electron app.
405+
406+
Here's how to set it up:
407+
408+
---
409+
410+
*Prerequisites:*
411+
- You need to have a workflow in place for pushing your app's installer files to an S3 bucket. If you've followed the earlier FAQ, this should already be set up.
412+
413+
---
414+
415+
*Step-by-Step Guide:*
416+
417+
1. Ensure you have the latest version of Electron Updater:
418+
419+
```
420+
npm install --save-dev electron-updater@latest
421+
```
422+
423+
2. In `src/main/main.ts`, add the following code to check for updates:
424+
425+
```javascript
426+
import { autoUpdater } from 'electron-updater';
427+
428+
class AppUpdater {
429+
constructor() {
430+
// Disable automatic downloading of updates
431+
autoUpdater.autoDownload = false;
432+
// Enable automatic installation of updates on the next computer restart
433+
autoUpdater.autoInstallOnAppQuit = true;
434+
435+
try {
436+
// Start listening for update events
437+
this.listenEvents();
438+
// Check for available updates
439+
autoUpdater.checkForUpdates();
440+
} catch (error) {
441+
console.error(error);
442+
}
443+
}
444+
445+
async listenEvents() {
446+
// Event listener for when the app is checking for updates
447+
autoUpdater.on('checking-for-update', () => {
448+
console.log('Checking for updates...');
449+
});
450+
451+
// Event listener for when an update is available
452+
autoUpdater.on('update-available', (info) => {
453+
console.log('Update available:', info);
454+
// Download the latest version of the update
455+
autoUpdater.downloadUpdate();
456+
});
457+
458+
// Event listener for when no update is available
459+
autoUpdater.on('update-not-available', (info) => {
460+
console.log('Update not available:', info);
461+
});
462+
463+
// Event listener for when an error occurs during the update process
464+
autoUpdater.on('error', (err) => {
465+
console.log('Error in auto-updater:', err);
466+
});
467+
468+
// Event listener for when an update has been downloaded
469+
autoUpdater.on('update-downloaded', (info) => {
470+
console.log('Update downloaded:', info);
471+
});
472+
}
473+
}
474+
```
475+
476+
3. For the best app performance, call the `AppUpdater` constructor after all initializations are done, the main window is created, and your app is ready:
477+
478+
```javascript
479+
new AppUpdater();
480+
```
481+
482+
![Auto Update Position](https://raw.githubusercontent.com/omkarcloud/macos-code-signing-example/master/images/auto-update-position.png)
483+
484+
4. Now, Update your app version in the `release/app/package.json` file:
485+
486+
```json
487+
{
488+
"name": "my-awesome-app",
489+
"version": "1.1.0" // Update this to your new version
490+
}
491+
```
492+
493+
5. Push your changes to the repository.
494+
495+
6. That's it! Now, whenever you push a new version:
496+
- The GitHub Workflow will automatically build and push the new version to your S3 bucket.
497+
- Your app will automatically check for updates and download them in the background.
498+
- When the user restarts their system, the new version will be automatically installed.
499+
500+
![Auto Update](https://raw.githubusercontent.com/omkarcloud/macos-code-signing-example/master/images/auto-update.png)

images/auto-update-position.png

158 KB
Loading

images/auto-update.png

1.37 MB
Loading

0 commit comments

Comments
 (0)