mirror of
https://github.com/Eugeny/tabby.git
synced 2025-07-04 18:39:54 +00: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/node": "^7.0.37",
|
||||||
"@types/webpack-env": "^1.13.0",
|
"@types/webpack-env": "^1.13.0",
|
||||||
"@types/winston": "^2.3.6",
|
"@types/winston": "^2.3.6",
|
||||||
|
"axios": "^0.18.0",
|
||||||
"bootstrap": "^4.1.3",
|
"bootstrap": "^4.1.3",
|
||||||
"core-js": "^2.4.1",
|
"core-js": "^2.4.1",
|
||||||
"electron-updater": "^2.8.9",
|
"electron-updater": "^2.8.9",
|
||||||
|
@ -132,8 +132,8 @@ export class AppRootComponent {
|
|||||||
ngbModal.open(SafeModeModalComponent)
|
ngbModal.open(SafeModeModalComponent)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updater.check().then(() => {
|
this.updater.check().then(available => {
|
||||||
this.updatesAvailable = true
|
this.updatesAvailable = available
|
||||||
})
|
})
|
||||||
|
|
||||||
this.touchbar.update()
|
this.touchbar.update()
|
||||||
|
@ -1,19 +1,30 @@
|
|||||||
|
import axios from 'axios'
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import { Logger, LogService } from './log.service'
|
import { Logger, LogService } from './log.service'
|
||||||
import { ElectronService } from './electron.service'
|
import { ElectronService } from './electron.service'
|
||||||
|
|
||||||
|
const UPDATES_URL = 'https://api.github.com/repos/eugeny/terminus/releases/latest'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UpdaterService {
|
export class UpdaterService {
|
||||||
private logger: Logger
|
private logger: Logger
|
||||||
private downloaded: Promise<void>
|
private downloaded: Promise<boolean>
|
||||||
|
private isSquirrel = false
|
||||||
|
private updateURL: string
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
log: LogService,
|
log: LogService,
|
||||||
private electron: ElectronService,
|
private electron: ElectronService,
|
||||||
) {
|
) {
|
||||||
this.logger = log.create('updater')
|
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.electron.autoUpdater.on('update-available', () => {
|
||||||
this.logger.info('Update available')
|
this.logger.info('Update available')
|
||||||
@ -22,20 +33,37 @@ export class UpdaterService {
|
|||||||
this.logger.info('No updates')
|
this.logger.info('No updates')
|
||||||
})
|
})
|
||||||
|
|
||||||
this.downloaded = new Promise<void>(resolve => {
|
this.downloaded = new Promise<boolean>(resolve => {
|
||||||
this.electron.autoUpdater.once('update-downloaded', resolve)
|
this.electron.autoUpdater.once('update-downloaded', () => resolve(true))
|
||||||
})
|
})
|
||||||
|
|
||||||
this.logger.debug('Checking for updates')
|
this.logger.debug('Checking for updates')
|
||||||
this.electron.autoUpdater.checkForUpdates()
|
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
|
return this.downloaded
|
||||||
}
|
}
|
||||||
|
|
||||||
async update () {
|
async update () {
|
||||||
await this.downloaded
|
if (!this.isSquirrel) {
|
||||||
this.electron.autoUpdater.quitAndInstall()
|
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"
|
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.8.0.tgz#f0e003d9ca9e7f59c7a508945d7b2ef9a04a542f"
|
||||||
integrity sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==
|
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:
|
bcrypt-pbkdf@^1.0.0:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e"
|
resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e"
|
||||||
@ -162,7 +170,7 @@ dashdash@^1.12.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
assert-plus "^1.0.0"
|
assert-plus "^1.0.0"
|
||||||
|
|
||||||
debug@^3.0.0:
|
debug@=3.1.0, debug@^3.0.0:
|
||||||
version "3.1.0"
|
version "3.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
|
resolved "https://registry.yarnpkg.com/debug/-/debug-3.1.0.tgz#5bb5a0672628b64149566ba16819e61518c67261"
|
||||||
integrity sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==
|
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"
|
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
|
||||||
integrity sha1-1RQsDK7msRifh9OnYREGT4bIu/I=
|
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:
|
forever-agent@~0.6.1:
|
||||||
version "0.6.1"
|
version "0.6.1"
|
||||||
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
|
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"
|
jsprim "^1.2.2"
|
||||||
sshpk "^1.7.0"
|
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:
|
is-typedarray@~1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
|
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user