| 696 | |
| 697 | // Auto-update initialization |
| 698 | async function initAutoUpdater() { |
| 699 | try { |
| 700 | const autoUpdateEnabled = await settingsService.getAutoUpdateSetting(); |
| 701 | if (!autoUpdateEnabled) { |
| 702 | console.log('[AutoUpdater] Skipped because auto-updates are disabled in settings'); |
| 703 | return; |
| 704 | } |
| 705 | // Skip auto-updater in development mode |
| 706 | if (!app.isPackaged) { |
| 707 | console.log('[AutoUpdater] Skipped in development (app is not packaged)'); |
| 708 | return; |
| 709 | } |
| 710 | |
| 711 | autoUpdater.setFeedURL({ |
| 712 | provider: 'github', |
| 713 | owner: 'pickle-com', |
| 714 | repo: 'glass', |
| 715 | }); |
| 716 | |
| 717 | // Immediately check for updates & notify |
| 718 | autoUpdater.checkForUpdatesAndNotify() |
| 719 | .catch(err => { |
| 720 | console.error('[AutoUpdater] Error checking for updates:', err); |
| 721 | }); |
| 722 | |
| 723 | autoUpdater.on('checking-for-update', () => { |
| 724 | console.log('[AutoUpdater] Checking for updates…'); |
| 725 | }); |
| 726 | |
| 727 | autoUpdater.on('update-available', (info) => { |
| 728 | console.log('[AutoUpdater] Update available:', info.version); |
| 729 | }); |
| 730 | |
| 731 | autoUpdater.on('update-not-available', () => { |
| 732 | console.log('[AutoUpdater] Application is up-to-date'); |
| 733 | }); |
| 734 | |
| 735 | autoUpdater.on('error', (err) => { |
| 736 | console.error('[AutoUpdater] Error while updating:', err); |
| 737 | }); |
| 738 | |
| 739 | autoUpdater.on('update-downloaded', (info) => { |
| 740 | console.log(`[AutoUpdater] Update downloaded: ${info.version}`); |
| 741 | |
| 742 | const dialogOpts = { |
| 743 | type: 'info', |
| 744 | buttons: ['Install now', 'Install on next launch'], |
| 745 | title: 'Update Available', |
| 746 | message: 'A new version of Glass is ready to be installed.', |
| 747 | defaultId: 0, |
| 748 | cancelId: 1 |
| 749 | }; |
| 750 | |
| 751 | dialog.showMessageBox(dialogOpts).then((returnValue) => { |
| 752 | // returnValue.response 0 is for 'Install Now' |
| 753 | if (returnValue.response === 0) { |
| 754 | autoUpdater.quitAndInstall(); |
| 755 | } |