Skip to content

Commit

Permalink
feat(electron-updater): checkForUpdatesAndNotify — do nothing if no A…
Browse files Browse the repository at this point in the history
…PPIMAGE env
  • Loading branch information
develar committed Oct 12, 2017
1 parent 2a54c69 commit 247c18a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 24 deletions.
6 changes: 6 additions & 0 deletions packages/electron-builder/templates/linux/AppRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
52 changes: 30 additions & 22 deletions packages/electron-updater/src/AppImageUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UpdateCheckResult | null> {
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<Array<string>> {
const downloadOptions: DownloadOptions = {
Expand Down Expand Up @@ -74,37 +89,30 @@ 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
destination = appImageFile
}
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()
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ export abstract class AppUpdater extends EventEmitter {
return checkForUpdatesPromise
}

checkForUpdatesAndNotify() {
checkForUpdatesAndNotify(): Promise<UpdateCheckResult | null> {
if (isDev) {
return
return BluebirdPromise.resolve(null)
}

this.signals.updateDownloaded(it => {
Expand Down

0 comments on commit 247c18a

Please sign in to comment.