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

fix: the Lyrics Source submenu lists the sources at once and fits without scrolling

My-Name-Is-Jefff2858cf56e55
diff --git a/tweak/Sources/Redesigned/Player/PlayerMenu.m b/tweak/Sources/Redesigned/Player/PlayerMenu.m
index 6560f1e6..fa9dc830 100644
--- a/tweak/Sources/Redesigned/Player/PlayerMenu.m
+++ b/tweak/Sources/Redesigned/Player/PlayerMenu.m
@@ -8,7 +8,7 @@
// a button for each of the two the background is not, while it is one of the
// three, named for what it switches to
// Lyrics Source a song's lyrics from another source than the one the order chose (issue #67): its
-// items are the sources with lines for the song, asked only once the submenu opens
+// items are the sources with lines for the song so far, asked as the ⋯ opens
//
// The item says under its name what is not as Spotify plays it, so the menu reads as a settings summary.
#import "Core/SGCore.h"
@@ -55,21 +55,13 @@ static UIAction *soundMenu(void) {
return open;
}
-// How long the submenu shows its loading row for the slowest sources before it lists the ones that answered.
-static const NSTimeInterval kOffersWait = 4;
static NSString *sheetKind(void);
-static NSString *timingText(NSArray<SGKaraokeLine *> *lines) {
- switch (SGKaraokeLinesTiming(lines)) {
- case SGKaraokeTimingWords: return @"Word by word";
- case SGKaraokeTimingLine: return @"Line by line";
- default: return @"Not synced";
- }
-}
-
// Automatic, checked while nothing is picked and naming what the order chose, then the sources with lines for
-// the track, in the order, the one picked checked.
-static NSArray<UIMenuElement *> *sourceItems(NSString *track, NSDictionary<NSString *, SGLyricsResult *> *offers) {
+// the track, in the order, the one picked checked, and the ones still asked named in a row of their own. The
+// sources' rows are one line each, so the list fits without scrolling: a scrolled list runs under the
+// submenu's title.
+static NSArray<UIMenuElement *> *sourceItems(NSString *track, NSDictionary<NSString *, SGLyricsResult *> *offers, NSArray<NSString *> *asking) {
NSString *current = SGLyricsChosenSource(track);
UIAction *automatic = [UIAction actionWithTitle:@"Automatic" image:nil identifier:nil
handler:^(UIAction *action) { SGLyricsChooseAutomatic(track); }];
@@ -82,11 +74,17 @@ static NSArray<UIMenuElement *> *sourceItems(NSString *track, NSDictionary<NSStr
SGLyricsProvider *provider = SGLyricsProviderFor(key);
UIAction *pick = [UIAction actionWithTitle:provider.name image:nil identifier:nil
handler:^(UIAction *action) { SGLyricsChooseSource(track, key); }];
- pick.subtitle = timingText(offer.karaokeLines);
pick.state = [key isEqualToString:current] ? UIMenuElementStateOn : UIMenuElementStateOff;
[items addObject:pick];
}
- if (items.count == 1) {
+ if (asking.count) {
+ NSMutableArray<NSString *> *names = [NSMutableArray array];
+ for (NSString *key in SGLyricsOrder()) if ([asking containsObject:key]) [names addObject:SGLyricsProviderFor(key).name];
+ UIAction *waiting = [UIAction actionWithTitle:@"Still Asking" image:nil identifier:nil handler:^(UIAction *action) {}];
+ waiting.subtitle = [names componentsJoinedByString:@", "];
+ waiting.attributes = UIMenuElementAttributesDisabled;
+ [items addObject:waiting];
+ } else if (items.count == 1) {
UIAction *none = [UIAction actionWithTitle:@"No Source Has Lyrics" image:nil identifier:nil handler:^(UIAction *action) {}];
none.attributes = UIMenuElementAttributesDisabled;
[items addObject:none];
@@ -97,10 +95,14 @@ static NSArray<UIMenuElement *> *sourceItems(NSString *track, NSDictionary<NSStr
static UIMenu *lyricsSourceMenu(void) {
NSString *track = SGKaraokePlayingTrack();
if (!SGLyricsEnabled() || !track.length || [sheetKind() isEqualToString:@"episode"]) return nil;
+ // The sources are asked as the ⋯ opens, and the submenu lists what has answered by the time it opens,
+ // at once: a loading row swapped for the items changes its size under the finger, which clips it. A
+ // source still out is named, and shows the next time.
+ SGLyricsOffersSoFar(track, NULL);
UIDeferredMenuElement *sources = [UIDeferredMenuElement elementWithUncachedProvider:^(void (^completion)(NSArray<UIMenuElement *> *)) {
- SGLyricsOffers(track, kOffersWait, ^(NSDictionary<NSString *, SGLyricsResult *> *offers) {
- completion(sourceItems(track, offers));
- });
+ NSArray<NSString *> *asking = nil;
+ NSDictionary<NSString *, SGLyricsResult *> *offers = SGLyricsOffersSoFar(track, &asking);
+ completion(sourceItems(track, offers, asking));
}];
UIMenu *menu = [UIMenu menuWithTitle:@"Lyrics Source" image:symbol(@"quote.bubble") identifier:nil options:0 children:@[sources]];
menu.subtitle = SGLyricsCreditFor(track);
diff --git a/tweak/Sources/Shared/LyricsSources/LyricsPick.m b/tweak/Sources/Shared/LyricsSources/LyricsPick.m
index f6ea33c3..94116bd4 100644
--- a/tweak/Sources/Shared/LyricsSources/LyricsPick.m
+++ b/tweak/Sources/Shared/LyricsSources/LyricsPick.m
@@ -92,7 +92,8 @@ static void askMissing(SGLyricsOfferAsk *ask) {
}
}
-void SGLyricsOffers(NSString *trackID, NSTimeInterval wait, void (^done)(NSDictionary<NSString *, SGLyricsResult *> *offers)) {
+// The track's ask, made if new, with every source missing an answer asked.
+static SGLyricsOfferAsk *askFor(NSString *trackID) {
if (!sg_asks) sg_asks = [NSMutableDictionary dictionary];
SGLyricsOfferAsk *ask = sg_asks[trackID];
if (!ask) {
@@ -104,6 +105,17 @@ void SGLyricsOffers(NSString *trackID, NSTimeInterval wait, void (^done)(NSDicti
ask.waiting = [NSMutableArray array];
}
askMissing(ask);
+ return ask;
+}
+
+NSDictionary<NSString *, SGLyricsResult *> *SGLyricsOffersSoFar(NSString *trackID, NSArray<NSString *> **asking) {
+ SGLyricsOfferAsk *ask = askFor(trackID);
+ if (asking) *asking = ask.asking.allObjects;
+ return offersIn(ask);
+}
+
+void SGLyricsOffers(NSString *trackID, NSTimeInterval wait, void (^done)(NSDictionary<NSString *, SGLyricsResult *> *offers)) {
+ SGLyricsOfferAsk *ask = askFor(trackID);
__block BOOL called = NO;
void (^once)(void) = ^{
if (called) return;
diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSources.h b/tweak/Sources/Shared/LyricsSources/LyricsSources.h
index fde10123..4fa3b3df 100644
--- a/tweak/Sources/Shared/LyricsSources/LyricsSources.h
+++ b/tweak/Sources/Shared/LyricsSources/LyricsSources.h
@@ -243,6 +243,8 @@ NSString *SGLyricsChosenSource(NSString *trackID);
// Every source in the order is asked for the track at once, the answers kept for the last few tracks, and
// `done` gets the ones with lines, by key, when all have answered or `wait` has passed.
void SGLyricsOffers(NSString *trackID, NSTimeInterval wait, void (^done)(NSDictionary<NSString *, SGLyricsResult *> *offers));
+// The same asks, answered at once: the sources with lines so far, and in `asking` the keys still out.
+NSDictionary<NSString *, SGLyricsResult *> *SGLyricsOffersSoFar(NSString *trackID, NSArray<NSString *> **asking);
// Makes the offer of `key` the track's lyrics now, everywhere they show, and posts
// SGLyricsSourceChosenNotification (object the track's id) once its lines are kept.
void SGLyricsChooseSource(NSString *trackID, NSString *key);