Merge pull request #1292 from ehwarren/auto-updater-fixes

Auto updater fixes
This commit is contained in:
Eugene 2019-07-23 22:43:07 +02:00 committed by GitHub
commit 092e5fb8aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 4 deletions

View File

@ -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)'
)

View File

@ -14,3 +14,4 @@ enableAnalytics: true
enableWelcomeTab: true
electronFlags:
- ['force_discrete_gpu', '0']
enableAutomaticUpdates: true

View File

@ -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<boolean> {
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);
}
}
}
}

View File

@ -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