Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (MuzikaUpdater._updatable) {
this.emit('error', new Error('already downloaded'));
return;
}
// if in development mode, don't check update and just emit not update available event.
if (isDev) {
this.emit('available', false);
Actions.app.setUpdatable('not-available');
return;
}
MuzikaUpdater._isChecking = true;
autoUpdater.removeAllListeners('update-available');
autoUpdater.removeAllListeners('update-not-available');
autoUpdater.once('update-available', () => {
this.emit('available', true);
Actions.app.setUpdatable('downloading');
});
autoUpdater.once('update-not-available', () => {
MuzikaUpdater._isChecking = false;
this.emit('available', false);
Actions.app.setUpdatable('not-available');
});
autoUpdater.once('update-downloaded', () => {
MuzikaUpdater._isChecking = false;
MuzikaUpdater._updatable = true;
this.emit('downloaded');
Actions.app.setUpdatable('updatable');
if (MuzikaUpdater._updatable) {
this.emit('error', new Error('already downloaded'));
return;
}
// if in development mode, don't check update and just emit not update available event.
if (isDev) {
this.emit('available', false);
Actions.app.setUpdatable('not-available');
return;
}
MuzikaUpdater._isChecking = true;
autoUpdater.removeAllListeners('update-available');
autoUpdater.removeAllListeners('update-not-available');
autoUpdater.once('update-available', () => {
this.emit('available', true);
Actions.app.setUpdatable('downloading');
});
autoUpdater.once('update-not-available', () => {
MuzikaUpdater._isChecking = false;
this.emit('available', false);
Actions.app.setUpdatable('not-available');
});
autoUpdater.once('update-downloaded', () => {
MuzikaUpdater._isChecking = false;
MuzikaUpdater._updatable = true;
this.emit('downloaded');
export function stopUpdater(): void {
autoUpdater.removeAllListeners();
}
}).on('error', e => {
const ee: any = e
this._stopPolling()
this._errorCount += 1
if (this._errorCount >= 5) {
this._logger.error(`Auto Update Error ${this._errorCount}, shutting down updater:\n${ee.message}`)
autoUpdater.removeAllListeners('update-available')
autoUpdater.removeAllListeners('update-downloaded')
autoUpdater.removeAllListeners('checking-for-update')
autoUpdater.removeAllListeners('error')
throw new UpdateError(`Update failed multiple times. Last error:\n${ee.message}`)
} else {
this._logger.error(`Auto Update Error ${this._errorCount}, continuing polling:\n${ee.message}`)
this._notifyUpdateError()
setTimeout(() => this._startPolling(), this._fallbackPollInterval)
}
})
}
__updaterCheck = async ( notifications: Event | boolean = false ) => {
updater.removeAllListeners ();
if ( notifications === true ) {
updater.on ( 'update-available', () => Notification.show ( 'A new update is available', 'Downloading it right now...' ) );
updater.on ( 'update-not-available', () => Notification.show ( 'No update is available', 'You\'re already using the latest version' ) );
updater.on ( 'error', err => {
Notification.show ( 'An error occurred', err.message );
Notification.show ( 'Update manually', 'Download the new version manually to update the app' );
shell.openExternal ( pkg['download'].url );
});
}
updater.checkForUpdatesAndNotify ();
}
eventsListenerRemove.forEach(event => {
autoUpdater.removeAllListeners(event);
});
}
}).on('error', e => {
const ee: any = e
this._stopPolling()
this._errorCount += 1
if (this._errorCount >= 5) {
this._logger.error(`Auto Update Error ${this._errorCount}, shutting down updater:\n${ee.message}`)
autoUpdater.removeAllListeners('update-available')
autoUpdater.removeAllListeners('update-downloaded')
autoUpdater.removeAllListeners('checking-for-update')
autoUpdater.removeAllListeners('error')
throw new UpdateError(`Update failed multiple times. Last error:\n${ee.message}`)
} else {
this._logger.error(`Auto Update Error ${this._errorCount}, continuing polling:\n${ee.message}`)
this._notifyUpdateError()
setTimeout(() => this._startPolling(), this._fallbackPollInterval)
}
})
}
autoUpdater.addListener('update-available', (info: UpdateInfo) => {
mainWindow!.webContents.send('update-available', info);
autoUpdater.removeAllListeners('update-not-available');
});
_.forEach(listeners, (listenerFunction, listenerName) => {
autoUpdater.removeAllListeners(listenerName);
autoUpdater.on(listenerName, listenerFunction);
});
event.sender.send('autoUpdate-initialized');
}).on('error', e => {
const ee: any = e
this._stopPolling()
this._errorCount += 1
if (this._errorCount >= 5) {
this._logger.error(`Auto Update Error ${this._errorCount}, shutting down updater:\n${ee.message}`)
autoUpdater.removeAllListeners('update-available')
autoUpdater.removeAllListeners('update-downloaded')
autoUpdater.removeAllListeners('checking-for-update')
autoUpdater.removeAllListeners('error')
throw new UpdateError(`Update failed multiple times. Last error:\n${ee.message}`)
} else {
this._logger.error(`Auto Update Error ${this._errorCount}, continuing polling:\n${ee.message}`)
this._notifyUpdateError()
setTimeout(() => this._startPolling(), this._fallbackPollInterval)
}
})
}