Skip to content

Commit

Permalink
fix(electron-updater): AppImage quitAndInstall exception
Browse files Browse the repository at this point in the history
Close #2240
  • Loading branch information
develar committed Dec 8, 2017
1 parent fbc59e8 commit e409c0e
Show file tree
Hide file tree
Showing 22 changed files with 128 additions and 100 deletions.
2 changes: 2 additions & 0 deletions .idea/dictionaries/develar.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/auto-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ It should only be called after `update-downloaded` has been emitted.
This is different from the normal quit event sequence.


- isSilent <code>Boolean</code> - *windows-only* Runs the installer in silent mode.
- isForceRunAfter <code>Boolean</code> - *windows-only* Run the app after finish even on silent install.
- isSilent <code>Boolean</code> - *windows-only* Runs the installer in silent mode. Defaults to `false`.
- isForceRunAfter <code>Boolean</code> - Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`.

<a name="Logger"></a>
### `Logger`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"electron-download-tf": "4.3.4",
"electron-is-dev": "^0.3.0",
"electron-osx-sign": "0.4.7",
"fs-extra-p": "^4.4.4",
"fs-extra-p": "^4.4.5",
"gitbook-plugin-footer": "^0.0.6",
"hosted-git-info": "^2.5.0",
"iconv-lite": "^0.4.19",
Expand Down
2 changes: 1 addition & 1 deletion packages/app-package-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"dependencies": {
"bluebird-lst": "^1.0.5",
"fs-extra-p": "^4.4.4",
"fs-extra-p": "^4.4.5",
"int64-buffer": "^0.1.10",
"builder-util-runtime": "^0.0.0-semantic-release",
"builder-util": "^0.0.0-semantic-release",
Expand Down
2 changes: 1 addition & 1 deletion packages/asar-integrity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"dependencies": {
"bluebird-lst": "^1.0.5",
"fs-extra-p": "^4.4.4"
"fs-extra-p": "^4.4.5"
},
"typings": "./out/main.d.ts"
}
2 changes: 1 addition & 1 deletion packages/builder-util-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"debug": "^3.1.0",
"fs-extra-p": "^4.4.4",
"fs-extra-p": "^4.4.5",
"bluebird-lst": "^1.0.5",
"sax": "^1.2.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"dependencies": {
"temp-file": "^3.0.0",
"fs-extra-p": "^4.4.4",
"fs-extra-p": "^4.4.5",
"is-ci": "^1.0.10",
"stat-mode": "^0.2.2",
"bluebird-lst": "^1.0.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/dmg-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"vendor"
],
"dependencies": {
"fs-extra-p": "^4.4.4",
"fs-extra-p": "^4.4.5",
"bluebird-lst": "^1.0.5",
"parse-color": "^1.0.0",
"builder-util": "^0.0.0-semantic-release",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"builder-util": "0.0.0-semantic-release",
"electron-osx-sign": "0.4.7",
"electron-publish": "0.0.0-semantic-release",
"fs-extra-p": "^4.4.4",
"fs-extra-p": "^4.4.5",
"hosted-git-info": "^2.5.0",
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.2",
Expand Down
25 changes: 7 additions & 18 deletions packages/electron-builder-lib/templates/linux/AppRun.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/bin/bash

set -e

# Be verbose if $DEBUG=1 is set
# be verbose if $DEBUG=1 is set
if [ ! -z "$DEBUG" ] ; then
env
set -x
fi

THIS="$0"
args=("$@") # http://stackoverflow.com/questions/3190818/
# http://stackoverflow.com/questions/3190818/
args=("$@")
NUMBER_OF_ARGS="$#"

# Please do not change $VENDORPREFIX as it will allow for desktop files
# please do not change $VENDORPREFIX as it will allow for desktop files
# belonging to AppImages to be recognized by future AppImageKit components
# such as desktop integration daemons
VENDORPREFIX=appimagekit
Expand All @@ -28,8 +28,7 @@ find-up () {
if [ -z $APPDIR ] ; then
# Find the AppDir. It is the directory that contains AppRun.
# This assumes that this script resides inside the AppDir or a subdirectory.
# If this script is run inside an AppImage, then the AppImage runtime
# likely has already set $APPDIR
# If this script is run inside an AppImage, then the AppImage runtime likely has already set $APPDIR
APPDIR=$(find-up "AppRun")
fi

Expand All @@ -44,23 +43,13 @@ BIN="$APPDIR/app/<%= executableName %>"

trap atexit EXIT

# Note that the following handles 0, 1 or more arguments (file paths)
# which can include blanks but uses a bashism; can the same be achieved
# in POSIX-shell? (FIXME)
# 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}"
exec "$BIN"
else
exec "${BIN}" "${args[@]}"
exec "$BIN" "${args[@]}"
fi
fi
}
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder-squirrel-windows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"builder-util": "^0.0.0-semantic-release",
"bluebird-lst": "^1.0.5",
"fs-extra-p": "^4.4.4",
"fs-extra-p": "^4.4.5",
"archiver": "^2.1.0",
"sanitize-filename": "^1.6.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"chalk": "^2.3.0",
"builder-util-runtime": "0.0.0-semantic-release",
"builder-util": "0.0.0-semantic-release",
"fs-extra-p": "^4.4.4",
"fs-extra-p": "^4.4.5",
"is-ci": "^1.0.10",
"read-config-file": "1.2.1",
"sanitize-filename": "^1.6.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"out"
],
"dependencies": {
"fs-extra-p": "^4.4.4",
"fs-extra-p": "^4.4.5",
"mime": "^2.0.3",
"bluebird-lst": "^1.0.5",
"builder-util-runtime": "^0.0.0-semantic-release",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-publisher-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"out"
],
"dependencies": {
"fs-extra-p": "^4.4.4",
"fs-extra-p": "^4.4.5",
"aws-sdk": "^2.166.0",
"mime": "^2.0.3",
"electron-publish": "~0.0.0-semantic-release",
Expand Down
10 changes: 9 additions & 1 deletion packages/electron-updater/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
## 2.17.2

### Bug Fixes

* Fix AppImage auto-update [#2240](https://github.com/electron-userland/electron-builder/issues/2240).

## 2.17.0

PrivateGitHubProvider requires at least Electron 1.6.11. Better to use latest stable.
### Bug Fixes

* PrivateGitHubProvider requires at least Electron 1.6.11. Better to use latest stable.

### Features

Expand Down
2 changes: 1 addition & 1 deletion packages/electron-updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"lazy-val": "^1.0.3",
"bluebird-lst": "^1.0.5",
"fs-extra-p": "^4.4.4",
"fs-extra-p": "^4.4.5",
"js-yaml": "^3.10.0",
"semver": "^5.4.1",
"source-map-support": "^0.5.0",
Expand Down
72 changes: 33 additions & 39 deletions packages/electron-updater/src/AppImageUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { CancellationToken, DownloadOptions, AllPublishOptions, UpdateInfo } from "builder-util-runtime"
import { spawn, SpawnOptions } from "child_process"
import "source-map-support/register"
import { AppImageDifferentialDownloader } from "./differentialDownloader/AppImageDifferentialDownloader"
import { UPDATE_DOWNLOADED, UpdateCheckResult } from "./main"
import { BaseUpdater } from "./BaseUpdater"
import BluebirdPromise from "bluebird-lst"
import { AllPublishOptions, CancellationToken, DownloadOptions, UpdateInfo } from "builder-util-runtime"
import { readBlockMapDataFromAppImage } from "builder-util-runtime/out/blockMapApi"
import { execFileSync, spawn } from "child_process"
import isDev from "electron-is-dev"
import { chmod, unlinkSync } from "fs-extra-p"
import { safeLoad } from "js-yaml"
import { chmod, move } from "fs-extra-p"
import * as path from "path"
import isDev from "electron-is-dev"
import BluebirdPromise from "bluebird-lst"
import "source-map-support/register"
import { BaseUpdater } from "./BaseUpdater"
import { AppImageDifferentialDownloader } from "./differentialDownloader/AppImageDifferentialDownloader"
import { UPDATE_DOWNLOADED, UpdateCheckResult } from "./main"
import { findFile } from "./Provider"

export class AppImageUpdater extends BaseUpdater {
Expand Down Expand Up @@ -74,6 +74,8 @@ export class AppImageUpdater extends BaseUpdater {
if (isDownloadFull) {
await this.httpExecutor.download(fileInfo.url.href, installerPath, downloadOptions)
}

await chmod(installerPath, 0o755)
})

this.downloadedUpdateHelper.setDownloadedFile(installerPath!!, null, updateInfo, fileInfo)
Expand All @@ -82,28 +84,14 @@ export class AppImageUpdater extends BaseUpdater {
return [installerPath!!]
}

protected doInstall(installerPath: string, isSilent: boolean, isForceRunAfter: boolean): boolean {
const args = [""]
if (isForceRunAfter) {
args.push("--force-run")
}

protected doInstall(installerPath: string, isSilent: boolean, isRunAfter: boolean): boolean {
const appImageFile = process.env.APPIMAGE!!
if (appImageFile == null) {
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"
}
// https://stackoverflow.com/a/1712051/1910191
unlinkSync(appImageFile)

let destination: string
if (path.basename(installerPath) === path.basename(appImageFile)) {
Expand All @@ -112,21 +100,27 @@ 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(() => {
try {
spawn(installerPath, args, spawnOptions)
.unref()
}
catch (e) {
this.dispatchError(e)
}
})
.catch(e => this.dispatchError(e))

execFileSync("mv", ["-f", installerPath, destination])

const env: any = {
...process.env,
APPIMAGE_SILENT_INSTALL: "true",
}

if (isRunAfter) {
spawn(destination, [], {
detached: true,
stdio: "ignore",
env,
})
.unref()
}
else {
env.APPIMAGE_EXIT_AFTER_INSTALL = "true"
execFileSync(destination, [], {env})
}
return true
}
}
6 changes: 3 additions & 3 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import BluebirdPromise from "bluebird-lst"
import { AllPublishOptions, BaseS3Options, BintrayOptions, CancellationToken, GenericServerOptions, getS3LikeProviderBaseUrl, GithubOptions, PublishConfiguration, UpdateInfo, UUID, asArray } from "builder-util-runtime"
import { AllPublishOptions, asArray, BaseS3Options, BintrayOptions, CancellationToken, GenericServerOptions, getS3LikeProviderBaseUrl, GithubOptions, PublishConfiguration, UpdateInfo, UUID } from "builder-util-runtime"
import { randomBytes } from "crypto"
import { Notification } from "electron"
import isDev from "electron-is-dev"
Expand Down Expand Up @@ -322,8 +322,8 @@ export abstract class AppUpdater extends EventEmitter {
* **Note:** `autoUpdater.quitAndInstall()` will close all application windows first and only emit `before-quit` event on `app` after that.
* This is different from the normal quit event sequence.
*
* @param isSilent *windows-only* Runs the installer in silent mode.
* @param isForceRunAfter *windows-only* Run the app after finish even on silent install.
* @param isSilent *windows-only* Runs the installer in silent mode. Defaults to `false`.
* @param isForceRunAfter Run the app after finish even on silent install. Not applicable for macOS. Ignored if `isSilent` is set to `false`.
*/
abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void

Expand Down
Loading

0 comments on commit e409c0e

Please sign in to comment.