Files
DockDoor/CrossSoundPlugin.swift
2026-09-17 22:14:07 -07:00

69 lines
2.7 KiB
Swift

import DockDoorWidgetSDK
import SwiftUI
/// Dock widget for the CrossSound desktop app.
///
/// CrossSound runs a small HTTP API on the loopback interface for its companion
/// integrations (the Stream Deck plugin on 52124, the Game Bar widget on 8963).
/// This widget is another client of that same API: it reads now-playing state,
/// and posts transport commands back. Nothing here talks to SoundCloud directly
/// — CrossSound owns the account, the tokens and the playback.
final class CrossSoundPlugin: WidgetPlugin, DockDoorWidgetProvider {
var id: String { "crosssound" }
var name: String { "CrossSound" }
var iconSymbol: String { "music.note" }
var widgetDescription: String { "Now playing, playlists and Discover from the CrossSound desktop app" }
var supportedOrientations: [WidgetOrientation] { [.horizontal, .vertical] }
private let client = CrossSoundClient(widgetId: "crosssound")
func settingsSchema() -> [WidgetSetting] {
[
.picker(
key: "dockText",
label: "Dock Text",
options: [CrossSoundDockText.titleAndArtist.rawValue,
CrossSoundDockText.titleOnly.rawValue,
CrossSoundDockText.hidden.rawValue],
defaultValue: CrossSoundDockText.titleAndArtist.rawValue
),
.toggle(key: "showArtwork", label: "Show Album Art in the Dock", defaultValue: true),
.toggle(key: "showHeart", label: "Show Heart When Liked", defaultValue: true),
.textField(
key: "port",
label: "API Port (blank = auto)",
placeholder: "52124",
defaultValue: ""
),
]
}
@MainActor
func makeBody(size: CGSize, isVertical: Bool) -> AnyView {
AnyView(CrossSoundWidgetView(size: size, isVertical: isVertical, pluginId: id, client: client))
}
@MainActor
func makePanelBody(dismiss: @escaping () -> Void) -> AnyView? {
AnyView(CrossSoundPanel(client: client, dismiss: dismiss))
}
/// Clicking the dock slot toggles playback — the one action worth having
/// without opening the panel.
func performTapAction() {
client.playPause()
}
}
/// What the extended dock layout prints next to the artwork.
enum CrossSoundDockText: String {
case titleAndArtist = "Title and Artist"
case titleOnly = "Title Only"
case hidden = "None"
static func current(pluginId: String) -> CrossSoundDockText {
let raw = WidgetDefaults.string(key: "dockText", widgetId: pluginId, default: titleAndArtist.rawValue)
return CrossSoundDockText(rawValue: raw) ?? .titleAndArtist
}
}