mirror of
https://github.com/Eugeny/tabby.git
synced 2024-09-20 09:27:16 +03:00
fall back to github updates if squirrel is unavailable
This commit is contained in:
parent
dff55558dd
commit
5cf31d3351
@ -21,6 +21,7 @@
|
||||
"@types/node": "^7.0.37",
|
||||
"@types/webpack-env": "^1.13.0",
|
||||
"@types/winston": "^2.3.6",
|
||||
"axios": "^0.18.0",
|
||||
"bootstrap": "^4.1.3",
|
||||
"core-js": "^2.4.1",
|
||||
"electron-updater": "^2.8.9",
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -73,6 +73,14 @@ aws4@^1.6.0:
|
||||
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
|
||||
integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==
|
||||
|
||||
axios@^0.18.0:
|
||||
version "0.18.0"
|
||||
resolved "https://registry.yarnpkg.com/axios/-/axios-0.18.0.tgz#32d53e4851efdc0a11993b6cd000789d70c05102"
|
||||
integrity sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=
|
||||
dependencies:
|
||||
follow-redirects "^1.3.0"
|
||||
is-buffer "^1.1.5"
|
||||
|
||||
bcrypt-pbkdf@^1.0.0:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e"
|
||||
@ -162,7 +170,7 @@ dashdash@^1.12.0:
|
||||
dependencies:
|
||||
assert-plus "^1.0.0"
|
||||
|
||||
debug@^3.0.0:
|
||||
debug@=3.1.0, debug@^3.0.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
|
||||
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
|
||||
@ -261,6 +269,13 @@ fast-json-stable-stringify@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
|
||||
integrity sha1-1RQsDK7msRifh9OnYREGT4bIu/I=
|
||||
|
||||
follow-redirects@^1.3.0:
|
||||
version "1.5.10"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
|
||||
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
|
||||
dependencies:
|
||||
debug "=3.1.0"
|
||||
|
||||
forever-agent@~0.6.1:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
|
||||
@ -341,6 +356,11 @@ http-signature@~1.2.0:
|
||||
jsprim "^1.2.2"
|
||||
sshpk "^1.7.0"
|
||||
|
||||
is-buffer@^1.1.5:
|
||||
version "1.1.6"
|
||||
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
|
||||
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
|
||||
|
||||
is-typedarray@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
|
||||
|
Loading…
Reference in New Issue
Block a user