diff --git a/packages/electron-builder/templates/linux/AppRun.sh b/packages/electron-builder/templates/linux/AppRun.sh index d67825e38ba..9ca84c3457d 100755 --- a/packages/electron-builder/templates/linux/AppRun.sh +++ b/packages/electron-builder/templates/linux/AppRun.sh @@ -50,6 +50,12 @@ trap atexit EXIT # http://stackoverflow.com/questions/3190818 atexit() { + +if [ ! -z "$APPIMAGE_DELETE_OLD_FILE" ] ; then + echo "Delete old file $APPIMAGE_DELETE_OLD_FILE" + rm -f "$APPIMAGE_DELETE_OLD_FILE" +fi + if [ -z "$APPIMAGE_EXIT_AFTER_INSTALL" ] ; then if [ $NUMBER_OF_ARGS -eq 0 ] ; then exec "${BIN}" diff --git a/packages/electron-updater/src/AppImageUpdater.ts b/packages/electron-updater/src/AppImageUpdater.ts index 5127d518700..3c02108523f 100644 --- a/packages/electron-updater/src/AppImageUpdater.ts +++ b/packages/electron-updater/src/AppImageUpdater.ts @@ -2,18 +2,33 @@ import { CancellationToken, DownloadOptions, AllPublishOptions, VersionInfo, App import { spawn, SpawnOptions } from "child_process" import "source-map-support/register" import { DifferentialDownloader } from "./differentialPackage" -import { FileInfo, UPDATE_DOWNLOADED } from "./main" +import { FileInfo, UPDATE_DOWNLOADED, UpdateCheckResult } from "./main" import { BaseUpdater } from "./BaseUpdater" import { readBlockMapDataFromAppImage } from "builder-util-runtime/out/blockMapApi" import { safeLoad } from "js-yaml" -import { chmod, move, unlink } from "fs-extra-p" +import { chmod, move } from "fs-extra-p" import * as path from "path" +import isDev from "electron-is-dev" +import BluebirdPromise from "bluebird-lst" export class AppImageUpdater extends BaseUpdater { constructor(options?: AllPublishOptions | null, app?: any) { super(options, app) } + checkForUpdatesAndNotify(): Promise { + if (isDev) { + return BluebirdPromise.resolve(null) + } + + if (process.env.APPIMAGE == null) { + this._logger.warn("APPIMAGE env is not defined, current application is not an AppImage") + return BluebirdPromise.resolve(null) + } + + return super.checkForUpdatesAndNotify() + } + /*** @private */ protected async doDownloadUpdate(versionInfo: VersionInfo, fileInfo: FileInfo, cancellationToken: CancellationToken): Promise> { const downloadOptions: DownloadOptions = { @@ -74,6 +89,18 @@ export class AppImageUpdater extends BaseUpdater { throw new Error("APPIMAGE env is not defined") } + const spawnOptions: SpawnOptions = { + detached: true, + stdio: "ignore", + env: { + APPIMAGE_SILENT_INSTALL: "true", + }, + } + + if (!isForceRunAfter) { + spawnOptions.env.APPIMAGE_EXIT_AFTER_INSTALL = "true" + } + let destination: string if (path.basename(installerPath) === path.basename(appImageFile)) { // no version in the file name, overwrite existing @@ -81,30 +108,11 @@ export class AppImageUpdater extends BaseUpdater { } else { destination = path.join(path.dirname(appImageFile), path.basename(installerPath)) + spawnOptions.env.APPIMAGE_DELETE_OLD_FILE = appImageFile } move(installerPath, destination, {overwrite: true}) .then(() => chmod(destination, "0755")) - .then((): any => { - if (destination === appImageFile) { - return null - } - else { - return unlink(appImageFile) - } - }) .then(() => { - const spawnOptions: SpawnOptions = { - detached: true, - stdio: "ignore", - env: { - APPIMAGE_SILENT_INSTALL: "true", - }, - } - - if (!isForceRunAfter) { - spawnOptions.env.APPIMAGE_EXIT_AFTER_INSTALL = "true" - } - try { spawn(installerPath, args, spawnOptions) .unref() diff --git a/packages/electron-updater/src/AppUpdater.ts b/packages/electron-updater/src/AppUpdater.ts index 85a919f1168..81ba44efaf8 100644 --- a/packages/electron-updater/src/AppUpdater.ts +++ b/packages/electron-updater/src/AppUpdater.ts @@ -171,9 +171,9 @@ export abstract class AppUpdater extends EventEmitter { return checkForUpdatesPromise } - checkForUpdatesAndNotify() { + checkForUpdatesAndNotify(): Promise { if (isDev) { - return + return BluebirdPromise.resolve(null) } this.signals.updateDownloaded(it => {