1.0.2: visualizer level scale, AppIntents metadata for widget buttons

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-10-27 21:57:50 -05:00
commit b9f9c81a3e
7 changed files with 153 additions and 31 deletions

View file

@ -82,7 +82,7 @@ final class Spectrum {
for i in 0..<frames {
var v: Float = 0
for c in ch { v += c[i * stride] }
ring[ringPos] = v / chans * 32768
ring[ringPos] = v / chans // -1…1 like Android (short / 32768)
ringPos = (ringPos + 1) & (Spectrum.n - 1)
}
let now = CFAbsoluteTimeGetCurrent()

View file

@ -61,36 +61,61 @@ struct NowSnapshot: Codable, Equatable {
}
}
// MARK: Widget buttons (iOS 17 interactive widgets). AudioPlaybackIntent runs in the app's process.
// MARK: Widget buttons (iOS 17 interactive widgets)
// One parameterless AudioPlaybackIntent per button, like FlacBox. AudioPlaybackIntent runs in the app's process.
// build.sh generates Metadata.appintents for these (tools/gen-appintents.py); without it iOS drops the widget.
enum MulberryCommand: String, AppEnum {
enum MulberryCommand: String {
case toggle, next, previous, shuffle, repeatMode, favourite
static var typeDisplayRepresentation: TypeDisplayRepresentation { "Mulberry command" }
static var caseDisplayRepresentations: [MulberryCommand: DisplayRepresentation] {
[.toggle: "Play/Pause", .next: "Next", .previous: "Previous", .shuffle: "Shuffle", .repeatMode: "Repeat",
.favourite: "Favourite"]
}
}
@available(iOS 17.0, *)
struct MulberryControlIntent: AudioPlaybackIntent {
static var title: LocalizedStringResource = "Control Mulberry"
static var isDiscoverable = false
@Parameter(title: "Command") var command: MulberryCommand
init() { command = .toggle }
init(_ c: MulberryCommand) { command = c }
func perform() async throws -> 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() }
}

View file

@ -1 +1 @@
1.0.1
1.0.2

View file

@ -95,15 +95,15 @@ struct CoverCookie: View {
}
}
struct CtlButton: View {
let cmd: MulberryCommand
struct CtlButton<I: AppIntent>: 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)

View file

@ -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

11
docs/releases/1.0.2.md Normal file
View file

@ -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.

84
tools/gen-appintents.py Normal file
View file

@ -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 <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"),
]
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}")