From 8d5b2bc4c5d367dcca26f2d025b258611160c86b Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Tue, 23 Jul 2019 12:24:17 -0700 Subject: [PATCH 1/5] Added configuration option to enable/disable automatic updates --- terminus-core/src/configDefaults.yaml | 1 + terminus-settings/src/components/settingsTab.component.pug | 6 ++++++ 2 files changed, 7 insertions(+) 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-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 From 2953ea60e85dfa3ecc591cd22926d6ccefd1e2dd Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Tue, 23 Jul 2019 12:24:35 -0700 Subject: [PATCH 2/5] Clarify that this button is used to install the available update --- terminus-core/src/components/appRoot.component.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)' ) From 7645a1d2c7309919d536caca516808973fa546d3 Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Tue, 23 Jul 2019 12:29:14 -0700 Subject: [PATCH 3/5] Added check to see if auto-update is enabled and fix issues with installation on windows platform --- terminus-core/src/services/updater.service.ts | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) 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); + } } } } From 04f233b4a5b419e9d5aff3b5bd31d957b1ba633b Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Tue, 23 Jul 2019 12:39:41 -0700 Subject: [PATCH 4/5] Download the install executable regardless of if we're going to automatically install it --- terminus-core/src/services/updater.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/terminus-core/src/services/updater.service.ts b/terminus-core/src/services/updater.service.ts index 8b511c38..2aa2e139 100644 --- a/terminus-core/src/services/updater.service.ts +++ b/terminus-core/src/services/updater.service.ts @@ -28,7 +28,6 @@ export class UpdaterService { 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', () => { From b144724ed5e218ad69b866713f88477b25b5541e Mon Sep 17 00:00:00 2001 From: Austin Warren Date: Tue, 23 Jul 2019 12:47:44 -0700 Subject: [PATCH 5/5] Fix import for spawn --- terminus-core/src/services/updater.service.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/terminus-core/src/services/updater.service.ts b/terminus-core/src/services/updater.service.ts index 2aa2e139..74ef004e 100644 --- a/terminus-core/src/services/updater.service.ts +++ b/terminus-core/src/services/updater.service.ts @@ -2,11 +2,12 @@ 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' -import { child_process } from 'mz'; const UPDATES_URL = 'https://api.github.com/repos/eugeny/terminus/releases/latest' @@ -80,7 +81,7 @@ export class UpdaterService { 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'}); + spawn(os.tmpdir() + 'terminus-installer-temp.exe', ['--force-run'], {detached: true, stdio: 'ignore'}); } });