Skip to content

Commit

Permalink
feat(portable): ExecutionLevel for nsis portable
Browse files Browse the repository at this point in the history
Close #1440
  • Loading branch information
develar committed Apr 8, 2017
1 parent fa50854 commit 3f8caab
Show file tree
Hide file tree
Showing 17 changed files with 13,525 additions and 10,328 deletions.
37 changes: 36 additions & 1 deletion docs/Developer API.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
<dd></dd>
<dt><a href="#module_electron-builder/out/options/linuxOptions">electron-builder/out/options/linuxOptions</a></dt>
<dd></dd>
<dt><a href="#module_electron-builder/out/options/winOptions">electron-builder/out/options/winOptions</a></dt>
<dd></dd>
<dt><a href="#module_electron-builder/out/packager/dirPackager">electron-builder/out/packager/dirPackager</a></dt>
<dd></dd>
<dt><a href="#module_electron-builder/out/packager/mac">electron-builder/out/packager/mac</a></dt>
Expand Down Expand Up @@ -1228,6 +1230,39 @@
| depends| <code>Array&lt;string&gt;</code> \| <code>null</code> | <a name="LinuxTargetSpecificOptions-depends"></a>Package dependencies. |
| icon| <code>string</code> | <a name="LinuxTargetSpecificOptions-icon"></a> |

<a name="module_electron-builder/out/options/winOptions"></a>

## electron-builder/out/options/winOptions

* [electron-builder/out/options/winOptions](#module_electron-builder/out/options/winOptions)
* [`.CommonNsisOptions`](#CommonNsisOptions)
* [`.PortableOptions`](#PortableOptions) ⇐ <code>[CommonNsisOptions](#CommonNsisOptions)</code>

<a name="CommonNsisOptions"></a>

### `CommonNsisOptions`
**Kind**: interface of <code>[electron-builder/out/options/winOptions](#module_electron-builder/out/options/winOptions)</code>
**Properties**

| Name | Type |
| --- | --- |
| unicode| <code>boolean</code> |
| guid| <code>string</code> \| <code>null</code> |
| warningsAsErrors| <code>boolean</code> |

<a name="PortableOptions"></a>

### `PortableOptions` ⇐ <code>[CommonNsisOptions](#CommonNsisOptions)</code>
Portable Specific Options ([portable](#Config-portable})

**Kind**: interface of <code>[electron-builder/out/options/winOptions](#module_electron-builder/out/options/winOptions)</code>
**Extends**: <code>[CommonNsisOptions](#CommonNsisOptions)</code>
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| requestExecutionLevel = <code>user</code>| <code>"user"</code> \| <code>"highest"</code> \| <code>"admin"</code> | <a name="PortableOptions-requestExecutionLevel"></a>The [requested execution level](http://nsis.sourceforge.net/Reference/RequestExecutionLevel) for Windows. |

<a name="module_electron-builder/out/packager/dirPackager"></a>

## electron-builder/out/packager/dirPackager
Expand Down Expand Up @@ -2990,6 +3025,7 @@ On Windows works only if [nsis.perMachine](https://github.com/electron-userland/
| target| <code>Array&lt;string \| [TargetConfig](#TargetConfig)&gt;</code> \| <code>string</code> \| <code>[TargetConfig](#TargetConfig)</code> \| <code>null</code> |
| icon| <code>string</code> \| <code>null</code> |
| fileAssociations| <code>Array&lt;[FileAssociation](#FileAssociation)&gt;</code> \| <code>[FileAssociation](#FileAssociation)</code> |
| forceCodeSigning| <code>boolean</code> |

<a name="Protocol"></a>

Expand Down Expand Up @@ -3050,7 +3086,6 @@ Please note — on macOS [you need to register an `open-url` event handler](http
| Name | Type | Description |
| --- | --- | --- |
| artifactName| <code>string</code> \| <code>null</code> | <a name="TargetSpecificOptions-artifactName"></a>The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). |
| forceCodeSigning| <code>boolean</code> | <a name="TargetSpecificOptions-forceCodeSigning"></a> |
| publish| <code>null</code> \| <code>string</code> \| <code>[GithubOptions](Publishing-Artifacts#GithubOptions)</code> \| <code>[S3Options](Publishing-Artifacts#S3Options)</code> \| <code>[GenericServerOptions](Publishing-Artifacts#GenericServerOptions)</code> \| <code>[BintrayOptions](Publishing-Artifacts#BintrayOptions)</code> \| <code>Array</code> | <a name="TargetSpecificOptions-publish"></a> |

<a name="Platform"></a>
Expand Down
19 changes: 11 additions & 8 deletions docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ You can use [file macros](#file-macros) in the `from` and `to` fields as well.
* [`.MacOptions`](#MacOptions) ⇐ <code>[PlatformSpecificBuildOptions](Developer-API#PlatformSpecificBuildOptions)</code>
* [`.MasBuildOptions`](#MasBuildOptions) ⇐ <code>[MacOptions](#MacOptions)</code>
* [`.Metadata`](#Metadata)
* [`.NsisOptions`](#NsisOptions)
* [`.NsisOptions`](#NsisOptions) ⇐ <code>[TargetSpecificOptions](Developer-API#TargetSpecificOptions)</code>
* [`.NsisWebOptions`](#NsisWebOptions) ⇐ <code>[NsisOptions](#NsisOptions)</code>
* [`.PackagerOptions`](#PackagerOptions)
* [`.PkgOptions`](#PkgOptions) ⇐ <code>[TargetSpecificOptions](Developer-API#TargetSpecificOptions)</code>
Expand Down Expand Up @@ -141,7 +141,7 @@ You can use [file macros](#file-macros) in the `from` and `to` fields as well.
<a name="AppXOptions"></a>

### `AppXOptions`
AppX Options
AppX Options ([appx](#Config-appx}).

**Kind**: interface of <code>[electron-builder](#module_electron-builder)</code>
**See**: [Windows AppX docs](https://msdn.microsoft.com/en-us/library/windows/apps/br211453.aspx).
Expand Down Expand Up @@ -276,7 +276,7 @@ Configuration Options
| win| <code>[WinBuildOptions](#WinBuildOptions)</code> \| <code>null</code> | <a name="Config-win"></a> |
| nsis| <code>[NsisOptions](#NsisOptions)</code> \| <code>null</code> | <a name="Config-nsis"></a> |
| nsisWeb| <code>[NsisWebOptions](#NsisWebOptions)</code> \| <code>null</code> | <a name="Config-nsisWeb"></a> |
| portable| <code>[NsisOptions](#NsisOptions)</code> \| <code>null</code> | <a name="Config-portable"></a> |
| portable| <code>[PortableOptions](Developer-API#PortableOptions)</code> \| <code>null</code> | <a name="Config-portable"></a> |
| appx| <code>[AppXOptions](#AppXOptions)</code> \| <code>null</code> | <a name="Config-appx"></a> |
| squirrelWindows| <code>[SquirrelWindowsOptions](#SquirrelWindowsOptions)</code> \| <code>null</code> | <a name="Config-squirrelWindows"></a> |
| linux| <code>[LinuxBuildOptions](#LinuxBuildOptions)</code> \| <code>null</code> | <a name="Config-linux"></a> |
Expand Down Expand Up @@ -454,11 +454,13 @@ Some standard fields should be defined in the `package.json`.

<a name="NsisOptions"></a>

### `NsisOptions`
NSIS specific options
### `NsisOptions` ⇐ <code>[TargetSpecificOptions](Developer-API#TargetSpecificOptions)</code>
NSIS specific options ([nsis](#Config-nsis}).

See [NSIS target notes](https://github.com/electron-userland/electron-builder/wiki/NSIS).

**Kind**: interface of <code>[electron-builder](#module_electron-builder)</code>
**Extends**: <code>[TargetSpecificOptions](Developer-API#TargetSpecificOptions)</code>
**Properties**

| Name | Type | Description |
Expand Down Expand Up @@ -488,7 +490,7 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
<a name="NsisWebOptions"></a>

### `NsisWebOptions` ⇐ <code>[NsisOptions](#NsisOptions)</code>
Web Installer Specific Options
Web Installer Specific Options ([nsisWeb](#Config-nsisWeb}).

**Kind**: interface of <code>[electron-builder](#module_electron-builder)</code>
**Extends**: <code>[NsisOptions](#NsisOptions)</code>
Expand Down Expand Up @@ -558,7 +560,8 @@ Web Installer Specific Options
<a name="SquirrelWindowsOptions"></a>

### `SquirrelWindowsOptions` ⇐ <code>[WinBuildOptions](#WinBuildOptions)</code>
Squirrel.Windows Options.
Squirrel.Windows Options ([squirrelWindows](#Config-squirrelWindows}).

To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency. Squirrel.Windows target is maintained, but deprecated. Please use `nsis` instead.

**Kind**: interface of <code>[electron-builder](#module_electron-builder)</code>
Expand All @@ -577,7 +580,7 @@ To use Squirrel.Windows please install `electron-builder-squirrel-windows` depen
<a name="WinBuildOptions"></a>

### `WinBuildOptions` ⇐ <code>[PlatformSpecificBuildOptions](Developer-API#PlatformSpecificBuildOptions)</code>
Windows Specific Options
Windows Specific Options ([win](#Config-win}).

**Kind**: interface of <code>[electron-builder](#module_electron-builder)</code>
**Extends**: <code>[PlatformSpecificBuildOptions](Developer-API#PlatformSpecificBuildOptions)</code>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ajv": "^5.0.4-beta.2",
"ajv-keywords": "^2.0.1-beta.2",
"archiver": "^1.3.0",
"aws-sdk": "^2.39.0",
"aws-sdk": "^2.40.0",
"bluebird-lst": "^1.0.2",
"chalk": "^1.1.3",
"chromium-pickle-js": "^0.2.0",
Expand Down Expand Up @@ -70,9 +70,9 @@
"@types/source-map-support": "^0.2.28",
"@types/xml2js": "^0.0.33",
"babel-plugin-array-includes": "^2.0.3",
"babel-plugin-transform-async-to-module-method": "^6.22.0",
"babel-plugin-transform-async-to-module-method": "^6.24.1",
"babel-plugin-transform-es2015-destructuring": "^6.23.0",
"babel-plugin-transform-es2015-parameters": "^6.23.0",
"babel-plugin-transform-es2015-parameters": "^6.24.1",
"babel-plugin-transform-es2015-spread": "^6.22.0",
"babel-plugin-transform-inline-imports-commonjs": "^1.2.0",
"catharsis": "^0.8.8",
Expand Down
4 changes: 2 additions & 2 deletions packages/electron-builder-core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ export interface TargetSpecificOptions {
The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern).
*/
readonly artifactName?: string | null

readonly forceCodeSigning?: boolean

readonly publish?: Publish
}
Expand All @@ -138,6 +136,8 @@ export interface PlatformSpecificBuildOptions extends TargetSpecificOptions {
readonly icon?: string | null

readonly fileAssociations?: Array<FileAssociation> | FileAssociation

readonly forceCodeSigning?: boolean
}

export const DEFAULT_TARGET = "default"
Expand Down
14 changes: 7 additions & 7 deletions packages/electron-builder/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Arch, AsarOptions, AuthorMetadata, BeforeBuildContext, CompressionLevel
import { Publish } from "electron-builder-http/out/publishOptions"
import { DebOptions, LinuxBuildOptions, LinuxTargetSpecificOptions, SnapOptions } from "./options/linuxOptions"
import { DmgOptions, MacOptions, MasBuildOptions, PkgOptions } from "./options/macOptions"
import { AppXOptions, NsisOptions, NsisWebOptions, SquirrelWindowsOptions, WinBuildOptions } from "./options/winOptions"
import { AppXOptions, NsisOptions, NsisWebOptions, PortableOptions, SquirrelWindowsOptions, WinBuildOptions } from "./options/winOptions"
import { PlatformPackager } from "./platformPackager"

/**
Expand Down Expand Up @@ -207,12 +207,12 @@ export interface Config extends PlatformSpecificBuildOptions {
readonly dmg?: DmgOptions | null
readonly pkg?: PkgOptions | null

readonly win?: WinBuildOptions | null
readonly nsis?: NsisOptions | null
readonly nsisWeb?: NsisWebOptions | null
readonly portable?: NsisOptions | null
readonly appx?: AppXOptions | null
readonly squirrelWindows?: SquirrelWindowsOptions | null
readonly win?: WinBuildOptions | null
readonly nsis?: NsisOptions | null
readonly nsisWeb?: NsisWebOptions | null
readonly portable?: PortableOptions | null
readonly appx?: AppXOptions | null
readonly squirrelWindows?: SquirrelWindowsOptions | null

readonly linux?: LinuxBuildOptions | null
readonly deb?: DebOptions | null
Expand Down
33 changes: 26 additions & 7 deletions packages/electron-builder/src/options/winOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PlatformSpecificBuildOptions, TargetConfigType } from "electron-builder-core"
import { PlatformSpecificBuildOptions, TargetConfigType, TargetSpecificOptions } from "electron-builder-core"

/**
* Windows Specific Options
* Windows Specific Options ([win](#Config-win}).
*/
export interface WinBuildOptions extends PlatformSpecificBuildOptions {
/**
Expand Down Expand Up @@ -69,11 +69,18 @@ export interface WinBuildOptions extends PlatformSpecificBuildOptions {
readonly publisherName?: string | Array<string> | null
}

export interface CommonNsisOptions {
readonly unicode?: boolean
readonly guid?: string | null
readonly warningsAsErrors?: boolean
}

/**
* NSIS specific options
* NSIS specific options ([nsis](#Config-nsis}).
*
* See [NSIS target notes](https://github.com/electron-userland/electron-builder/wiki/NSIS).
*/
export interface NsisOptions {
export interface NsisOptions extends CommonNsisOptions, TargetSpecificOptions {
/**
* One-click installation.
* @default true
Expand Down Expand Up @@ -208,8 +215,19 @@ export interface NsisOptions {
readonly deleteAppDataOnUninstall?: boolean
}

/**
* Portable Specific Options ([portable](#Config-portable})
*/
export interface PortableOptions extends TargetSpecificOptions, CommonNsisOptions {
/**
* The [requested execution level](http://nsis.sourceforge.net/Reference/RequestExecutionLevel) for Windows.
* @default user
*/
readonly requestExecutionLevel?: "user" | "highest" | "admin"
}

/**
* Web Installer Specific Options
* Web Installer Specific Options ([nsisWeb](#Config-nsisWeb}).
*/
export interface NsisWebOptions extends NsisOptions {
/**
Expand All @@ -228,7 +246,8 @@ export interface NsisWebOptions extends NsisOptions {
}

/**
* Squirrel.Windows Options.
* Squirrel.Windows Options ([squirrelWindows](#Config-squirrelWindows}).
*
* To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency. Squirrel.Windows target is maintained, but deprecated. Please use `nsis` instead.
*/
export interface SquirrelWindowsOptions extends WinBuildOptions {
Expand Down Expand Up @@ -270,7 +289,7 @@ export interface SquirrelWindowsOptions extends WinBuildOptions {
}

/**
* AppX Options
* AppX Options ([appx](#Config-appx}).
* @see [Windows AppX docs](https://msdn.microsoft.com/en-us/library/windows/apps/br211453.aspx).
*/
export interface AppXOptions {
Expand Down
51 changes: 29 additions & 22 deletions packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { safeLoad } from "js-yaml"
import * as path from "path"
import sanitizeFileName from "sanitize-filename"
import { v5 as uuid5 } from "uuid-1345"
import { NsisOptions } from "../options/winOptions"
import { NsisOptions, PortableOptions } from "../options/winOptions"
import { normalizeExt } from "../platformPackager"
import { getSignVendorPath } from "../windowsCodeSign"
import { WinPackager } from "../winPackager"
Expand Down Expand Up @@ -154,7 +154,10 @@ export default class NsisTarget extends Target {
}

this.configureDefinesForAllTypeOfInstaller(defines)
if (!isPortable) {
if (isPortable) {
defines.REQUEST_EXECUTION_LEVEL = (<PortableOptions>options).requestExecutionLevel || "user"
}
else {
await this.configureDefines(oneClick, defines)
}

Expand Down Expand Up @@ -375,31 +378,16 @@ export default class NsisTarget extends Target {
scriptHeader += createMacro("licensePage", licensePage)
}

const messages = safeLoad(await readFile(path.join(__dirname, "..", "..", "templates", "nsis", "messages.yml"), "utf-8"))
const langs: Array<string> = []
for (const messageId of Object.keys(messages)) {
const langToTranslations = messages[messageId]
const unspecifiedLangs = new Set(bundledLanguages)
for (const lang of Object.keys(langToTranslations)) {
const langWithRegion = toLangWithRegion(lang)
langs.push(`LangString ${messageId} ${lcid[langWithRegion]} "${langToTranslations[lang].replace(/\n/g, "$\\r$\\n")}"`)
unspecifiedLangs.delete(langWithRegion)
}

const defaultTranslation = langToTranslations["en"].replace(/\n/g, "$\\r$\\n")
for (const langWithRegion of unspecifiedLangs) {
langs.push(`LangString ${messageId} ${lcid[langWithRegion]} "${defaultTranslation}"`)
}
}

if (langs.length > 0) {
scriptHeader += "\n" + langs.join("\n") + "\n\n"
}
scriptHeader += "\n" + computeCustomMessageTranslations(safeLoad(await readFile(path.join(this.nsisTemplatesDir, "messages.yml"), "utf-8"))).join("\n") + "\n\n"

if (this.isPortable) {
return scriptHeader + originalScript
}

if (this.options.oneClick === false) {
scriptHeader += "\n" + computeCustomMessageTranslations(safeLoad(await readFile(path.join(this.nsisTemplatesDir, "boringMessages.yml"), "utf-8"))).join("\n") + "\n\n"
}

const customInclude = await packager.getResource(this.options.include, "installer.nsh")
if (customInclude != null) {
scriptHeader += `!addincludedir "${packager.buildResourcesDir}"\n`
Expand Down Expand Up @@ -504,6 +492,25 @@ export default class NsisTarget extends Target {
}
}

function computeCustomMessageTranslations(messages: any): Array<string> {
const result: Array<string> = []
for (const messageId of Object.keys(messages)) {
const langToTranslations = messages[messageId]
const unspecifiedLangs = new Set(bundledLanguages)
for (const lang of Object.keys(langToTranslations)) {
const langWithRegion = toLangWithRegion(lang)
result.push(`LangString ${messageId} ${lcid[langWithRegion]} "${langToTranslations[lang].replace(/\n/g, "$\\r$\\n")}"`)
unspecifiedLangs.delete(langWithRegion)
}

const defaultTranslation = langToTranslations["en"].replace(/\n/g, "$\\r$\\n")
for (const langWithRegion of unspecifiedLangs) {
result.push(`LangString ${messageId} ${lcid[langWithRegion]} "${defaultTranslation}"`)
}
}
return result
}

function toLangWithRegion(lang: string): string {
let langWithRegion = langToLangWithRegion.get(lang)
if (langWithRegion == null) {
Expand Down
18 changes: 18 additions & 0 deletions packages/electron-builder/templates/nsis/boringMessages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
chooseInstallationOptions:
en: Choose Installation Options
ru: Выберите опции установки
chooseUninstallationOptions:
en: Choose Uninstallation Options
ru: Выберите опции удаления
freshInstallForAll:
en: Fresh install for all users.
ru: Новая установка для всех пользователей.
freshInstallForCurrent:
en: Fresh install for current user only.
ru: Новая установка только для текущего пользователя.
onlyForMe:
en: Only for &me
ru: Только для &меня
forAll:
en: Anyone who uses this computer (&all users)
ru: Для &всех пользователей данного компьютера
Loading

0 comments on commit 3f8caab

Please sign in to comment.