Skip to content

Instantly share code, notes, and snippets.

@weedgrease
Last active February 22, 2017 22:40
Show Gist options
  • Save weedgrease/f250bc557e21a750d753291a1f6ce710 to your computer and use it in GitHub Desktop.
Save weedgrease/f250bc557e21a750d753291a1f6ce710 to your computer and use it in GitHub Desktop.
const {app, autoUpdater, dialog} = require('electron');
const ms = require('ms');
const platform = process.platform === 'darwin' ? 'osx' : process.platform;
const version = app.getVersion();
const feedUrl = `https://my-updates-here.herokuapp.com/update/${platform}`;
export default class AutoUpdater {
constructor(mainWindow) {
var self = this;
this.mainWindow = mainWindow;
this.nutsUrl = `${FEED_URL}/${version}`;
autoUpdater.on('update-available', () => {
console.log('[Updater] Update available');
});
autoUpdater.on('update-downloaded', (e, releaseNotes, releaseName) => {
console.log('[Updater] Update downloaded');
console.log(releaseNotes);
// create dialog here
});
setTimeout(() => {
autoUpdater.setFeedURL(self.nutsUrls)
self.checkForUpdates();
}, ms('10s'));
};
startCheckTimer() {
var self = this;
setInterval(() => {
self.checkForUpdates();
}, ms('30m'));
};
checkForUpdates() {
try {
autoUpdater.checkForUpdates()
} catch (ex) {
console.warn(`[Updater] Failure checking for updates: ${ex.message}`)
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment