mirror of
https://github.com/Eugeny/tabby.git
synced 2024-12-27 20:43:01 +03:00
Added check to see if auto-update is enabled and fix issues with installation on windows platform
This commit is contained in:
parent
2953ea60e8
commit
7645a1d2c7
@ -1,8 +1,12 @@
|
||||
import axios from 'axios'
|
||||
import * as fs from 'fs'
|
||||
import os from 'os'
|
||||
|
||||
import { Injectable } from '@angular/core'
|
||||
import { Logger, LogService } from './log.service'
|
||||
import { ElectronService } from './electron.service'
|
||||
import { ConfigService } from './config.service'
|
||||
import { child_process } from 'mz';
|
||||
|
||||
const UPDATES_URL = 'https://api.github.com/repos/eugeny/terminus/releases/latest'
|
||||
|
||||
@ -18,11 +22,15 @@ 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.autoDownload = !!config.store.enableAutomaticUpdates;
|
||||
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) {
|
||||
child_process.spawn(os.tmpdir() + 'terminus-installer-temp.exe', ['--force-run'], {detached: true, stdio: 'ignore'});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
})
|
||||
} else {
|
||||
await this.downloaded;
|
||||
this.autoUpdater.quitAndInstall(false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user