-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(windows): capabilities #9437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat(windows): capabilities #9437
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also generate a changeset for the CHANGELOG and CI/CD to pick it up. You can use pnpm generate-changeset for CLI
| xmlns:uap4="http://schemas.microsoft.com/appx/manifest/uap/windows10/4" | ||
| xmlns:uap6="http://schemas.microsoft.com/appx/manifest/uap/windows10/6" | ||
| xmlns:uap7="http://schemas.microsoft.com/appx/manifest/uap/windows10/7" | ||
| xmlns:uap11="http://schemas.microsoft.com/appx/manifest/uap/windows10/11" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this backwards compatible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backward compatible to what?
I could possibly implement a routine that adds the namespace declarations when needed by a capability. Would that be acceptable?
Idea: new replacement token ${namespaces} for manifest parsing
<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"
${namespaces} >
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Backward compatible to what?
My apologies. Is there any side effects in adding each new line of xmlns to the manifest? (I'm not familiar with appx tbh)
| // order matters | ||
| // see https://learn.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/element-capabilities | ||
|
|
||
| export const CAPABILITIES = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wildly overcomplicated/over-engineered to me. Instead of classes for each object that only are using super. Why not just use a Map<CompatibilityType, string>?
Here's the rewritten code of what I'm thinking is more optimized and it dramatically reduces the number of classes/super being used.
export interface Capability {
readonly nsAlias: string | null;
readonly nsURI: string | null;
readonly name: string;
toXMLString(): string;
}
type CapabilityConfig = {
nsAlias: string | null;
nsURI: string | null;
elementName: string;
};
class AppxCapability implements Capability {
constructor(
public readonly nsAlias: string | null,
public readonly nsURI: string | null,
private readonly elementName: string,
public readonly name: string
) {}
toXMLString(): string {
const tagName = this.nsAlias ? `${this.nsAlias}:${this.elementName}` : this.elementName;
return `<${tagName} Name="${this.name}"/>`;
}
}
// Capability type configurations
const CAPABILITY_TYPES = {
common: {
nsAlias: null,
nsURI: "http://schemas.microsoft.com/appx/manifest/foundation/windows10",
elementName: "Capability",
},
device: {
nsAlias: null,
nsURI: "http://schemas.microsoft.com/appx/manifest/foundation/windows10",
elementName: "DeviceCapability",
},
uap: {
nsAlias: "uap",
nsURI: "http://schemas.microsoft.com/appx/manifest/uap/windows10",
elementName: "Capability",
},
uap6: {
nsAlias: "uap6",
nsURI: "http://schemas.microsoft.com/appx/manifest/uap/windows10/6",
elementName: "Capability",
},
uap7: {
nsAlias: "uap7",
nsURI: "http://schemas.microsoft.com/appx/manifest/uap/windows10/7",
elementName: "Capability",
},
uap11: {
nsAlias: "uap11",
nsURI: "http://schemas.microsoft.com/appx/manifest/uap/windows10/11",
elementName: "Capability",
},
mobile: {
nsAlias: "mobile",
nsURI: "http://schemas.microsoft.com/appx/manifest/mobile/windows10",
elementName: "Capability",
},
rescap: {
nsAlias: "rescap",
nsURI: "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities",
elementName: "Capability",
},
} as const;
type CapabilityType = keyof typeof CAPABILITY_TYPES;
// Map of capability types to their capability names (grouped by type)
const CAPABILITY_MAP = new Map<CapabilityType, string[]>([
// Common capabilities
["common", [
"internetClient",
"internetClientServer",
"privateNetworkClientServer",
"codeGeneration",
"allJoyn",
"backgroundMediaPlayback",
"remoteSystem",
"spatialPerception",
"userDataTasks",
"userNotificationListener",
]],
// UAP capabilities
["uap", [
"musicLibrary",
"picturesLibrary",
"videosLibrary",
"removableStorage",
"appointments",
"contacts",
"phoneCall",
"phoneCallHistoryPublic",
"userAccountInformation",
"voipCall",
"objects3D",
"chat",
"blockedChatMessages",
"enterpriseAuthentication",
"sharedUserCertificates",
"documentsLibrary",
]],
// Device capabilities
["device", [
"location",
"microphone",
"webcam",
"proximity",
"pointOfService",
"wiFiControl",
"radios",
"optical",
"activity",
"humanPresence",
"serialcommunication",
"gazeInput",
"lowLevel",
"packageQuery",
]],
// Mobile capabilities
["mobile", [
"recordedCallsFolder",
]],
// Restricted capabilities
["rescap", [
"enterpriseDataPolicy",
"appCaptureSettings",
"cellularDeviceControl",
"cellularDeviceIdentity",
"cellularMessaging",
"deviceUnlock",
"dualSimTiles",
"enterpriseDeviceLockdown",
"inputInjectionBrokered",
"inputObservation",
"inputSuppression",
"networkingVpnProvider",
"packageManagement",
"screenDuplication",
"userPrincipalName",
"walletSystem",
"locationHistory",
"confirmAppClose",
"phoneCallHistory",
"appointmentsSystem",
"chatSystem",
"contactsSystem",
"email",
"emailSystem",
"phoneCallHistorySystem",
"smsSend",
"userDataSystem",
"previewStore",
"firstSignInSettings",
"teamEditionExperience",
"remotePassportAuthentication",
"previewUiComposition",
"secureAssessment",
"networkConnectionManagerProvisioning",
"networkDataPlanProvisioning",
"slapiQueryLicenseValue",
"extendedBackgroundTaskTime",
"extendedExecutionBackgroundAudio",
"extendedExecutionCritical",
"extendedExecutionUnconstrained",
"deviceManagementDmAccount",
"deviceManagementFoundation",
"deviceManagementWapSecurityPolicies",
"deviceManagementEmailAccount",
"packagePolicySystem",
"gameList",
"xboxAccessoryManagement",
"cortanaSpeechAccessory",
"accessoryManager",
"interopServices",
"inputForegroundObservation",
"oemDeployment",
"oemPublicDirectory",
"appLicensing",
"locationSystem",
"userDataAccountsProvider",
"previewPenWorkspace",
"secondaryAuthenticationFactor",
"storeLicenseManagement",
"userSystemId",
"targetedContent",
"uiAutomation",
"gameBarServices",
"appCaptureServices",
"appBroadcastServices",
"audioDeviceConfiguration",
"backgroundMediaRecording",
"previewInkWorkspace",
"startScreenManagement",
"cortanaPermissions",
"allAppMods",
"expandedResources",
"protectedApp",
"gameMonitor",
"appDiagnostics",
"devicePortalProvider",
"enterpriseCloudSSO",
"backgroundVoIP",
"oneProcessVoIP",
"developmentModeNetwork",
"broadFileSystemAccess",
"smbios",
"runFullTrust",
"allowElevation",
"teamEditionDeviceCredential",
"teamEditionView",
"cameraProcessingExtension",
"networkDataUsageManagement",
"phoneLineTransportManagement",
"unvirtualizedResources",
"modifiableApp",
"packageWriteRedirectionCompatibilityShim",
"customInstallActions",
"packagedServices",
"localSystemServices",
"backgroundSpatialPerception",
"uiAccess",
]],
// UAP6 capabilities
["uap6", [
"graphicsCapture",
]],
// UAP7 capabilities
["uap7", [
"globalMediaControl",
]],
// UAP11 capabilities
["uap11", [
"graphicsCaptureWithoutBorder",
"graphicsCaptureProgrammatic",
]],
]);
// Factory function to create capabilities
function createCapability(type: CapabilityType, name: string): Capability {
const config = CAPABILITY_TYPES[type];
return new AppxCapability(config.nsAlias, config.nsURI, config.elementName, name);
}
// Export ordered list of all capabilities (order matters per Microsoft docs)
export const CAPABILITIES: Capability[] = Array.from(CAPABILITY_MAP.entries()).flatMap(
([type, names]) => names.map(name => createCapability(type, name))
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great. Sorry for the complex code I suggested. I had several iterations and ended up with that construct. Your approach is much cleaner.
| } | ||
| capabilities += "\n</Capabilities>"; | ||
| return capabilities | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't an optimized flow and can be simplified / made more performant.
export function getCapabilitiesXML(): string {
const caps = asArray(this.options.capabilities)
// Ensure runFullTrust is always included
const capSet = new Set(caps);
capSet.add("runFullTrust");
// Filter and map in one pass
const capabilityStrings = CAPABILITIES
.filter(cap => capSet.has(cap.name))
.map(cap => ` ${cap.toXMLString()}`);
return `<Capabilities>\n${capabilityStrings.join('\n')}\n</Capabilities>`;
}
Key optimizations:
- Set instead of array -
capSet.has(cap.name)is O(1) vscaps.indexOf(cap.name)which is O(n) - Single pass - Combined filter and map with chaining instead of building
stringin loop - Template literal - Cleaner string construction with
join() - Flexible input - Handles both string array and single string (matching asArray pattern)
- Immutable - Doesn't modify input array, creates new
Set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just used the code from getExtensions and modified it a little. Didn't want to break any coding conventions. But your aproach is of course much better.
| "type": "string" | ||
| }, | ||
| "capabilities": { | ||
| "description": "windows uwp capabilities", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like pnpm generate-all needs to be run again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Soryy, didn't think about that.
|
Thanks for the quick response to this pr. I will continue to work on this in the next week. |
This pull request adresses issue #9436.
It adds the optional config property
capabilitiestoAppxOptions. Docs, schema and template are modified according to that.Should be easy to take this over into the next release.