Skip to content

Commit

Permalink
feat(appx): add support for custom extensions in appmanifest.xml
Browse files Browse the repository at this point in the history
Close #4707
  • Loading branch information
develar committed Mar 3, 2020
1 parent b03f2c1 commit 6d7b25c
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 61 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
"ts-jsdoc": "^3.1.1",
"tslint": "^6.0.0",
"typescript": "~3.8.3",
"typescript-json-schema": "^0.42.0",
"whitespace": "^2.1.0",
"worker-farm": "^1.7.0"
},
Expand Down
142 changes: 93 additions & 49 deletions packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@
"string"
]
},
"customExtensionsPath": {
"description": "Relative path to custom extensions xml to be included in an `appmanifest.xml`.",
"type": "string"
},
"displayName": {
"description": "A friendly name that can be displayed to users. Corresponds to [Properties.DisplayName](https://msdn.microsoft.com/en-us/library/windows/apps/br211432.aspx).\nDefaults to the application product name.",
"type": [
Expand Down Expand Up @@ -1560,9 +1564,6 @@
},
"target": {
"anyOf": [
{
"$ref": "#/definitions/TargetConfiguration"
},
{
"items": {
"anyOf": [
Expand All @@ -1576,6 +1577,9 @@
},
"type": "array"
},
{
"$ref": "#/definitions/TargetConfiguration"
},
{
"type": [
"null",
Expand Down Expand Up @@ -2112,41 +2116,41 @@
"string"
]
},
"helperRendererBundleId": {
"default": "${appBundleIdentifier}.helper.Renderer",
"description": "The bundle identifier to use in the Renderer helper's plist.",
"helperEHBundleId": {
"default": "${appBundleIdentifier}.helper.EH",
"description": "The bundle identifier to use in the EH helper's plist.",
"type": [
"null",
"string"
]
},
"helperPluginBundleId": {
"default": "${appBundleIdentifier}.helper.Plugin",
"description": "The bundle identifier to use in the Plugin helper's plist.",
"helperGPUBundleId": {
"default": "${appBundleIdentifier}.helper.GPU",
"description": "The bundle identifier to use in the GPU helper's plist.",
"type": [
"null",
"string"
]
},
"helperGPUBundleId": {
"default": "${appBundleIdentifier}.helper.GPU",
"description": "The bundle identifier to use in the GPU helper's plist.",
"helperNPBundleId": {
"default": "${appBundleIdentifier}.helper.NP",
"description": "The bundle identifier to use in the NP helper's plist.",
"type": [
"null",
"string"
]
},
"helperEHBundleId": {
"default": "${appBundleIdentifier}.helper.EH",
"description": "The bundle identifier to use in the EH helper's plist.",
"helperPluginBundleId": {
"default": "${appBundleIdentifier}.helper.Plugin",
"description": "The bundle identifier to use in the Plugin helper's plist.",
"type": [
"null",
"string"
]
},
"helperNPBundleId": {
"default": "${appBundleIdentifier}.helper.NP",
"description": "The bundle identifier to use in the NP helper's plist.",
"helperRendererBundleId": {
"default": "${appBundleIdentifier}.helper.Renderer",
"description": "The bundle identifier to use in the Renderer helper's plist.",
"type": [
"null",
"string"
Expand Down Expand Up @@ -2652,6 +2656,46 @@
"string"
]
},
"helperEHBundleId": {
"default": "${appBundleIdentifier}.helper.EH",
"description": "The bundle identifier to use in the EH helper's plist.",
"type": [
"null",
"string"
]
},
"helperGPUBundleId": {
"default": "${appBundleIdentifier}.helper.GPU",
"description": "The bundle identifier to use in the GPU helper's plist.",
"type": [
"null",
"string"
]
},
"helperNPBundleId": {
"default": "${appBundleIdentifier}.helper.NP",
"description": "The bundle identifier to use in the NP helper's plist.",
"type": [
"null",
"string"
]
},
"helperPluginBundleId": {
"default": "${appBundleIdentifier}.helper.Plugin",
"description": "The bundle identifier to use in the Plugin helper's plist.",
"type": [
"null",
"string"
]
},
"helperRendererBundleId": {
"default": "${appBundleIdentifier}.helper.Renderer",
"description": "The bundle identifier to use in the Renderer helper's plist.",
"type": [
"null",
"string"
]
},
"icon": {
"default": "build/icon.icns",
"description": "The path to application icon.",
Expand Down Expand Up @@ -3765,6 +3809,20 @@
"string"
]
},
"mustClose": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"description": "Identifies applications that must be closed before the package is installed.\\n\\nCorresponds to [must-close](https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html#//apple_ref/doc/uid/TP40005370-CH100-SW77)"
},
"overwriteAction": {
"anyOf": [
{
Expand Down Expand Up @@ -3871,20 +3929,6 @@
"null",
"string"
]
},
"mustClose": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array"
},
{
"type": "null"
}
],
"description": "Identifies applications that must be closed before the package is installed.\n\nCorresponds to [must-close](https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html#//apple_ref/doc/uid/TP40005370-CH100-SW77)"
}
},
"type": "object"
Expand Down Expand Up @@ -3982,13 +4026,6 @@
}
]
},
"splashImage": {
"describe": "The image to show while the portable executable is extracting. This image must be a bitmap (`.bmp`) image.",
"type": [
"null",
"string"
]
},
"requestExecutionLevel": {
"default": "user",
"description": "The [requested execution level](http://nsis.sourceforge.net/Reference/RequestExecutionLevel) for Windows.",
Expand All @@ -3999,6 +4036,13 @@
],
"type": "string"
},
"splashImage": {
"description": "The image to show while the portable executable is extracting. This image must be a bitmap (`.bmp`) image.",
"type": [
"null",
"string"
]
},
"unicode": {
"default": true,
"description": "Whether to create [Unicode installer](http://nsis.sourceforge.net/Docs/Chapter1.html#intro-unicode).",
Expand Down Expand Up @@ -5217,9 +5261,6 @@
},
"target": {
"anyOf": [
{
"$ref": "#/definitions/TargetConfiguration"
},
{
"items": {
"anyOf": [
Expand All @@ -5233,6 +5274,9 @@
},
"type": "array"
},
{
"$ref": "#/definitions/TargetConfiguration"
},
{
"type": [
"null",
Expand Down Expand Up @@ -5343,7 +5387,7 @@
}
]
},
"artifactBuildCompleted": {
"appxManifestCreated": {
"anyOf": [
{
"typeof": "function"
Expand All @@ -5355,9 +5399,9 @@
]
}
],
"description": "The function (or path to file or module id) to be run on artifact build completed."
"description": "Appx manifest created on disk - not packed into .appx package yet."
},
"artifactBuildStarted": {
"artifactBuildCompleted": {
"anyOf": [
{
"typeof": "function"
Expand All @@ -5369,9 +5413,9 @@
]
}
],
"description": "The function (or path to file or module id) to be run on artifact build start."
"description": "The function (or path to file or module id) to be run on artifact build completed."
},
"appxManifestCreated": {
"artifactBuildStarted": {
"anyOf": [
{
"typeof": "function"
Expand All @@ -5383,7 +5427,7 @@
]
}
],
"description": "The function (or path to file or module id) to be run when appx manifest is created but before it is packed into the installer bundle."
"description": "The function (or path to file or module id) to be run on artifact build start."
},
"artifactName": {
"description": "The [artifact file name template](/configuration/configuration#artifact-file-name-template). Defaults to `${productName}-${version}.${ext}` (some target can have other defaults, see corresponding options).",
Expand Down Expand Up @@ -6039,4 +6083,4 @@
}
},
"type": "object"
}
}
5 changes: 5 additions & 0 deletions packages/app-builder-lib/src/options/AppXOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export interface AppXOptions extends TargetSpecificOptions {
*/
readonly addAutoLaunchExtension?: boolean

/**
* Relative path to custom extensions xml to be included in an `appmanifest.xml`.
*/
readonly customExtensionsPath?: string

/**
* Whether to overlay the app's name on top of tile images on the Start screen. Defaults to `false`. (https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/element-uap-shownameontiles) in the dependencies.
* @default false
Expand Down
18 changes: 14 additions & 4 deletions packages/app-builder-lib/src/targets/AppxTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ export default class AppXTarget extends Target {
const options = this.options
const executable = `app\\${appInfo.productFilename}.exe`
const displayName = options.displayName || appInfo.productName
const extensions = await this.getExtensions(executable, displayName)

const manifest = (await readFile(path.join(getTemplatePath("appx"), "appxmanifest.xml"), "utf8"))
.replace(/\${([a-zA-Z0-9]+)}/g, (match, p1): string => {
switch (p1) {
Expand Down Expand Up @@ -200,7 +202,7 @@ export default class AppXTarget extends Target {
return result

case "identityName":
return options.identityName || appInfo.name
return options.identityName || appInfo.name

case "executable":
return executable
Expand Down Expand Up @@ -239,7 +241,7 @@ export default class AppXTarget extends Target {
return resourceLanguageTag(asArray(options.languages))

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

case "minVersion":
return arch === Arch.arm64 ? "10.0.16299.0" : "10.0.14316.0"
Expand All @@ -254,7 +256,7 @@ export default class AppXTarget extends Target {
await writeFile(outFile, manifest)
}

private getExtensions(executable: string, displayName: string): string {
private async getExtensions(executable: string, displayName: string): Promise<string> {
const uriSchemes = asArray(this.packager.config.protocols)
.concat(asArray(this.packager.platformSpecificBuildOptions.protocols))

Expand All @@ -267,7 +269,10 @@ export default class AppXTarget extends Target {
isAddAutoLaunchExtension = deps != null && deps["electron-winstore-auto-launch"] != null
}

if (!isAddAutoLaunchExtension && uriSchemes.length === 0 && fileAssociations.length === 0) {
if (!isAddAutoLaunchExtension
&& uriSchemes.length === 0
&& fileAssociations.length === 0
&& this.options.customExtensionsPath === undefined) {
return ""
}

Expand Down Expand Up @@ -304,6 +309,11 @@ export default class AppXTarget extends Target {
}
}

if (this.options.customExtensionsPath !== undefined) {
const extensionsPath = path.resolve(this.packager.info.appDir, this.options.customExtensionsPath)
extensions += await readFile(extensionsPath, "utf8")
}

extensions += "</Extensions>"
return extensions
}
Expand Down
Loading

0 comments on commit 6d7b25c

Please sign in to comment.