electron/spec-main/fixtures/auto-update/update/index.js

43 lines
941 B
JavaScript
Raw Normal View History

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