| 1 | """Bundle the local development app. Distribution signing is a separate step. |
| 2 | |
| 3 | Calls keeps its own bundler rather than rastrillo/native's tools/bundle-mac.py, |
| 4 | which the other four apps use, because that one cannot yet build Calls: it |
| 5 | embeds no frameworks but Sparkle (Calls needs CallsBridge and LiveKitWebRTC, |
| 6 | with an rpath), copies no resources but Lucide's notice (Calls ships the |
| 7 | RNNoise, DeepFilterNet and WebRTC notices and the DeepFilterNet model), writes |
| 8 | no usage descriptions (camera, microphone, Continuity Camera), and draws the |
| 9 | icon as an ICNS only, where Calls compiles an Icon Composer Assets.car for |
| 10 | macOS 26. Its naming rules are followed here: works.oficina.<app>, the plain |
| 11 | name as CFBundleName, "Oficina <App>" as the file and display name, and URL |
| 12 | schemes from mac-updates.json registered under the bundle ID. |
| 13 | """ |
| 14 | import json |
| 15 | from pathlib import Path |
| 16 | import plistlib |
| 17 | import shutil |
| 18 | import subprocess |
| 19 | import sys |
| 20 | |
| 21 | configuration = sys.argv[1] if len(sys.argv) > 1 else 'debug' |
| 22 | if configuration not in ('debug', 'release'): raise ValueError('invalid build configuration') |
| 23 | root = Path(__file__).resolve().parent.parent |
| 24 | products = Path(subprocess.check_output(['swift', 'build', '--package-path', str(root / 'apple'), '--configuration', configuration, '--show-bin-path'], text=True).strip()) |
| 25 | # Finder, the Dock and Spotlight show "Oficina Calls" (the .app file name and |
| 26 | # CFBundleDisplayName), apart from every other calls app. Inside its own |
| 27 | # windows the app is plain "Calls": CFBundleName is the short name the menu bar |
| 28 | # and the About panel use. (SwiftUI titles About, Hide, Quit and Help with the |
| 29 | # display name, so CallsMac.swift declares RastrilloApple's |
| 30 | # PlainAppNameCommands to name them itself.) Same |
| 31 | # rule as rastrillo/native tools/bundle-mac.py. |
| 32 | display_name = 'Oficina Calls' |
| 33 | bundle = root / f'build/{display_name}.app/Contents' |
| 34 | if bundle.parent.exists(): shutil.rmtree(bundle.parent) |
| 35 | # Builds before the rename wrote build/Calls.app; one left behind would be |
| 36 | # opened by mistake, so it goes. |
| 37 | if (root / 'build/Calls.app').exists(): shutil.rmtree(root / 'build/Calls.app') |
| 38 | (bundle / 'MacOS').mkdir(parents=True, exist_ok=True) |
| 39 | (bundle / 'Frameworks').mkdir(parents=True, exist_ok=True) |
| 40 | (bundle / 'Resources').mkdir(parents=True, exist_ok=True) |
| 41 | shutil.copy2(products / 'CallsMac', bundle / 'MacOS/CallsMac') |
| 42 | subprocess.run(['swift', str(root / 'scripts/generate-mac-icon.swift')], check=True) |
| 43 | icon = root / 'apple/Sources/CallsMac/Resources/MacIcon.png' |
| 44 | shutil.copy2(icon, bundle / 'Resources/MacIcon.png') |
| 45 | shutil.copy2(root / 'LICENSE.lucide', bundle / 'Resources/LICENSE.lucide') |
| 46 | shutil.copy2(root / 'LICENSE.rnnoise', bundle / 'Resources/LICENSE.rnnoise') |
| 47 | shutil.copy2(root / 'LICENSE.deepfilternet', bundle / 'Resources/LICENSE.deepfilternet') |
| 48 | # The Rust crates libdf links (scripts/deepfilter-notices.py) and WebRTC's |
| 49 | # own licence, for the LiveKitWebRTC framework embedded below. |
| 50 | shutil.copy2(root / 'LICENSE.deepfilternet-crates', bundle / 'Resources/LICENSE.deepfilternet-crates') |
| 51 | shutil.copy2(root / 'LICENSE.webrtc', bundle / 'Resources/LICENSE.webrtc') |
| 52 | shutil.copy2(root / 'PATENTS.webrtc', bundle / 'Resources/PATENTS.webrtc') |
| 53 | # The Mac's noise suppressor model (scripts/build-deepfilter.sh). Without |
| 54 | # it the app falls back to RNNoise. |
| 55 | shutil.copy2(root / 'build/DeepFilterNet3_onnx.tar.gz', bundle / 'Resources/DeepFilterNet3_onnx.tar.gz') |
| 56 | # macOS 26 and later draw an app's icon from an asset catalog: full-bleed |
| 57 | # artwork that the system masks, lights and tints itself. An app with only an |
| 58 | # ICNS is legacy there, its artwork shrunk onto a plain squircle. So compile |
| 59 | # the square master (the iPhone's, which is opaque and unrounded) as an Icon |
| 60 | # Composer .icon into Assets.car, named by CFBundleIconName. actool also |
| 61 | # flattens it into renditions on the 824-point grid for macOS 14 and 15. |
| 62 | icon_package = root / 'build/AppIcon.icon' |
| 63 | if icon_package.exists(): shutil.rmtree(icon_package) |
| 64 | (icon_package / 'Assets').mkdir(parents=True) |
| 65 | shutil.copy2(root / 'ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png', icon_package / 'Assets/calls.png') |
| 66 | (icon_package / 'icon.json').write_text(json.dumps({ |
| 67 | 'fill': 'automatic', |
| 68 | 'groups': [{'layers': [{'glass': False, 'image-name': 'calls.png', 'name': 'calls'}], |
| 69 | 'shadow': {'kind': 'neutral', 'opacity': 0.5}, |
| 70 | 'translucency': {'enabled': False, 'value': 0}}], |
| 71 | 'supported-platforms': {'squares': ['macOS']}, |
| 72 | }, indent=2)) |
| 73 | catalog = root / 'build/AssetCatalog' |
| 74 | if catalog.exists(): shutil.rmtree(catalog) |
| 75 | catalog.mkdir(parents=True) |
| 76 | subprocess.run(['xcrun', 'actool', str(icon_package), '--compile', str(catalog), |
| 77 | '--platform', 'macosx', '--minimum-deployment-target', '14.0', |
| 78 | '--app-icon', 'AppIcon', '--output-partial-info-plist', str(catalog / 'partial.plist'), |
| 79 | '--errors', '--warnings'], check=True, stdout=subprocess.DEVNULL) |
| 80 | if not (catalog / 'Assets.car').exists(): |
| 81 | raise SystemExit('actool wrote no Assets.car: an Xcode that compiles .icon (26 or later) is required') |
| 82 | shutil.copy2(catalog / 'Assets.car', bundle / 'Resources/Assets.car') |
| 83 | # The ICNS stays as CFBundleIconFile for anything that reads only that key. |
| 84 | # The PNG is the Dock icon for a run outside a bundle (CallsMac.swift). |
| 85 | iconset = root / 'build/AppIcon.iconset' |
| 86 | iconset.mkdir(parents=True, exist_ok=True) |
| 87 | for size in (16, 32, 128, 256, 512): |
| 88 | for scale in (1, 2): |
| 89 | name = f'icon_{size}x{size}' + ('@2x' if scale == 2 else '') + '.png' |
| 90 | subprocess.run(['sips', '-z', str(size * scale), str(size * scale), |
| 91 | str(icon), '--out', str(iconset / name)], |
| 92 | check=True, stdout=subprocess.DEVNULL) |
| 93 | subprocess.run(['iconutil', '-c', 'icns', str(iconset), '-o', |
| 94 | str(bundle / 'Resources/CallsMac.icns')], check=True) |
| 95 | # The app's URL schemes are declared once, in mac-updates.json, as the shared |
| 96 | # bundler reads them (rastrillo/native tools/bundle-mac.py), and registered |
| 97 | # under the bundle ID as their name, as it registers them. |
| 98 | updates = json.loads((root / 'mac-updates.json').read_text()) |
| 99 | info = { |
| 100 | 'CFBundleURLTypes': [{'CFBundleURLName': updates['bundle_id'], |
| 101 | 'CFBundleURLSchemes': updates['url_schemes']}], |
| 102 | 'CFBundleName': 'Calls', 'CFBundleDisplayName': display_name, |
| 103 | # Sparkle names the app from SUBundleName, then CFBundleDisplayName |
| 104 | # (SUHost.m), so without this its windows would say "Oficina Calls is now |
| 105 | # updated" in an app whose menu is Calls. Its installer still finds the |
| 106 | # update by file name or bundle ID first (SUInstaller.m), so the plain name |
| 107 | # changes no lookup. As rastrillo/native tools/bundle-mac.py writes it. |
| 108 | 'SUBundleName': 'Calls', |
| 109 | # Paul, 2026-11-14: every Oficina build, Sparkle and App Store, Mac and |
| 110 | # iPhone, is works.oficina.<app>: here works.oficina.calls, read from |
| 111 | # mac-updates.json so the two cannot disagree (mac_updates.py refuses a |
| 112 | # release whose Info.plist names another app). |
| 113 | 'CFBundleIdentifier': updates['bundle_id'], |
| 114 | 'CFBundleExecutable': 'CallsMac', 'CFBundlePackageType': 'APPL', |
| 115 | 'CFBundleIconFile': 'CallsMac.icns', 'CFBundleIconName': 'AppIcon', |
| 116 | 'CFBundleShortVersionString': '0.1.0', 'CFBundleVersion': '1', |
| 117 | 'LSMinimumSystemVersion': '14.0', 'NSHighResolutionCapable': True, |
| 118 | 'NSCameraUseContinuityCameraDeviceType': True, |
| 119 | 'NSCameraUsageDescription': 'Calls uses your camera to share video in a meeting.', |
| 120 | 'NSMicrophoneUsageDescription': 'Calls uses your microphone so people in the meeting can hear you.', |
| 121 | } |
| 122 | (bundle / 'Info.plist').write_bytes(plistlib.dumps(info)) |
| 123 | # SwiftPM links dynamic binary dependencies using @rpath. Embed just the macOS |
| 124 | # slice rather than shipping iOS and simulator frameworks inside the Mac app. |
| 125 | for xc in [root / 'build/CallsBridge.xcframework', *list((root / 'apple/.build/artifacts').rglob('LiveKitWebRTC.xcframework'))]: |
| 126 | manifest = plistlib.loads((xc / 'Info.plist').read_bytes()) |
| 127 | for lib in manifest['AvailableLibraries']: |
| 128 | if lib['SupportedPlatform'] != 'macos': |
| 129 | continue |
| 130 | source = xc / lib['LibraryIdentifier'] / lib['LibraryPath'] |
| 131 | binary = source / source.stem |
| 132 | if 'dynamically linked' not in subprocess.check_output(['file', str(binary)], text=True): |
| 133 | continue |
| 134 | dest = bundle / 'Frameworks' / source.name |
| 135 | if dest.exists(): shutil.rmtree(dest) |
| 136 | shutil.copytree(source, dest, symlinks=True) |
| 137 | for resource in products.glob('*.bundle'): |
| 138 | shutil.copytree(resource, bundle / 'Resources' / resource.name, symlinks=True) |
| 139 | subprocess.run(['install_name_tool', '-add_rpath', '@executable_path/../Frameworks', str(bundle / 'MacOS/CallsMac')], check=True) |
| 140 | |