properly relaunch app in the portable build (fixes #478)

This commit is contained in:
Eugene Pankov 2019-05-19 22:41:41 +02:00
parent 206cf974c0
commit 1a0acad3c2
5 changed files with 22 additions and 12 deletions

View File

@ -83,7 +83,7 @@
"token": "d993c4faa708a4cba84fa3a8e822457e7298d75c" "token": "d993c4faa708a4cba84fa3a8e822457e7298d75c"
}, },
{ {
"provider": "github", "provider": "github"
} }
], ],
"portable": { "portable": {

View File

@ -28,6 +28,7 @@ export class HostAppService {
*/ */
shown = new EventEmitter<any>() shown = new EventEmitter<any>()
isFullScreen = false isFullScreen = false
isPortable = !!process.env.PORTABLE_EXECUTABLE_FILE
private preferencesMenu = new Subject<void>() private preferencesMenu = new Subject<void>()
private secondInstance = new Subject<void>() private secondInstance = new Subject<void>()
@ -251,6 +252,15 @@ export class HostAppService {
this.electron.ipcRenderer.send('window-close') this.electron.ipcRenderer.send('window-close')
} }
relaunch () {
if (this.isPortable) {
this.electron.app.relaunch({ execPath: process.env.PORTABLE_EXECUTABLE_FILE })
} else {
this.electron.app.relaunch()
}
this.electron.app.exit()
}
quit () { quit () {
this.logger.info('Quitting') this.logger.info('Quitting')
this.electron.app.quit() this.electron.app.quit()

View File

@ -59,6 +59,7 @@ export class ShellIntegrationService {
} }
async install () { async install () {
const exe = process.env.PORTABLE_EXECUTABLE_FILE || this.electron.app.getPath('exe')
if (this.hostApp.platform === Platform.macOS) { if (this.hostApp.platform === Platform.macOS) {
for (let wf of this.automatorWorkflows) { for (let wf of this.automatorWorkflows) {
await exec(`cp -r "${this.automatorWorkflowsLocation}/${wf}" "${this.automatorWorkflowsDestination}"`) await exec(`cp -r "${this.automatorWorkflowsLocation}/${wf}" "${this.automatorWorkflowsDestination}"`)
@ -67,8 +68,8 @@ export class ShellIntegrationService {
for (let registryKey of this.registryKeys) { for (let registryKey of this.registryKeys) {
wnr.createRegistryKey(wnr.HK.CU, registryKey.path) wnr.createRegistryKey(wnr.HK.CU, registryKey.path)
wnr.createRegistryKey(wnr.HK.CU, registryKey.path + '\\command') wnr.createRegistryKey(wnr.HK.CU, registryKey.path + '\\command')
wnr.setRegistryValue(wnr.HK.CU, registryKey.path, 'Icon', wnr.REG.SZ, this.electron.app.getPath('exe')) wnr.setRegistryValue(wnr.HK.CU, registryKey.path, 'Icon', wnr.REG.SZ, exe)
wnr.setRegistryValue(wnr.HK.CU, registryKey.path + '\\command', '', wnr.REG.SZ, this.electron.app.getPath('exe') + ' ' + registryKey.command) wnr.setRegistryValue(wnr.HK.CU, registryKey.path + '\\command', '', wnr.REG.SZ, exe + ' ' + registryKey.command)
} }
} }
} }

View File

@ -1,5 +1,4 @@
import axios from 'axios' import axios from 'axios'
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'
@ -14,6 +13,7 @@ export class UpdaterService {
private downloaded: Promise<boolean> private downloaded: Promise<boolean>
private electronUpdaterAvailable = true private electronUpdaterAvailable = true
private updateURL: string private updateURL: string
private autoUpdater
constructor ( constructor (
log: LogService, log: LogService,
@ -21,24 +21,24 @@ export class UpdaterService {
) { ) {
this.logger = log.create('updater') this.logger = log.create('updater')
const autoUpdater = electron.remote.require('electron-updater').autoUpdater this.autoUpdater = electron.remote.require('electron-updater').autoUpdater
autoUpdater.on('update-available', () => { this.autoUpdater.on('update-available', () => {
this.logger.info('Update available') this.logger.info('Update available')
}) })
autoUpdater.once('update-not-available', () => { this.autoUpdater.once('update-not-available', () => {
this.logger.info('No updates') this.logger.info('No updates')
}) })
this.downloaded = new Promise<boolean>(resolve => { this.downloaded = new Promise<boolean>(resolve => {
autoUpdater.once('update-downloaded', () => resolve(true)) this.autoUpdater.once('update-downloaded', () => resolve(true))
}) })
this.logger.debug('Checking for updates') this.logger.debug('Checking for updates')
if (this.electronUpdaterAvailable) { if (this.electronUpdaterAvailable) {
try { try {
autoUpdater.checkForUpdates() this.autoUpdater.checkForUpdates()
} catch (e) { } catch (e) {
this.electronUpdaterAvailable = false this.electronUpdaterAvailable = false
this.logger.info('Electron updater unavailable, falling back', e) this.logger.info('Electron updater unavailable, falling back', e)
@ -68,7 +68,7 @@ export class UpdaterService {
this.electron.shell.openExternal(this.updateURL) this.electron.shell.openExternal(this.updateURL)
} else { } else {
await this.downloaded await this.downloaded
autoUpdater.quitAndInstall() this.autoUpdater.quitAndInstall()
} }
} }
} }

View File

@ -100,8 +100,7 @@ export class SettingsTabComponent extends BaseTabComponent {
} }
restartApp () { restartApp () {
this.electron.app.relaunch() this.hostApp.relaunch()
this.electron.app.exit()
} }
saveConfigFile () { saveConfigFile () {