mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-05 06:24:56 +00:00
fall back to github updates if squirrel is unavailable
This commit is contained in:
@@ -132,8 +132,8 @@ export class AppRootComponent {
|
||||
ngbModal.open(SafeModeModalComponent)
|
||||
}
|
||||
|
||||
this.updater.check().then(() => {
|
||||
this.updatesAvailable = true
|
||||
this.updater.check().then(available => {
|
||||
this.updatesAvailable = available
|
||||
})
|
||||
|
||||
this.touchbar.update()
|
||||
|
@@ -1,19 +1,30 @@
|
||||
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'
|
||||
|
||||
@Injectable()
|
||||
export class UpdaterService {
|
||||
private logger: Logger
|
||||
private downloaded: Promise<void>
|
||||
private downloaded: Promise<boolean>
|
||||
private isSquirrel = false
|
||||
private updateURL: string
|
||||
|
||||
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()}`)
|
||||
|
||||
try {
|
||||
electron.autoUpdater.setFeedURL(`https://terminus-updates.herokuapp.com/update/${os.platform()}/${electron.app.getVersion()}`)
|
||||
this.isSquirrel = true
|
||||
} catch (e) {
|
||||
this.logger.info('Squirrel updater unavailable, falling back')
|
||||
}
|
||||
|
||||
this.electron.autoUpdater.on('update-available', () => {
|
||||
this.logger.info('Update available')
|
||||
@@ -22,20 +33,37 @@ export class UpdaterService {
|
||||
this.logger.info('No updates')
|
||||
})
|
||||
|
||||
this.downloaded = new Promise<void>(resolve => {
|
||||
this.electron.autoUpdater.once('update-downloaded', resolve)
|
||||
this.downloaded = new Promise<boolean>(resolve => {
|
||||
this.electron.autoUpdater.once('update-downloaded', () => resolve(true))
|
||||
})
|
||||
|
||||
this.logger.debug('Checking for updates')
|
||||
this.electron.autoUpdater.checkForUpdates()
|
||||
}
|
||||
|
||||
check (): Promise<void> {
|
||||
async check (): Promise<boolean> {
|
||||
if (!this.isSquirrel) {
|
||||
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')
|
||||
this.updateURL = data.html_url
|
||||
return true
|
||||
}
|
||||
this.logger.info('No updates')
|
||||
return false
|
||||
}
|
||||
return this.downloaded
|
||||
}
|
||||
|
||||
async update () {
|
||||
await this.downloaded
|
||||
this.electron.autoUpdater.quitAndInstall()
|
||||
if (!this.isSquirrel) {
|
||||
this.electron.shell.openExternal(this.updateURL)
|
||||
} else {
|
||||
await this.downloaded
|
||||
this.electron.autoUpdater.quitAndInstall()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user