|
| 1 | +/* |
| 2 | + * Wire |
| 3 | + * Copyright (C) 2025 Wire Swiss GmbH |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see http://www.gnu.org/licenses/. |
| 17 | + * |
| 18 | + */ |
| 19 | + |
| 20 | +import {BrowserWindow, dialog} from 'electron'; |
| 21 | +import {autoUpdater} from 'electron-updater'; |
| 22 | + |
| 23 | +import {getLogger} from '../logging/getLogger'; |
| 24 | +import {config} from '../settings/config'; |
| 25 | + |
| 26 | +const logger = getLogger('MacAutoUpdater'); |
| 27 | +const isInternalBuild = (): boolean => config.environment === 'internal'; |
| 28 | + |
| 29 | +export function initMacAutoUpdater(mainWindow: BrowserWindow): void { |
| 30 | + // Skip in dev |
| 31 | + if (process.env.NODE_ENV === 'development') { |
| 32 | + logger.log('Skipping auto-update in development'); |
| 33 | + return; |
| 34 | + } |
| 35 | + |
| 36 | + // Only run for internal builds (production = App Store -> handled by Apple) |
| 37 | + if (!isInternalBuild()) { |
| 38 | + logger.log('Skipping auto-update: not an internal build'); |
| 39 | + return; |
| 40 | + } |
| 41 | + |
| 42 | + logger.log('Initializing macOS auto-updater for internal build'); |
| 43 | + |
| 44 | + // INTERNAL FEED URL (served from S3) |
| 45 | + // We upload latest-mac.yml + WireInternal-<version>.zip here. |
| 46 | + const feedUrl = |
| 47 | + process.env.WIRE_INTERNAL_MAC_UPDATE_URL || 'https://wire-taco.s3.eu-west-1.amazonaws.com/mac/internal/updates/'; |
| 48 | + |
| 49 | + // TODO (infra): once internal mac auto-update is validated using the raw S3 URL, |
| 50 | + // expose it via https://wire-app.wire.com/mac/internal/updates/ (similar to WIN_URL_UPDATE). |
| 51 | + // const feedUrl = |
| 52 | + // process.env.WIRE_INTERNAL_MAC_UPDATE_URL || |
| 53 | + // 'https://wire-app.wire.com/mac/internal/updates/'; |
| 54 | + |
| 55 | + logger.log(`Using update feed: ${feedUrl}`); |
| 56 | + |
| 57 | + autoUpdater.setFeedURL({ |
| 58 | + provider: 'generic', |
| 59 | + url: feedUrl, |
| 60 | + }); |
| 61 | + |
| 62 | + autoUpdater.on('checking-for-update', () => { |
| 63 | + logger.log('Checking for update…'); |
| 64 | + }); |
| 65 | + |
| 66 | + autoUpdater.on('update-available', info => { |
| 67 | + logger.log(`Update available: ${info.version}`); |
| 68 | + }); |
| 69 | + |
| 70 | + autoUpdater.on('update-not-available', info => { |
| 71 | + logger.log(`No update available (current: ${info.version})`); |
| 72 | + }); |
| 73 | + |
| 74 | + autoUpdater.on('error', err => { |
| 75 | + logger.error('Auto-updater error', err); |
| 76 | + }); |
| 77 | + |
| 78 | + autoUpdater.on('download-progress', progress => { |
| 79 | + // For now we only log; no progress UI. |
| 80 | + logger.log( |
| 81 | + `Update download progress: ${progress.percent?.toFixed?.(1) ?? 'n/a'}% at ${progress.bytesPerSecond} B/s`, |
| 82 | + ); |
| 83 | + }); |
| 84 | + |
| 85 | + autoUpdater.on('update-downloaded', async info => { |
| 86 | + logger.log(`Update downloaded: ${info.version}`); |
| 87 | + |
| 88 | + // Show a simple native dialog when the update is ready. |
| 89 | + const result = await dialog.showMessageBox(mainWindow, { |
| 90 | + type: 'info', |
| 91 | + buttons: ['Install & Restart', 'Later'], |
| 92 | + defaultId: 0, |
| 93 | + cancelId: 1, |
| 94 | + title: 'Wire Update Ready', |
| 95 | + message: 'A new version of Wire is ready to install.', |
| 96 | + detail: `Version ${info.version} has been downloaded. Wire will restart to complete the update.`, |
| 97 | + }); |
| 98 | + |
| 99 | + if (result.response === 0) { |
| 100 | + logger.log('User chose to install update now'); |
| 101 | + autoUpdater.quitAndInstall(); |
| 102 | + } else { |
| 103 | + logger.log('User chose to install later'); |
| 104 | + } |
| 105 | + }); |
| 106 | + |
| 107 | + // Kick off background check + download. |
| 108 | + autoUpdater.checkForUpdates(); |
| 109 | +} |
0 commit comments