Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

feat: Control Center and lock screen controls run Like, Karaoke and the timer

My-Name-Is-Jeffa6ae15204594
diff --git a/docs/tweaks.md b/docs/tweaks.md
index d40a1502..30fa362d 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -290,8 +290,9 @@ Shared:
(extension/LiveActivity/Controls.swift), buttons, as the extension cannot read Sing's state. Each is
a LiveActivityIntent or AudioPlaybackIntent, so it runs inside Spotify, launched in the background
when needed, and LiveActivity.x answers it with the activity on or off, Like through
- HeadGestures.x's collection platform and Sing through SGSetSingOn; a sleep timer set with the
- activity off keeps a clock of its own. The intent asks again for 8 s while the player is not up,
+ HeadGestures.x's collection platform and Sing through SGSetSingOn; the sleep timer (15 min, 30 min,
+ 1 hour, End of track, End of album or Off) is the card's own, Player/SleepTimer.m, which keeps its
+ own clock with the activity off. The intent asks again for 8 s while the player is not up,
then tells Siri to open Spotify. Checked in the simulator against harness/shortcuts/
ListeningStats/ listening stats kept on the phone (ListeningStats.h lists its files): each music track timed while
diff --git a/extension/LiveActivity/Controls.swift b/extension/LiveActivity/Controls.swift
new file mode 100644
index 00000000..5070f83a
--- /dev/null
+++ b/extension/LiveActivity/Controls.swift
@@ -0,0 +1,70 @@
+// Controls for Control Center, the lock screen and the Action button (iOS 18): Like, Sing and the sleep
+// timer. Each runs one of LiveActivityShared.swift's shortcut intents, which perform inside Spotify. They are
+// buttons, not toggles: what Sing is doing lives in Spotify, and this extension shares no container with it
+// to read it from, so a toggle's on and off would be a guess.
+import AppIntents
+import SwiftUI
+import WidgetKit
+
+private let green = Color(red: 0.12, green: 0.84, blue: 0.38)
+
+@available(iOS 18.0, *)
+struct SGLikeControl: ControlWidget {
+ var body: some ControlWidgetConfiguration {
+ StaticControlConfiguration(kind: "spotifyglass.control.like") {
+ ControlWidgetButton(action: SGLikeIntent()) {
+ Label("Like This Song", systemImage: "heart")
+ .controlWidgetActionHint("Like")
+ }
+ .tint(green)
+ }
+ .displayName("Like This Song")
+ .description("Adds the song playing in Spotify to Liked Songs.")
+ }
+}
+
+@available(iOS 18.0, *)
+struct SGSingControl: ControlWidget {
+ var body: some ControlWidgetConfiguration {
+ StaticControlConfiguration(kind: "spotifyglass.control.sing") {
+ ControlWidgetButton(action: SGSingIntent(.toggle)) {
+ Label("Sing", systemImage: "music.mic")
+ .controlWidgetActionHint("Turn Sing On or Off")
+ }
+ .tint(green)
+ }
+ .displayName("Sing")
+ .description("Turns the vocals down in Spotify so you can sing along, or brings them back.")
+ }
+}
+
+// Which length the sleep timer control sets, picked when it is added.
+@available(iOS 18.0, *)
+struct SGSleepTimerControlConfiguration: ControlConfigurationIntent {
+ static let title: LocalizedStringResource = "Sleep Timer"
+ static let isDiscoverable = false
+
+ @Parameter(title: "Length", default: .thirty)
+ var length: SGSleepTimerLength
+}
+
+@available(iOS 18.0, *)
+struct SGSleepTimerControl: ControlWidget {
+ var body: some ControlWidgetConfiguration {
+ AppIntentControlConfiguration(kind: "spotifyglass.control.sleeptimer", intent: SGSleepTimerControlConfiguration.self) { configuration in
+ ControlWidgetButton(action: SGSleepTimerIntent(configuration.length)) {
+ Label {
+ Text("Sleep Timer")
+ Text(SGSleepTimerLength.caseDisplayRepresentations[configuration.length]?.title ?? "")
+ } icon: {
+ Image(systemName: "moon.zzz")
+ }
+ .controlWidgetActionHint(configuration.length == .off ? "Turn Off the Sleep Timer" : "Start the Sleep Timer")
+ }
+ .tint(green)
+ }
+ .displayName("Sleep Timer")
+ .description("Pauses Spotify after the length you pick, or at the end of the track or the album.")
+ .promptsForUserConfiguration()
+ }
+}
diff --git a/extension/LiveActivity/LiveActivityWidget.swift b/extension/LiveActivity/LiveActivityWidget.swift
index 5cf17c23..3bfc39aa 100644
--- a/extension/LiveActivity/LiveActivityWidget.swift
+++ b/extension/LiveActivity/LiveActivityWidget.swift
@@ -22,6 +22,9 @@ struct SGLiveActivityBundle: WidgetBundle {
SGLyricsLiveActivity()
if #available(iOS 18.0, *) {
SGLyricsWatchLiveActivity()
+ SGLikeControl()
+ SGSingControl()
+ SGSleepTimerControl()
}
}
}
diff --git a/harness/shortcuts/README.md b/harness/shortcuts/README.md
index 2f3b78f8..90dce29e 100644
--- a/harness/shortcuts/README.md
+++ b/harness/shortcuts/README.md
@@ -7,6 +7,7 @@ registered the same way:
- Like with the player not up for three posts: asked again every 250 ms and done on the fourth.
- Sing on refused: thrown at once, the message read out as the observer wrote it.
- Sleep timer, Next and Play or pause: each answered on the first post.
+- Sleep timer at End of album: posted as `timer:album`, the Live Activity's own action.
- Previous never answered: given up after 32 posts, about 8 s, with "Spotify isn't ready yet".
It checks that the post is made on the main thread and that the reply is a mutable dictionary the
diff --git a/harness/shortcuts/main.swift b/harness/shortcuts/main.swift
index 8ed09480..062bc59b 100644
--- a/harness/shortcuts/main.swift
+++ b/harness/shortcuts/main.swift
@@ -40,6 +40,10 @@ struct Harness {
_ = try? await SGPlayPauseIntent().perform()
check(SGHarnessPosts == 3, "timer, next and play or pause each answered first time")
+ // End of album reaches LiveActivity.x as the Live Activity's own action, which SleepTimer.h's end of album sets.
+ _ = try? await SGSleepTimerIntent(.endOfAlbum).perform()
+ check(SGHarnessLastAction == "timer:album", "end of album posts \(String(describing: SGHarnessLastAction))")
+
SGHarnessPosts = 0
let start = Date()
do {
diff --git a/harness/shortcuts/observer.h b/harness/shortcuts/observer.h
index 3f76be4f..e7210042 100644
--- a/harness/shortcuts/observer.h
+++ b/harness/shortcuts/observer.h
@@ -2,5 +2,7 @@
// How many times the stand-in was asked since the count was last reset.
extern NSInteger SGHarnessPosts;
+// The action of the last post.
+extern NSString *SGHarnessLastAction;
// Registers the stand-in, which leaves the first `waitPosts` posts unanswered and never answers previous.
void SGHarnessObserve(NSInteger waitPosts);
diff --git a/harness/shortcuts/observer.m b/harness/shortcuts/observer.m
index 1a0a4786..fd776996 100644
--- a/harness/shortcuts/observer.m
+++ b/harness/shortcuts/observer.m
@@ -4,6 +4,7 @@
#import "observer.h"
NSInteger SGHarnessPosts;
+NSString *SGHarnessLastAction;
void SGHarnessObserve(NSInteger waitPosts) {
[NSNotificationCenter.defaultCenter addObserverForName:@"SGShortcut" object:nil queue:nil usingBlock:^(NSNotification *note) {
@@ -14,6 +15,7 @@ void SGHarnessObserve(NSInteger waitPosts) {
}
NSString *action = note.object;
SGHarnessPosts++;
+ SGHarnessLastAction = action;
static NSInteger total;
// The player not up for the first posts: no answer, as runShortcut gives none without a track.
if (++total <= waitPosts ||[action isEqualToString:@"previous"]) return;
diff --git a/scripts/build-extension.sh b/scripts/build-extension.sh
index 96b4e359..83b11ff0 100755
--- a/scripts/build-extension.sh
+++ b/scripts/build-extension.sh
@@ -15,7 +15,7 @@ OUT="${2:?usage: $0 <host Info.plist> <out dir>}"
NAME=SpotifyGlassLiveActivity
APPEX="$OUT/$NAME.appex"
SHARED="$ROOT/tweak/Sources/Shared/LiveActivity/LiveActivityShared.swift"
-WIDGET="$ROOT/extension/LiveActivity/LiveActivityWidget.swift"
+WIDGET=("$ROOT/extension/LiveActivity/LiveActivityWidget.swift" "$ROOT/extension/LiveActivity/Controls.swift")
# Spotify's App Shortcuts, which only the app's metadata may carry.
SHORTCUTS="$ROOT/tweak/Sources/Shared/LiveActivity/AppShortcuts.swift"
@@ -48,8 +48,8 @@ metadata() {
echo "==> building $NAME.appex"
xcrun --sdk iphoneos swiftc -O -wmo -parse-as-library -target arm64-apple-ios17.0 -module-name "$NAME" \
- -Xlinker -e -Xlinker _NSExtensionMain -o "$APPEX/$NAME" "$SHARED" "$WIDGET"
-metadata "$NAME" 17.0 "$APPEX" "$SHARED" "$WIDGET"
+ -Xlinker -e -Xlinker _NSExtensionMain -o "$APPEX/$NAME" "$SHARED" "${WIDGET[@]}"
+metadata "$NAME" 17.0 "$APPEX" "$SHARED" "${WIDGET[@]}"
sed -e "s/HOST_BUNDLE_ID/$(plutil -extract CFBundleIdentifier raw -o - "$HOST_PLIST")/" \
-e "s/HOST_SHORT_VERSION/$(plutil -extract CFBundleShortVersionString raw -o - "$HOST_PLIST")/" \
diff --git a/tweak/Sources/Shared/LiveActivity/LiveActivityShared.swift b/tweak/Sources/Shared/LiveActivity/LiveActivityShared.swift
index abdc5a89..a7cc8c36 100644
--- a/tweak/Sources/Shared/LiveActivity/LiveActivityShared.swift
+++ b/tweak/Sources/Shared/LiveActivity/LiveActivityShared.swift
@@ -143,7 +143,7 @@ private func askSpotify(_ action: String) async throws -> String {
@available(iOS 16.0, *)
enum SGSleepTimerLength: String, AppEnum {
// The raw values are the timer action's, timer:VALUE.
- case fifteen = "15", thirty = "30", hour = "60", endOfTrack = "track", off = "cancel"
+ case fifteen = "15", thirty = "30", hour = "60", endOfTrack = "track", endOfAlbum = "album", off = "cancel"
static let typeDisplayRepresentation: TypeDisplayRepresentation = "Sleep Timer"
static let caseDisplayRepresentations: [SGSleepTimerLength: DisplayRepresentation] = [
@@ -151,6 +151,7 @@ enum SGSleepTimerLength: String, AppEnum {
.thirty: "30 Minutes",
.hour: "1 Hour",
.endOfTrack: "End of Track",
+ .endOfAlbum: "End of Album",
.off: "Off",
]
}
@@ -244,7 +245,7 @@ struct SGSingIntent: LiveActivityIntent {
@available(iOS 17.0, *)
struct SGSleepTimerIntent: LiveActivityIntent {
static let title: LocalizedStringResource = "Sleep Timer"
- static let description = IntentDescription("Pauses Spotify after a while or at the end of the track, or turns the timer off.")
+ static let description = IntentDescription("Pauses Spotify after a while or at the end of the track or the album, or turns the timer off.")
@Parameter(title: "Length")
var length: SGSleepTimerLength