Skip to content

Commit

Permalink
feat(nsis): Add flag to force start on silent install
Browse files Browse the repository at this point in the history
Close #1545, Close #1712
  • Loading branch information
Szava authored and develar committed Jun 20, 2017
1 parent ed662e8 commit f24c389
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 10 deletions.
7 changes: 4 additions & 3 deletions docs/Auto Update.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Emitted on progress. Only supported over Windows build, since `Squirrel.Mac` [do
* [`.getFeedURL()`](#module_electron-updater.AppUpdater+getFeedURL) ⇒ <code>undefined</code> \| <code>null</code> \| <code>String</code>
* [`.setFeedURL(options)`](#module_electron-updater.AppUpdater+setFeedURL)
* [`.loadUpdateConfig()`](#module_electron-updater.AppUpdater+loadUpdateConfig) ⇒ <code>Promise&lt;any&gt;</code>
* [`.quitAndInstall(isSilent)`](#module_electron-updater.AppUpdater+quitAndInstall)
* [`.quitAndInstall(isSilent, isForceRunAfter)`](#module_electron-updater.AppUpdater+quitAndInstall)
* [.UpdaterSignal](#UpdaterSignal)
* [`.login(handler)`](#module_electron-updater.UpdaterSignal+login)
* [`.progress(handler)`](#module_electron-updater.UpdaterSignal+progress)
Expand Down Expand Up @@ -253,7 +253,7 @@ Emitted on progress. Only supported over Windows build, since `Squirrel.Mac` [do
* [`.getFeedURL()`](#module_electron-updater.AppUpdater+getFeedURL) ⇒ <code>undefined</code> \| <code>null</code> \| <code>String</code>
* [`.setFeedURL(options)`](#module_electron-updater.AppUpdater+setFeedURL)
* [`.loadUpdateConfig()`](#module_electron-updater.AppUpdater+loadUpdateConfig) ⇒ <code>Promise&lt;any&gt;</code>
* [`.quitAndInstall(isSilent)`](#module_electron-updater.AppUpdater+quitAndInstall)
* [`.quitAndInstall(isSilent, isForceRunAfter)`](#module_electron-updater.AppUpdater+quitAndInstall)

<a name="module_electron-updater.AppUpdater+checkForUpdates"></a>
#### `appUpdater.checkForUpdates()`<code>Promise&lt;[UpdateCheckResult](#UpdateCheckResult)&gt;</code>
Expand Down Expand Up @@ -288,7 +288,7 @@ Configure update provider. If value is `string`, [module:electron-builder-http/o
#### `appUpdater.loadUpdateConfig()`<code>Promise&lt;any&gt;</code>
**Kind**: instance method of [<code>AppUpdater</code>](#AppUpdater)
<a name="module_electron-updater.AppUpdater+quitAndInstall"></a>
#### `appUpdater.quitAndInstall(isSilent)`
#### `appUpdater.quitAndInstall(isSilent, isForceRunAfter)`
Restarts the app and installs the update after it has been downloaded.
It should only be called after `update-downloaded` has been emitted.

Expand All @@ -300,6 +300,7 @@ This is different from the normal quit event sequence.
| Param | Type | Description |
| --- | --- | --- |
| 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. |

<a name="UpdaterSignal"></a>
### UpdaterSignal
Expand Down
5 changes: 3 additions & 2 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,10 @@ Configuration Options
* <a name="AppXOptions-languages"></a>`languages` Array&lt;String&gt; | String - The list of [supported languages](https://docs.microsoft.com/en-us/windows/uwp/globalizing/manage-language-and-region#specify-the-supported-languages-in-the-apps-manifest) that will be listed in the Windows Store. The first entry (index 0) will be the default language. Defaults to en-US if omitted.
* <a name="AppXOptions-artifactName"></a>`artifactName` String - The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern).
* <a name="AppXOptions-publish"></a>`publish` String | [GithubOptions](Publishing-Artifacts#GithubOptions) | [S3Options](Publishing-Artifacts#S3Options) | [GenericServerOptions](Publishing-Artifacts#GenericServerOptions) | [BintrayOptions](Publishing-Artifacts#BintrayOptions) | Array
* <a name="Config-squirrelWindows"></a>`squirrelWindows`<a name="SquirrelWindowsOptions"></a> - Squirrel.Windows options.
* <a name="Config-squirrelWindows"></a>`squirrelWindows`<a name="SquirrelWindowsOptions"></a> - Squirrel.Windows options. Squirrel.Windows target is maintained, but deprecated. Please use `nsis` instead.

To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency. Squirrel.Windows target is maintained, but deprecated. Please use `nsis` instead.
To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency.
To build for Squirrel.Windows on macOS, please install `mono`: `brew install mono`.
Inherits [WinBuildOptions](#WinBuildOptions) options.
* <a name="SquirrelWindowsOptions-iconUrl"></a>`iconUrl` String - A URL to an ICO file to use as the application icon (displayed in Control Panel > Programs and Features). Defaults to the Electron icon.

Expand Down
4 changes: 4 additions & 0 deletions packages/electron-builder/src/util/bundledTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ import { getBinFromGithub } from "electron-builder-util/out/binDownload"
// 2 minutes
export const EXEC_TIMEOUT = {timeout: 120 * 1000}

/** @internal */
export interface ToolInfo {
path: string
env?: any
}

/** @internal */
export function computeEnv(oldValue: string | null | undefined, newValues: Array<string>): string {
let parsedOldValue = oldValue ? oldValue.split(":") : []
return newValues.concat(parsedOldValue).filter(it => it.length > 0).join(":")
}

/** @internal */
export function computeToolEnv(libPath: Array<string>): any {
// noinspection SpellCheckingInspection
return Object.assign({}, process.env, {
DYLD_LIBRARY_PATH: computeEnv(process.env.DYLD_LIBRARY_PATH, libPath)
})
}

/** @private */
export function getLinuxToolsPath() {
//noinspection SpellCheckingInspection
return getBinFromGithub("linux-tools", "mac-10.12", "DowDogHsS6X4a5au4r8T8qYprf7hqjfzcU7DL5oiD43jhZMfkQOjmFFYC1s7Lp9ARXp+sm8OJhuwaqCHMVGZYg==")
Expand Down
1 change: 1 addition & 0 deletions packages/electron-builder/src/util/macosVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function isOsVersionGreaterThanOrEqualTo(input: string) {
return semver.gte(await macOsVersion.value, clean(input))
}

/** @internal */
export async function isMacOsSierra() {
return process.platform === "darwin" && await isOsVersionGreaterThanOrEqualTo("10.12")
}
2 changes: 2 additions & 0 deletions packages/electron-builder/src/util/wine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const wineExecutable = new Lazy<ToolInfo>(async () => {
return {path: "wine"}
})

/** @private */
export function execWine(file: string, args: Array<string>, options: ExecOptions = EXEC_TIMEOUT): Promise<string> {
if (process.platform === "win32") {
return exec(file, args, options)
Expand All @@ -34,6 +35,7 @@ export function execWine(file: string, args: Array<string>, options: ExecOptions
}
}

/** @private */
export function prepareArgs(args: Array<string>, exePath: string) {
if (process.platform !== "win32") {
args.unshift(exePath)
Expand Down
8 changes: 8 additions & 0 deletions packages/electron-builder/templates/nsis/common.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ Name "${PRODUCT_NAME}"
!macroend
!define Updated `"" Updated ""`

!macro _ForceRun _a _b _t _f
ClearErrors
${GetParameters} $R9
${GetOptions} $R9 "--force-run" $R8
IfErrors `${_f}` `${_t}`
!macroend
!define ForceRun `"" ForceRun ""`

!macro extractEmbeddedAppPackage
!ifdef COMPRESS
SetCompress off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ ${endif}
!ifdef ONE_CLICK
!ifdef RUN_AFTER_FINISH
${IfNot} ${Silent}
${OrIf} ${ForceRun}
# otherwise app window will be in backround
HideWindow
!insertmacro StartApp
Expand Down
3 changes: 2 additions & 1 deletion packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,9 @@ export abstract class AppUpdater extends EventEmitter {
* 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.
*/
abstract quitAndInstall(isSilent?: boolean): void
abstract quitAndInstall(isSilent?: boolean, isForceRunAfter?: boolean): void

async loadUpdateConfig() {
if (this._appUpdateConfigPath == null) {
Expand Down
13 changes: 9 additions & 4 deletions packages/electron-updater/src/NsisUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,17 @@ export class NsisUpdater extends AppUpdater {

this.app.on("quit", () => {
this._logger.info("Auto install update on quit")
this.install(true)
this.install(true, false)
})
}

quitAndInstall(isSilent: boolean = false): void {
if (this.install(isSilent)) {
quitAndInstall(isSilent: boolean = false, isForceRunAfter: boolean = false): void {
if (this.install(isSilent, isForceRunAfter)) {
this.app.quit()
}
}

private install(isSilent: boolean): boolean {
private install(isSilent: boolean, isForceRunAfter: boolean): boolean {
if (this.quitAndInstallCalled) {
return false
}
Expand All @@ -163,6 +163,11 @@ export class NsisUpdater extends AppUpdater {
if (isSilent) {
args.push("/S")
}

if (isForceRunAfter) {
args.push("--force-run")
}

const spawnOptions = {
detached: true,
stdio: "ignore",
Expand Down

0 comments on commit f24c389

Please sign in to comment.