electrobun 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electrobun",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Build ultra fast, tiny, and cross-platform desktop apps with Typescript.",
5
5
  "license": "MIT",
6
6
  "author": "Blackboard Technologies Inc.",
package/src/cli/index.ts CHANGED
@@ -564,6 +564,55 @@ const defaultConfig = {
564
564
  },
565
565
  };
566
566
 
567
+ // Mapping of entitlements to their corresponding Info.plist usage description keys
568
+ const ENTITLEMENT_TO_PLIST_KEY: Record<string, string> = {
569
+ "com.apple.security.device.camera": "NSCameraUsageDescription",
570
+ "com.apple.security.device.microphone": "NSMicrophoneUsageDescription",
571
+ "com.apple.security.device.audio-input": "NSMicrophoneUsageDescription",
572
+ "com.apple.security.personal-information.location": "NSLocationUsageDescription",
573
+ "com.apple.security.personal-information.location-when-in-use": "NSLocationWhenInUseUsageDescription",
574
+ "com.apple.security.personal-information.contacts": "NSContactsUsageDescription",
575
+ "com.apple.security.personal-information.calendars": "NSCalendarsUsageDescription",
576
+ "com.apple.security.personal-information.reminders": "NSRemindersUsageDescription",
577
+ "com.apple.security.personal-information.photos-library": "NSPhotoLibraryUsageDescription",
578
+ "com.apple.security.personal-information.apple-music-library": "NSAppleMusicUsageDescription",
579
+ "com.apple.security.personal-information.motion": "NSMotionUsageDescription",
580
+ "com.apple.security.personal-information.speech-recognition": "NSSpeechRecognitionUsageDescription",
581
+ "com.apple.security.device.bluetooth": "NSBluetoothAlwaysUsageDescription",
582
+ "com.apple.security.files.user-selected.read-write": "NSDocumentsFolderUsageDescription",
583
+ "com.apple.security.files.downloads.read-write": "NSDownloadsFolderUsageDescription",
584
+ "com.apple.security.files.desktop.read-write": "NSDesktopFolderUsageDescription",
585
+ };
586
+
587
+ // Helper function to escape XML special characters
588
+ function escapeXml(str: string): string {
589
+ return str
590
+ .replace(/&/g, '&amp;')
591
+ .replace(/</g, '&lt;')
592
+ .replace(/>/g, '&gt;')
593
+ .replace(/"/g, '&quot;')
594
+ .replace(/'/g, '&apos;');
595
+ }
596
+
597
+ // Helper function to generate usage description entries for Info.plist
598
+ function generateUsageDescriptions(entitlements: Record<string, boolean | string>): string {
599
+ const usageEntries: string[] = [];
600
+
601
+ for (const [entitlement, value] of Object.entries(entitlements)) {
602
+ const plistKey = ENTITLEMENT_TO_PLIST_KEY[entitlement];
603
+ if (plistKey && value) {
604
+ // Use the string value as description, or a default if it's just true
605
+ const description = typeof value === "string"
606
+ ? escapeXml(value)
607
+ : `This app requires access for ${entitlement.split('.').pop()?.replace('-', ' ')}`;
608
+
609
+ usageEntries.push(` <key>${plistKey}</key>\n <string>${description}</string>`);
610
+ }
611
+ }
612
+
613
+ return usageEntries.join('\n');
614
+ }
615
+
567
616
  const command = commandDefaults[commandArg];
568
617
 
569
618
  if (!command) {
@@ -1001,6 +1050,9 @@ if (commandArg === "init") {
1001
1050
 
1002
1051
  // We likely want to let users configure this for different environments (eg: dev, canary, stable) and/or
1003
1052
  // provide methods to help segment data in those folders based on channel/environment
1053
+ // Generate usage descriptions from entitlements
1054
+ const usageDescriptions = generateUsageDescriptions(config.build.mac.entitlements || {});
1055
+
1004
1056
  const InfoPlistContents = `<?xml version="1.0" encoding="UTF-8"?>
1005
1057
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
1006
1058
  <plist version="1.0">
@@ -1016,7 +1068,7 @@ if (commandArg === "init") {
1016
1068
  <key>CFBundlePackageType</key>
1017
1069
  <string>APPL</string>
1018
1070
  <key>CFBundleIconFile</key>
1019
- <string>AppIcon</string>
1071
+ <string>AppIcon</string>${usageDescriptions ? '\n' + usageDescriptions : ''}
1020
1072
  </dict>
1021
1073
  </plist>`;
1022
1074
 
@@ -2101,7 +2153,7 @@ async function getConfig() {
2101
2153
  };
2102
2154
  }
2103
2155
 
2104
- function buildEntitlementsFile(entitlements) {
2156
+ function buildEntitlementsFile(entitlements: Record<string, boolean | string>) {
2105
2157
  return `<?xml version="1.0" encoding="UTF-8"?>
2106
2158
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
2107
2159
  <plist version="1.0">
@@ -2120,7 +2172,8 @@ function getEntitlementValue(value: boolean | string) {
2120
2172
  if (typeof value === "boolean") {
2121
2173
  return `<${value.toString()}/>`;
2122
2174
  } else {
2123
- return value;
2175
+ // For string values (usage descriptions), still return boolean true for the entitlement
2176
+ return `<true/>`;
2124
2177
  }
2125
2178
  }
2126
2179
 
@@ -17,6 +17,10 @@ export default {
17
17
  },
18
18
  mac: {
19
19
  bundleCEF: false,
20
+ codesign: true,
21
+ entitlements: {
22
+ "com.apple.security.device.camera": "This app needs camera access to take photos for your photo booth",
23
+ },
20
24
  },
21
25
  linux: {
22
26
  bundleCEF: true,
@@ -5,6 +5,7 @@
5
5
  "scripts": {
6
6
  "dev": "electrobun dev",
7
7
  "build:dev": "electrobun build",
8
+ "build:canary": "electrobun build --env=canary",
8
9
  "start": "bun run build:dev && bun run dev"
9
10
  },
10
11
  "dependencies": {