electron/spec/fixtures/auto-update/update/index.js
Samuel Attard d8bb172318
fix: abort ShipIt installation attempt at the final mile if the app is running (#36130)
* fix: abort ShipIt installation attempt at the final mile if the app is running

* chore: remove only

* Update patches/squirrel.mac/fix_abort_installation_attempt_at_the_final_mile_if_the_app_is.patch

Co-authored-by: Jeremy Rose <jeremya@chromium.org>

* chore: update patches

* spec: make the ShipIt process lister helper more resilient

Co-authored-by: Jeremy Rose <jeremya@chromium.org>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
2022-11-14 10:12:16 -08:00

48 lines
1.1 KiB
JavaScript

const fs = require('fs');
const path = require('path');
process.on('uncaughtException', (err) => {
console.error(err);
process.exit(1);
});
const { app, autoUpdater } = require('electron');
autoUpdater.on('error', (err) => {
console.error(err);
process.exit(1);
});
const urlPath = path.resolve(__dirname, '../../../../url.txt');
let feedUrl = process.argv[1];
if (feedUrl === 'remain-open') {
// Hold the event loop
setInterval(() => {});
} else {
if (!feedUrl || !feedUrl.startsWith('http')) {
feedUrl = `${fs.readFileSync(urlPath, 'utf8')}/${app.getVersion()}`;
} else {
fs.writeFileSync(urlPath, `${feedUrl}/updated`);
}
autoUpdater.setFeedURL({
url: feedUrl
});
autoUpdater.checkForUpdates();
autoUpdater.on('update-available', () => {
console.log('Update Available');
});
autoUpdater.on('update-downloaded', () => {
console.log('Update Downloaded');
autoUpdater.quitAndInstall();
});
autoUpdater.on('update-not-available', () => {
console.error('No update available');
process.exit(1);
});
}