diff --git a/terminus-core/src/services/updater.service.ts b/terminus-core/src/services/updater.service.ts index 1266ebfa..8b511c38 100644 --- a/terminus-core/src/services/updater.service.ts +++ b/terminus-core/src/services/updater.service.ts @@ -1,8 +1,12 @@ import axios from 'axios' +import * as fs from 'fs' +import os from 'os' import { Injectable } from '@angular/core' import { Logger, LogService } from './log.service' import { ElectronService } from './electron.service' +import { ConfigService } from './config.service' +import { child_process } from 'mz'; const UPDATES_URL = 'https://api.github.com/repos/eugeny/terminus/releases/latest' @@ -18,11 +22,15 @@ export class UpdaterService { constructor ( log: LogService, private electron: ElectronService, + config: ConfigService, ) { this.logger = log.create('updater') this.autoUpdater = electron.remote.require('electron-updater').autoUpdater + this.autoUpdater.autoDownload = !!config.store.enableAutomaticUpdates; + this.autoUpdater.autoInstallOnAppQuit = !!config.store.enableAutomaticUpdates; + this.autoUpdater.on('update-available', () => { this.logger.info('Update available') }) @@ -48,7 +56,7 @@ export class UpdaterService { async check (): Promise { if (!this.electronUpdaterAvailable) { - this.logger.debug('Checking for updates') + this.logger.debug('Checking for updates through fallback method.') const response = await axios.get(UPDATES_URL) const data = response.data const version = data.tag_name.substring(1) @@ -67,8 +75,22 @@ export class UpdaterService { if (!this.electronUpdaterAvailable) { this.electron.shell.openExternal(this.updateURL) } else { - await this.downloaded - this.autoUpdater.quitAndInstall() + if (process.platform === 'win32') { + let downloadpath = await this.autoUpdater.downloadUpdate(); + fs.exists(downloadpath[0], (exists) => { + if (exists) { + fs.copyFile(downloadpath[0], os.tmpdir() + 'terminus-installer-temp.exe', (err) => { + if (!err) { + child_process.spawn(os.tmpdir() + 'terminus-installer-temp.exe', ['--force-run'], {detached: true, stdio: 'ignore'}); + } + }); + + } + }) + } else { + await this.downloaded; + this.autoUpdater.quitAndInstall(false, true); + } } } }