auto-updater (fixes #348)

This commit is contained in:
Eugene Pankov
2018-11-28 21:26:15 +01:00
parent 462232a2fb
commit 991294e61a
8 changed files with 34 additions and 54 deletions

View File

@@ -50,7 +50,7 @@ title-bar(
)
button.btn.btn-secondary.btn-tab-bar.btn-update(
*ngIf='appUpdate',
*ngIf='updatesAvailable',
title='Update available',
(click)='updateApp()',
[innerHTML]='updateIcon'

View File

@@ -11,7 +11,7 @@ import { ConfigService } from '../services/config.service'
import { DockingService } from '../services/docking.service'
import { TabRecoveryService } from '../services/tabRecovery.service'
import { ThemesService } from '../services/themes.service'
import { UpdaterService, Update } from '../services/updater.service'
import { UpdaterService } from '../services/updater.service'
import { TouchbarService } from '../services/touchbar.service'
import { BaseTabComponent } from './baseTab.component'
@@ -63,8 +63,8 @@ export class AppRootComponent {
tabsDragging = false
unsortedTabs: BaseTabComponent[] = []
updateIcon: SafeHtml
updatesAvailable = false
private logger: Logger
private appUpdate: Update
constructor (
private docking: DockingService,
@@ -132,8 +132,8 @@ export class AppRootComponent {
ngbModal.open(SafeModeModalComponent)
}
this.updater.check().then(update => {
this.appUpdate = update
this.updater.check().then(() => {
this.updatesAvailable = true
})
this.touchbar.update()
@@ -217,7 +217,7 @@ export class AppRootComponent {
}
updateApp () {
this.electron.shell.openExternal(this.appUpdate.url)
this.updater.update()
}
onTabDragStart () {

View File

@@ -12,6 +12,7 @@ export class ElectronService {
nativeImage: any
screen: any
remote: any
autoUpdater: any
TouchBar: typeof TouchBar
BrowserWindow: typeof BrowserWindow
Menu: typeof Menu
@@ -29,6 +30,7 @@ export class ElectronService {
this.ipcRenderer = this.electron.ipcRenderer
this.globalShortcut = this.remote.globalShortcut
this.nativeImage = this.remote.nativeImage
this.autoUpdater = this.remote.autoUpdater
this.TouchBar = this.remote.TouchBar
this.BrowserWindow = this.remote.BrowserWindow
this.Menu = this.remote.Menu

View File

@@ -1,36 +1,41 @@
import axios from 'axios'
import * as os from 'os'
import { Injectable } from '@angular/core'
import { Logger, LogService } from './log.service'
import { ElectronService } from './electron.service'
const UPDATES_URL = 'https://api.github.com/repos/eugeny/terminus/releases/latest'
export interface Update {
version: string
url: string
}
@Injectable()
export class UpdaterService {
private logger: Logger
private downloaded: Promise<void>
constructor (
log: LogService,
private electron: ElectronService,
) {
this.logger = log.create('updater')
electron.autoUpdater.setFeedURL(`https://terminus-updates.herokuapp.com/update/${os.platform()}/${electron.app.getVersion()}`)
this.electron.autoUpdater.on('update-available', () => {
this.logger.info('Update available')
})
this.electron.autoUpdater.once('update-not-available', () => {
this.logger.info('No updates')
})
this.downloaded = new Promise<void>(resolve => {
this.electron.autoUpdater.once('update-downloaded', resolve)
})
this.logger.debug('Checking for updates')
this.electron.autoUpdater.checkForUpdates()
}
async check (): Promise<Update> {
this.logger.debug('Checking for updates')
let response = await axios.get(UPDATES_URL)
let data = response.data
let version = data.tag_name.substring(1)
if (this.electron.app.getVersion() !== version) {
this.logger.info('Update available:', version)
return { version, url: data.html_url }
}
this.logger.info('No updates')
return null
check (): Promise<void> {
return this.downloaded
}
async update () {
await this.downloaded
this.electron.autoUpdater.quitAndInstall()
}
}