Mulberry/ios/tools/gen-appintents.py
astar76 fd04376c75 Add Mulberry for iOS (1.0.6) under ios/
SwiftUI port of the Android app with the desktop feature set; built on Linux,
linked and signed on a jailbroken iPhone. History imported from the standalone repo.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-27 23:23:51 -05:00

86 lines
3.2 KiB
Python

"""Writes Metadata.appintents (what Xcode's appintentsmetadataprocessor produces) for Mulberry's widget intents.
Without it iOS can't resolve Button(intent:) and silently drops widgets that use them.
Layout copied from a working Xcode-built music widget (FlacBox): parameterless AudioPlaybackIntents.
Usage: gen-appintents.py <swift module name> <bundle dir>"""
import json
import os
import sys
module, bundle = sys.argv[1], sys.argv[2]
# (Swift type, title) — must match Shared/WidgetShared.swift
INTENTS = [
("PlayPauseIntent", "Play or pause"),
("NextTrackIntent", "Next track"),
("PreviousTrackIntent", "Previous track"),
("ShuffleIntent", "Shuffle"),
("RepeatIntent", "Repeat"),
("FavouriteIntent", "Favourite"),
("SkipBackIntent", "Back 10 seconds"),
("SkipForwardIntent", "Forward 10 seconds"),
]
def mangled(name):
return f"{len(module)}{module}{len(name)}{name}V"
def action(name, title):
protocol = "com.apple.link.systemProtocol.AudioStarting" # AudioPlaybackIntent
return {
"assistantDefinedSchemaTraits": [],
"assistantDefinedSchemas": [],
"authenticationPolicy": 0,
"availabilityAnnotations": {
"LNPlatformNameIOS": {"introducedVersion": "17.0"},
"LNPlatformNameMACOS": {"introducedVersion": "14.0"},
"LNPlatformNameTVOS": {"introducedVersion": "17.0"},
"LNPlatformNameWATCHOS": {"introducedVersion": "10.0"},
"LNPlatformNameWildcard": {"introducedVersion": "*"},
},
"effectiveBundleIdentifiers": [],
"fullyQualifiedTypeName": f"{module}.{name}",
"identifier": name,
"isAuthPolExplicit": False,
"isDiscoverable": True,
"mangledTypeName": mangled(name),
"mangledTypeNameByBundleIdentifier": {},
"mangledTypeNameByBundleIdentifierV2": {},
"mangledTypeNameV2": mangled(name),
"openAppWhenRun": False,
"outputFlags": 0,
"parameters": [],
"presentationStyle": 0,
"requiredCapabilities": [],
"supportedModes": 1,
"systemProtocolMetadata": [protocol, {"empty": {}}],
"systemProtocolMetadataV2": [protocol, {"empty": {}}],
"systemProtocols": [protocol],
"title": {"alternatives": [], "key": title},
"typeSpecificMetadata": [],
"visibilityMetadata": {"assistantOnly": False, "isDiscoverable": True},
}
data = {
"actions": {name: action(name, title) for name, title in INTENTS},
"assistantEntities": [],
"assistantIntentNegativePhrases": [],
"assistantIntents": [],
"autoShortcuts": [],
"entities": [],
"enums": [],
"generator": {"name": "xcode-tools", "version": "16F6"},
"negativePhrases": [],
"queries": [],
"shortcutTileColor": 14,
"version": 1,
}
out = os.path.join(bundle, "Metadata.appintents")
os.makedirs(out, exist_ok=True)
with open(os.path.join(out, "extract.actionsdata"), "w") as f:
json.dump(data, f, separators=(",", ":"), sort_keys=True)
with open(os.path.join(out, "version.json"), "w") as f:
json.dump({"toolsVersion": "16F6", "version": "3.0"}, f, indent=2)
print(f"{out}: {len(INTENTS)} intents for module {module}")