Skip to content

Commit

Permalink
feat(appx): support electron-winstore-auto-launch
Browse files Browse the repository at this point in the history
Close #3072
  • Loading branch information
develar committed Jul 14, 2018
1 parent df90039 commit 91d55da
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 57 deletions.
1 change: 1 addition & 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"@types/ejs": "^2.6.0",
"@types/electron-is-dev": "^0.3.0",
"@types/ini": "^1.3.29",
"@types/jest": "^23.1.5",
"@types/jest": "^23.1.6",
"@types/js-yaml": "^3.11.2",
"@types/lodash.isequal": "^4.5.2",
"@types/node-emoji": "^1.8.0",
Expand All @@ -94,7 +94,7 @@
"electron-builder-tslint-config": "^1.1.0",
"env-paths": "^1.0.0",
"globby": "^8.0.1",
"jest-cli": "^23.4.0",
"jest-cli": "^23.4.1",
"jest-junit": "^5.1.0",
"jsdoc-to-markdown": "^4.0.1",
"path-sort": "^0.1.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/electron-builder-lib/src/options/AppXOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export interface AppXOptions extends TargetSpecificOptions {
*/
readonly languages?: Array<string> | string | null

/**
* Whether to add auto launch extension. Defaults to `true` if [electron-winstore-auto-launch](https://github.com/felixrieseberg/electron-winstore-auto-launch) in the dependencies.
*/
readonly addAutoLaunchExtension?: boolean

/**
* @private
* @default false
Expand Down
35 changes: 29 additions & 6 deletions packages/electron-builder-lib/src/targets/AppxTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default class AppXTarget extends Target {
const userAssets = assetInfo.userAssets

const manifestFile = stageDir.getTempFile("AppxManifest.xml")
await this.writeManifest(getTemplatePath("appx"), manifestFile, arch, await this.computePublisherName(), userAssets)
await this.writeManifest(manifestFile, arch, await this.computePublisherName(), userAssets)
mappingList.push(assetInfo.mappings)
mappingList.push([`"${vm.toVmFile(manifestFile)}" "AppxManifest.xml"`])

Expand Down Expand Up @@ -161,11 +161,13 @@ export default class AppXTarget extends Target {
return publisher
}

private async writeManifest(templatePath: string, outFile: string, arch: Arch, publisher: string, userAssets: Array<string>) {
private async writeManifest(outFile: string, arch: Arch, publisher: string, userAssets: Array<string>) {
const appInfo = this.packager.appInfo
const options = this.options
const manifest = (await readFile(path.join(templatePath, "appxmanifest.xml"), "utf8"))
.replace(/\$\{([a-zA-Z0-9]+)\}/g, (match, p1): string => {
const executable = `app\\${appInfo.productFilename}.exe`
const displayName = options.displayName || appInfo.productName
const manifest = (await readFile(path.join(getTemplatePath("appx"), "appxmanifest.xml"), "utf8"))
.replace(/\${([a-zA-Z0-9]+)}/g, (match, p1): string => {
switch (p1) {
case "publisher":
return publisher
Expand Down Expand Up @@ -195,10 +197,10 @@ export default class AppXTarget extends Target {
return options.identityName || appInfo.name

case "executable":
return `app\\${appInfo.productFilename}.exe`
return executable

case "displayName":
return options.displayName || appInfo.productName
return displayName

case "description":
return appInfo.description || appInfo.productName
Expand Down Expand Up @@ -230,12 +232,33 @@ export default class AppXTarget extends Target {
case "resourceLanguages":
return resourceLanguageTag(asArray(options.languages))

case "extensions":
return this.getExtensions(executable, displayName)

default:
throw new Error(`Macro ${p1} is not defined`)
}
})
await writeFile(outFile, manifest)
}

private getExtensions(executable: string, displayName: string): string {
let isAddAutoLaunchExtension = this.options.addAutoLaunchExtension
if (isAddAutoLaunchExtension === undefined) {
const deps = this.packager.info.metadata.dependencies
isAddAutoLaunchExtension = deps != null && deps["electron-winstore-auto-launch"] != null
}

if (!isAddAutoLaunchExtension) {
return ""
}

return `<Extensions>
<desktop:Extension Category="windows.startupTask" Executable="${executable}" EntryPoint="Windows.FullTrustApplication">
<desktop:StartupTask TaskId="SlackStartup" Enabled="true" DisplayName="${displayName}" />
</desktop:Extension>
</Extensions>`
}
}

// get the resource - language tag, see https://docs.microsoft.com/en-us/windows/uwp/globalizing/manage-language-and-region#specify-the-supported-languages-in-the-apps-manifest
Expand Down
3 changes: 3 additions & 0 deletions packages/electron-builder-lib/templates/appx/appxmanifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<!--suppress XmlUnusedNamespaceDeclaration -->
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities">
<!-- use single quotes to avoid double quotes escaping in the publisher value -->
<Identity Name="${identityName}"
Expand Down Expand Up @@ -35,6 +37,7 @@
${defaultTile}
${splashScreen}
</uap:VisualElements>
${extensions}
</Application>
</Applications>
</Package>
12 changes: 12 additions & 0 deletions test/out/windows/__snapshots__/appxTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ Object {
}
`;

exports[`auto launch 1`] = `
Object {
"win": Array [
Object {
"arch": "x64",
"file": "Test App ßW-1.1.0.appx",
"safeArtifactName": "TestApp-1.1.0.appx",
},
],
}
`;

exports[`certificateSubjectName 1`] = `
Object {
"win": Array [
Expand Down
10 changes: 10 additions & 0 deletions test/src/windows/appxTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ it.ifDevOrWinCi("AppX", app({
signedWin: true,
}))

it.ifDevOrWinCi("auto launch", app({
targets: Platform.WINDOWS.createTarget(["appx"], Arch.x64),
config: {
appx: {
addAutoLaunchExtension: true,
},
},
}, {
}))

const it2 = isEnvTrue(process.env.DO_APPX_CERT_STORE_AWARE_TEST) ? test : test.skip
it2.ifNotCi("certificateSubjectName", app({
targets: Platform.WINDOWS.createTarget(["appx"], Arch.x64),
Expand Down
98 changes: 49 additions & 49 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -993,9 +993,9 @@
version "1.1.0"
resolved "https://registry.yarnpkg.com/@types/is-ci/-/is-ci-1.1.0.tgz#583c5fbfcc461be9971106b9558930d67df49227"

"@types/jest@^23.1.5":
version "23.1.5"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.1.5.tgz#e31be003956e1fa8c860124d99bea9ae327ae37b"
"@types/jest@^23.1.6":
version "23.1.6"
resolved "https://registry.yarnpkg.com/@types/jest/-/jest-23.1.6.tgz#11c88f738f5b57d1a9dd4970c576a6639b8f0f37"

"@types/js-yaml@^3.11.2":
version "3.11.2"
Expand Down Expand Up @@ -3412,9 +3412,9 @@ jest-changed-files@^23.4.0:
dependencies:
throat "^4.0.0"

jest-cli@^23.4.0:
version "23.4.0"
resolved "https://registry.yarnpkg.com/jest-cli/-/jest-cli-23.4.0.tgz#d1fdd1dbc41d69ae8bd43d0070ce23988eacd86f"
jest-cli@^23.4.1:
version "23.4.1"
resolved "https://registry.yarnpkg.com/jest-cli/-/jest-cli-23.4.1.tgz#c1ffd33254caee376990aa2abe2963e0de4ca76b"
dependencies:
ansi-escapes "^3.0.0"
chalk "^2.0.1"
Expand All @@ -3428,16 +3428,16 @@ jest-cli@^23.4.0:
istanbul-lib-instrument "^1.10.1"
istanbul-lib-source-maps "^1.2.4"
jest-changed-files "^23.4.0"
jest-config "^23.4.0"
jest-config "^23.4.1"
jest-environment-jsdom "^23.4.0"
jest-get-type "^22.1.0"
jest-haste-map "^23.4.0"
jest-haste-map "^23.4.1"
jest-message-util "^23.4.0"
jest-regex-util "^23.3.0"
jest-resolve-dependencies "^23.4.0"
jest-runner "^23.4.0"
jest-runtime "^23.4.0"
jest-snapshot "^23.4.0"
jest-resolve-dependencies "^23.4.1"
jest-runner "^23.4.1"
jest-runtime "^23.4.1"
jest-snapshot "^23.4.1"
jest-util "^23.4.0"
jest-validate "^23.4.0"
jest-watcher "^23.4.0"
Expand All @@ -3453,9 +3453,9 @@ jest-cli@^23.4.0:
which "^1.2.12"
yargs "^11.0.0"

jest-config@^23.4.0:
version "23.4.0"
resolved "https://registry.yarnpkg.com/jest-config/-/jest-config-23.4.0.tgz#79ccf8d68aa0e48f9e3beb81b83aa5875c63fa3f"
jest-config@^23.4.1:
version "23.4.1"
resolved "https://registry.yarnpkg.com/jest-config/-/jest-config-23.4.1.tgz#3172fa21f0507d7f8a088ed1dbe4157057f201e9"
dependencies:
babel-core "^6.0.0"
babel-jest "^23.4.0"
Expand All @@ -3464,9 +3464,9 @@ jest-config@^23.4.0:
jest-environment-jsdom "^23.4.0"
jest-environment-node "^23.4.0"
jest-get-type "^22.1.0"
jest-jasmine2 "^23.4.0"
jest-jasmine2 "^23.4.1"
jest-regex-util "^23.3.0"
jest-resolve "^23.4.0"
jest-resolve "^23.4.1"
jest-util "^23.4.0"
jest-validate "^23.4.0"
pretty-format "^23.2.0"
Expand Down Expand Up @@ -3512,9 +3512,9 @@ jest-get-type@^22.1.0:
version "22.4.3"
resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-22.4.3.tgz#e3a8504d8479342dd4420236b322869f18900ce4"

jest-haste-map@^23.4.0:
version "23.4.0"
resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-23.4.0.tgz#f2a0eaa41af766cd5101e6c291fdc6435c93ee1c"
jest-haste-map@^23.4.1:
version "23.4.1"
resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-23.4.1.tgz#43a174ba7ac079ae1dd74eaf5a5fe78989474dd2"
dependencies:
fb-watchman "^2.0.0"
graceful-fs "^4.1.11"
Expand All @@ -3524,9 +3524,9 @@ jest-haste-map@^23.4.0:
micromatch "^2.3.11"
sane "^2.0.0"

jest-jasmine2@^23.4.0:
version "23.4.0"
resolved "https://registry.yarnpkg.com/jest-jasmine2/-/jest-jasmine2-23.4.0.tgz#17ce539fe608ef898d6986518144acf270beca8f"
jest-jasmine2@^23.4.1:
version "23.4.1"
resolved "https://registry.yarnpkg.com/jest-jasmine2/-/jest-jasmine2-23.4.1.tgz#fa192262430d418e827636e4a98423e5e7ff0fce"
dependencies:
chalk "^2.0.1"
co "^4.6.0"
Expand All @@ -3536,7 +3536,7 @@ jest-jasmine2@^23.4.0:
jest-each "^23.4.0"
jest-matcher-utils "^23.2.0"
jest-message-util "^23.4.0"
jest-snapshot "^23.4.0"
jest-snapshot "^23.4.1"
jest-util "^23.4.0"
pretty-format "^23.2.0"

Expand Down Expand Up @@ -3581,42 +3581,42 @@ jest-regex-util@^23.3.0:
version "23.3.0"
resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-23.3.0.tgz#5f86729547c2785c4002ceaa8f849fe8ca471bc5"

jest-resolve-dependencies@^23.4.0:
version "23.4.0"
resolved "https://registry.yarnpkg.com/jest-resolve-dependencies/-/jest-resolve-dependencies-23.4.0.tgz#e73efce70262a6e2bf5263d0b23009a098678620"
jest-resolve-dependencies@^23.4.1:
version "23.4.1"
resolved "https://registry.yarnpkg.com/jest-resolve-dependencies/-/jest-resolve-dependencies-23.4.1.tgz#a1d85247e2963f8b3859f6b0ec61b741b359378e"
dependencies:
jest-regex-util "^23.3.0"
jest-snapshot "^23.4.0"
jest-snapshot "^23.4.1"

jest-resolve@^23.4.0:
version "23.4.0"
resolved "https://registry.yarnpkg.com/jest-resolve/-/jest-resolve-23.4.0.tgz#b4061dbcd6391b5e445d5fd84c9dad5ff1ff5662"
jest-resolve@^23.4.1:
version "23.4.1"
resolved "https://registry.yarnpkg.com/jest-resolve/-/jest-resolve-23.4.1.tgz#7f3c17104732a2c0c940a01256025ed745814982"
dependencies:
browser-resolve "^1.11.3"
chalk "^2.0.1"
realpath-native "^1.0.0"

jest-runner@^23.4.0:
version "23.4.0"
resolved "https://registry.yarnpkg.com/jest-runner/-/jest-runner-23.4.0.tgz#1859b211a264ea5a43b7a3022e1199067c4dfe57"
jest-runner@^23.4.1:
version "23.4.1"
resolved "https://registry.yarnpkg.com/jest-runner/-/jest-runner-23.4.1.tgz#d41fd1459b95d35d6df685f1468c09e617c8c260"
dependencies:
exit "^0.1.2"
graceful-fs "^4.1.11"
jest-config "^23.4.0"
jest-config "^23.4.1"
jest-docblock "^23.2.0"
jest-haste-map "^23.4.0"
jest-jasmine2 "^23.4.0"
jest-haste-map "^23.4.1"
jest-jasmine2 "^23.4.1"
jest-leak-detector "^23.2.0"
jest-message-util "^23.4.0"
jest-runtime "^23.4.0"
jest-runtime "^23.4.1"
jest-util "^23.4.0"
jest-worker "^23.2.0"
source-map-support "^0.5.6"
throat "^4.0.0"

jest-runtime@^23.4.0:
version "23.4.0"
resolved "https://registry.yarnpkg.com/jest-runtime/-/jest-runtime-23.4.0.tgz#c30ef619def587b93bad4a4938da9accb9936b4d"
jest-runtime@^23.4.1:
version "23.4.1"
resolved "https://registry.yarnpkg.com/jest-runtime/-/jest-runtime-23.4.1.tgz#c1822eba5eb19294debe6b25b2760d0a8c532fd1"
dependencies:
babel-core "^6.0.0"
babel-plugin-istanbul "^4.1.6"
Expand All @@ -3625,12 +3625,12 @@ jest-runtime@^23.4.0:
exit "^0.1.2"
fast-json-stable-stringify "^2.0.0"
graceful-fs "^4.1.11"
jest-config "^23.4.0"
jest-haste-map "^23.4.0"
jest-config "^23.4.1"
jest-haste-map "^23.4.1"
jest-message-util "^23.4.0"
jest-regex-util "^23.3.0"
jest-resolve "^23.4.0"
jest-snapshot "^23.4.0"
jest-resolve "^23.4.1"
jest-snapshot "^23.4.1"
jest-util "^23.4.0"
jest-validate "^23.4.0"
micromatch "^2.3.11"
Expand All @@ -3644,17 +3644,17 @@ jest-serializer@^23.0.1:
version "23.0.1"
resolved "https://registry.yarnpkg.com/jest-serializer/-/jest-serializer-23.0.1.tgz#a3776aeb311e90fe83fab9e533e85102bd164165"

jest-snapshot@^23.4.0:
version "23.4.0"
resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-23.4.0.tgz#7463d0357cabdfe1c63994d5e32f707d1033d616"
jest-snapshot@^23.4.1:
version "23.4.1"
resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-23.4.1.tgz#090de9acae927f6a3af3005bda40d912b83e9c96"
dependencies:
babel-traverse "^6.0.0"
babel-types "^6.0.0"
chalk "^2.0.1"
jest-diff "^23.2.0"
jest-matcher-utils "^23.2.0"
jest-message-util "^23.4.0"
jest-resolve "^23.4.0"
jest-resolve "^23.4.1"
mkdirp "^0.5.1"
natural-compare "^1.4.0"
pretty-format "^23.2.0"
Expand Down

0 comments on commit 91d55da

Please sign in to comment.