Skip to content

Commit b3bab47

Browse files
committed
feat: improve self-extraction logic for macOS updater by checking pending cache directory for ZIP files
1 parent cb66ffa commit b3bab47

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

electron/updater.cjs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,29 @@ function initUpdater({ app, getMainWindow, isDev, stopAgentServer, sessionName }
480480
if (!stagedBundlePath) {
481481
// ShipIt didn't stage the bundle (unreliable on macOS 26+). Fall back to
482482
// extracting the downloaded ZIP ourselves, mirroring the debug-downgrade path.
483-
const zipPath = pendingUpdateInfo?.downloadedFile;
483+
// Try info.downloadedFile first, then scan the pending cache dir — electron-updater
484+
// on macOS Squirrel doesn't always populate downloadedFile.
485+
let zipPath = pendingUpdateInfo?.downloadedFile || null;
486+
log('info', 'ShipIt has no staged bundle — attempting self-extraction. downloadedFile:', zipPath);
487+
if (!zipPath || !fs.existsSync(zipPath)) {
488+
const pendingDir = path.join(macPaths.updaterCacheDir, 'pending');
489+
try {
490+
if (fs.existsSync(pendingDir)) {
491+
const zips = fs.readdirSync(pendingDir).filter((f) => f.endsWith('.zip'));
492+
if (zips.length > 0) {
493+
zipPath = path.join(pendingDir, zips[zips.length - 1]);
494+
log('info', 'Found ZIP in pending dir:', zipPath);
495+
} else {
496+
log('warn', 'No ZIP files found in pending dir:', pendingDir);
497+
}
498+
} else {
499+
log('warn', 'Pending dir does not exist:', pendingDir);
500+
}
501+
} catch (scanErr) {
502+
log('warn', 'Could not scan pending dir:', scanErr.message);
503+
}
504+
}
484505
if (zipPath && fs.existsSync(zipPath)) {
485-
log('info', 'ShipIt has no staged bundle — self-extracting downloaded ZIP:', zipPath);
486506
const extractDir = path.join(macPaths.updaterCacheDir, 'manual-extract');
487507
try {
488508
fs.rmSync(extractDir, { recursive: true, force: true });
@@ -494,13 +514,13 @@ function initUpdater({ app, getMainWindow, isDev, stopAgentServer, sessionName }
494514
stagedBundlePath = path.join(extractDir, appDirName);
495515
log('info', 'Self-extracted bundle at:', stagedBundlePath);
496516
} else {
497-
log('error', 'No .app found inside extracted ZIP');
517+
log('error', 'No .app found inside extracted ZIP. Contents:', entries.join(', '));
498518
}
499519
} catch (extractErr) {
500520
log('error', 'Failed to self-extract downloaded ZIP:', extractErr.message);
501521
}
502522
} else {
503-
log('warn', 'No downloadedFile path available for self-extraction');
523+
log('error', 'No usable ZIP found for self-extraction. zipPath:', zipPath);
504524
}
505525
}
506526
if (!stagedBundlePath) {

0 commit comments

Comments
 (0)