diff --git a/App/Audio/Spectrum.swift b/App/Audio/Spectrum.swift index c2ae972..c6bc3d8 100644 --- a/App/Audio/Spectrum.swift +++ b/App/Audio/Spectrum.swift @@ -82,7 +82,7 @@ final class Spectrum { for i in 0.. some IntentResult { - let c = command - await MainActor.run { IntentRouter.handler?(c) } - return .result() - } } /// The app installs a handler at launch; inside the widget extension it stays nil. enum IntentRouter { @MainActor static var handler: ((MulberryCommand) -> Void)? + + static func run(_ c: MulberryCommand) async { + await MainActor.run { IntentRouter.handler?(c) } + } +} + +@available(iOS 17.0, *) +struct PlayPauseIntent: AudioPlaybackIntent { + static var title: LocalizedStringResource = "Play or pause" + init() {} + func perform() async throws -> some IntentResult { await IntentRouter.run(.toggle); return .result() } +} + +@available(iOS 17.0, *) +struct NextTrackIntent: AudioPlaybackIntent { + static var title: LocalizedStringResource = "Next track" + init() {} + func perform() async throws -> some IntentResult { await IntentRouter.run(.next); return .result() } +} + +@available(iOS 17.0, *) +struct PreviousTrackIntent: AudioPlaybackIntent { + static var title: LocalizedStringResource = "Previous track" + init() {} + func perform() async throws -> some IntentResult { await IntentRouter.run(.previous); return .result() } +} + +@available(iOS 17.0, *) +struct ShuffleIntent: AudioPlaybackIntent { + static var title: LocalizedStringResource = "Shuffle" + init() {} + func perform() async throws -> some IntentResult { await IntentRouter.run(.shuffle); return .result() } +} + +@available(iOS 17.0, *) +struct RepeatIntent: AudioPlaybackIntent { + static var title: LocalizedStringResource = "Repeat" + init() {} + func perform() async throws -> some IntentResult { await IntentRouter.run(.repeatMode); return .result() } +} + +@available(iOS 17.0, *) +struct FavouriteIntent: AudioPlaybackIntent { + static var title: LocalizedStringResource = "Favourite" + init() {} + func perform() async throws -> some IntentResult { await IntentRouter.run(.favourite); return .result() } } diff --git a/VERSION b/VERSION index 7dea76e..6d7de6e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.1 +1.0.2 diff --git a/Widget/MulberryWidgets.swift b/Widget/MulberryWidgets.swift index 417f098..a4d89da 100644 --- a/Widget/MulberryWidgets.swift +++ b/Widget/MulberryWidgets.swift @@ -95,15 +95,15 @@ struct CoverCookie: View { } } -struct CtlButton: View { - let cmd: MulberryCommand +struct CtlButton: View { + let intent: I let icon: String let size: CGFloat let fg: Color let bg: Color var wide = false var body: some View { - Button(intent: MulberryControlIntent(cmd)) { + Button(intent: intent) { Image(systemName: icon) .font(.system(size: size * 0.4, weight: .bold)) .foregroundColor(fg) @@ -120,12 +120,12 @@ struct Controls: View { var size: CGFloat = 34 var body: some View { HStack(spacing: 8) { - CtlButton(cmd: .shuffle, icon: "shuffle", size: size, fg: s.shuffle ? col.onPrimaryC : col.onSurfaceVar, + CtlButton(intent: ShuffleIntent(), icon: "shuffle", size: size, fg: s.shuffle ? col.onPrimaryC : col.onSurfaceVar, bg: s.shuffle ? col.primaryC : col.surfaceHigh) - CtlButton(cmd: .previous, icon: "backward.end.fill", size: size, fg: col.onSecondaryC, bg: col.secondaryC) - CtlButton(cmd: .toggle, icon: s.playing ? "pause.fill" : "play.fill", size: size, fg: col.onPrimary, bg: col.primary, wide: true) - CtlButton(cmd: .next, icon: "forward.end.fill", size: size, fg: col.onSecondaryC, bg: col.secondaryC) - CtlButton(cmd: .repeatMode, icon: s.repeatMode == 2 ? "repeat.1" : "repeat", size: size, + CtlButton(intent: PreviousTrackIntent(), icon: "backward.end.fill", size: size, fg: col.onSecondaryC, bg: col.secondaryC) + CtlButton(intent: PlayPauseIntent(), icon: s.playing ? "pause.fill" : "play.fill", size: size, fg: col.onPrimary, bg: col.primary, wide: true) + CtlButton(intent: NextTrackIntent(), icon: "forward.end.fill", size: size, fg: col.onSecondaryC, bg: col.secondaryC) + CtlButton(intent: RepeatIntent(), icon: s.repeatMode == 2 ? "repeat.1" : "repeat", size: size, fg: s.repeatMode > 0 ? col.onPrimaryC : col.onSurfaceVar, bg: s.repeatMode > 0 ? col.primaryC : col.surfaceHigh) } } @@ -202,7 +202,7 @@ struct PlayerWidgetView: View { HStack(alignment: .top) { CoverCookie(art: e.art, colors: col).frame(width: 64, height: 64) Spacer() - CtlButton(cmd: .toggle, icon: s.playing ? "pause.fill" : "play.fill", size: 40, fg: col.onPrimary, bg: col.primary) + CtlButton(intent: PlayPauseIntent(), icon: s.playing ? "pause.fill" : "play.fill", size: 40, fg: col.onPrimary, bg: col.primary) } Spacer(minLength: 0) titles(s, col) diff --git a/build.sh b/build.sh index 89cc349..7fe438f 100755 --- a/build.sh +++ b/build.sh @@ -81,6 +81,8 @@ sed -e "s/@VERSION@/$VERSION/" -e "s/@BUILD@/$BUILD/" Resources/Info.plist > "$A sed -e "s/@VERSION@/$VERSION/" -e "s/@BUILD@/$BUILD/" Resources/Widget-Info.plist > "$APPEX/Info.plist" cp Resources/AppIcon*.png "$APP/" printf 'APPL????' > "$APP/PkgInfo" +python3 tools/gen-appintents.py Mulberry "$APP" +python3 tools/gen-appintents.py MulberryWidgets "$APPEX" echo "== sign" if command -v ldid >/dev/null; then diff --git a/docs/releases/1.0.2.md b/docs/releases/1.0.2.md new file mode 100644 index 0000000..da2cd70 --- /dev/null +++ b/docs/releases/1.0.2.md @@ -0,0 +1,11 @@ +# Mulberry for iOS 1.0.2 + +## Fixes +- Visualizer: levels were ~90 dB too hot (samples scaled ×32768 instead of −1…1), so every bar sat at maximum and the + bass shape never saw a beat. It now matches the Android app. +- Player widget: its buttons now ship the AppIntents metadata iOS needs; without it iOS dropped the widget + (the Lyrics and Lock Screen widgets already registered in 1.0.1). +- Widget buttons are separate Play/Pause, Next, Previous, Shuffle and Repeat actions, like FlacBox. + +## Removed +- The diagnostic "Mulberry test" widget. diff --git a/tools/gen-appintents.py b/tools/gen-appintents.py new file mode 100644 index 0000000..8a71074 --- /dev/null +++ b/tools/gen-appintents.py @@ -0,0 +1,84 @@ +"""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 """ +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"), +] + + +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}")