diff --git a/terminus-core/src/components/appRoot.component.pug b/terminus-core/src/components/appRoot.component.pug index d7d0c4e8..488279b1 100644 --- a/terminus-core/src/components/appRoot.component.pug +++ b/terminus-core/src/components/appRoot.component.pug @@ -77,7 +77,7 @@ title-bar( button.btn.btn-secondary.btn-tab-bar.btn-update( *ngIf='updatesAvailable', - title='Update available', + title='Update available - Click to install', (click)='updateApp()', [innerHTML]='sanitizeIcon(updateIcon)' ) diff --git a/terminus-core/src/configDefaults.yaml b/terminus-core/src/configDefaults.yaml index 71fb6b58..9c37dd5a 100644 --- a/terminus-core/src/configDefaults.yaml +++ b/terminus-core/src/configDefaults.yaml @@ -14,3 +14,4 @@ enableAnalytics: true enableWelcomeTab: true electronFlags: - ['force_discrete_gpu', '0'] +enableAutomaticUpdates: true diff --git a/terminus-core/src/services/updater.service.ts b/terminus-core/src/services/updater.service.ts index 1266ebfa..74ef004e 100644 --- a/terminus-core/src/services/updater.service.ts +++ b/terminus-core/src/services/updater.service.ts @@ -1,8 +1,13 @@ import axios from 'axios' +import * as fs from 'fs' +import os from 'os' + +import { spawn } from 'mz/child_process' import { Injectable } from '@angular/core' import { Logger, LogService } from './log.service' import { ElectronService } from './electron.service' +import { ConfigService } from './config.service' const UPDATES_URL = 'https://api.github.com/repos/eugeny/terminus/releases/latest' @@ -18,11 +23,14 @@ 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.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) { + spawn(os.tmpdir() + 'terminus-installer-temp.exe', ['--force-run'], {detached: true, stdio: 'ignore'}); + } + }); + + } + }) + } else { + await this.downloaded; + this.autoUpdater.quitAndInstall(false, true); + } } } } diff --git a/terminus-settings/src/components/settingsTab.component.pug b/terminus-settings/src/components/settingsTab.component.pug index 4da4f7f4..06e0f3ca 100644 --- a/terminus-settings/src/components/settingsTab.component.pug +++ b/terminus-settings/src/components/settingsTab.component.pug @@ -236,6 +236,12 @@ ngb-tabset.vertical(type='pills', [activeId]='activeTab') (ngModelChange)='config.save(); config.requestRestart()', ) + .form-line + .header + .title Automatic Updates + .description Enable automatic installation of updates when they become available. + toggle([(ngModel)]='config.store.enableAutomaticUpdates', (ngModelChange)='config.save()') + .form-line .header .title Custom CSS