You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
+
classAppUpdater {
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
+
asynclistenEvents() {
446
+
// Event listener for when the app is checking for updates
// 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:
0 commit comments