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: Lyrics Source opens a panel that lists each source as it answers

My-Name-Is-Jeff60f6db199ec1
diff --git a/tweak/Sources/Redesigned/Player/PlayerMenu.m b/tweak/Sources/Redesigned/Player/PlayerMenu.m
index fa9dc830..574e441d 100644
--- a/tweak/Sources/Redesigned/Player/PlayerMenu.m
+++ b/tweak/Sources/Redesigned/Player/PlayerMenu.m
@@ -7,8 +7,8 @@
// Show Fluid Artwork, Show Animated Artwork, Show Visualizer
// 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 so far, asked as the ⋯ opens
+// Lyrics Source a song's lyrics from another source than the one the order chose (issue #67), in a
+// popover from the ⋯ that asks every source and lists each as it answers
//
// 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"
@@ -17,9 +17,10 @@
#import "Shared/Player/SpeedPitch.h"
#import "Shared/Lyrics/Lyrics.h"
#import "Shared/LyricsSources/LyricsSources.h"
+#import "Settings/SGPageStyle.h"
#import "Player.h"
-static __weak UIView *sg_moreButton; // the ⋯ the sliders' panel comes from
+static __weak UIView *sg_moreButton; // the ⋯ the panels come from
static UIImage *symbol(NSString *name) {
return [UIImage systemImageNamed:name];
@@ -57,56 +58,148 @@ static UIAction *soundMenu(void) {
static NSString *sheetKind(void);
-// 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, 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); }];
- automatic.subtitle = current ? @"As the order chooses" : SGLyricsCreditFor(track);
- automatic.state = current ? UIMenuElementStateOff : UIMenuElementStateOn;
- NSMutableArray<UIMenuElement *> *items = [NSMutableArray arrayWithObject:automatic];
+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";
+ }
+}
+
+// A row of the panel: a source to pick (nil key: Automatic), or one still asked, or the note that none has lines.
+@interface SGRSourceRow : NSObject
+@property (nonatomic, copy) NSString *key, *title, *subtitle;
+@property (nonatomic) BOOL picked, asking, note;
+@end
+
+@implementation SGRSourceRow
+@end
+
+// The Lyrics Source panel, a popover from the ⋯ like Speed, Pitch & Reverb's: a menu's submenu ran its rows
+// under its own title when scrolled, and could not take a source that answered after it opened. Here the title
+// scrolls with the rows, and each answer fills its row in while the panel is open.
+@interface SGRLyricsSourcePanel : UITableViewController
+@property (nonatomic, copy) NSString *track;
+@end
+
+@implementation SGRLyricsSourcePanel {
+ NSArray<SGRSourceRow *> *_rows;
+}
+
+static const CGFloat kSourcePanelWidth = 300, kSourcePanelMaxHeight = 440;
+
+- (instancetype)init {
+ return [super initWithStyle:UITableViewStylePlain];
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ self.tableView.backgroundColor = UIColor.clearColor;
+ UILabel *title = [UILabel new];
+ title.text = @"Lyrics Source";
+ title.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
+ title.textColor = UIColor.labelColor;
+ title.accessibilityTraits = UIAccessibilityTraitHeader;
+ title.frame = CGRectMake(20, 16, kSourcePanelWidth - 40, ceil(title.font.lineHeight));
+ UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kSourcePanelWidth, CGRectGetMaxY(title.frame) + 6)];
+ [header addSubview:title];
+ self.tableView.tableHeaderView = header;
+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(offersChanged:) name:SGLyricsOffersDidChangeNotification object:nil];
+ SGLyricsAskOffers(_track);
+ [self rebuild];
+}
+
+- (void)offersChanged:(NSNotification *)note {
+ if ([note.object isEqual:_track]) [self rebuild];
+}
+
+// Automatic, checked while nothing is picked and naming what the order chose, then the sources in the order:
+// those with lines for the track, the one picked checked, and those still asked with a spinner.
+- (void)rebuild {
+ NSArray<NSString *> *asking = nil;
+ NSDictionary<NSString *, SGLyricsResult *> *offers = SGLyricsOffersSoFar(_track, &asking);
+ NSString *current = SGLyricsChosenSource(_track);
+ SGRSourceRow *automatic = [SGRSourceRow new];
+ automatic.title = @"Automatic";
+ automatic.subtitle = current ? @"As the order chooses" : SGLyricsCreditFor(_track);
+ automatic.picked = !current;
+ NSMutableArray<SGRSourceRow *> *rows = [NSMutableArray arrayWithObject:automatic];
for (NSString *key in SGLyricsOrder()) {
SGLyricsResult *offer = offers[key];
- if (!offer) continue;
- SGLyricsProvider *provider = SGLyricsProviderFor(key);
- UIAction *pick = [UIAction actionWithTitle:provider.name image:nil identifier:nil
- handler:^(UIAction *action) { SGLyricsChooseSource(track, key); }];
- pick.state = [key isEqualToString:current] ? UIMenuElementStateOn : UIMenuElementStateOff;
- [items addObject:pick];
+ BOOL out = [asking containsObject:key];
+ if (!offer && !out) continue;
+ SGRSourceRow *row = [SGRSourceRow new];
+ row.key = key;
+ row.title = SGLyricsProviderFor(key).name;
+ row.subtitle = offer ? timingText(offer.karaokeLines) : @"Asking…";
+ row.asking = !offer;
+ row.picked = offer && [key isEqualToString:current];
+ [rows addObject:row];
}
- 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];
+ if (rows.count == 1) {
+ SGRSourceRow *none = [SGRSourceRow new];
+ none.title = @"No Source Has Lyrics";
+ none.note = YES;
+ [rows addObject:none];
}
- return items;
+ _rows = rows;
+ [self.tableView reloadData];
+ [self.tableView layoutIfNeeded];
+ self.preferredContentSize = CGSizeMake(kSourcePanelWidth, MIN(self.tableView.contentSize.height, kSourcePanelMaxHeight));
}
-static UIMenu *lyricsSourceMenu(void) {
+- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {
+ return _rows.count;
+}
+
+- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {
+ SGRSourceRow *row = _rows[path.row];
+ UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"source"] ?: [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"source"];
+ UIListContentConfiguration *content = [UIListContentConfiguration subtitleCellConfiguration];
+ content.text = row.title;
+ content.secondaryText = row.subtitle;
+ BOOL dim = row.asking || row.note;
+ content.textProperties.color = dim ? UIColor.secondaryLabelColor : UIColor.labelColor;
+ content.secondaryTextProperties.color = UIColor.secondaryLabelColor;
+ cell.contentConfiguration = content;
+ cell.backgroundColor = UIColor.clearColor;
+ cell.tintColor = UIColor.labelColor;
+ cell.selectionStyle = dim ? UITableViewCellSelectionStyleNone : UITableViewCellSelectionStyleDefault;
+ cell.accessoryType = row.picked ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
+ UIActivityIndicatorView *spinner = nil;
+ if (row.asking) {
+ spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleMedium];
+ [spinner startAnimating];
+ }
+ cell.accessoryView = spinner;
+ cell.accessibilityTraits = dim ? UIAccessibilityTraitNotEnabled : UIAccessibilityTraitButton | (row.picked ? UIAccessibilityTraitSelected : 0);
+ return cell;
+}
+
+- (NSIndexPath *)tableView:(UITableView *)table willSelectRowAtIndexPath:(NSIndexPath *)path {
+ SGRSourceRow *row = _rows[path.row];
+ return row.asking || row.note ? nil : path;
+}
+
+- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {
+ SGRSourceRow *row = _rows[path.row];
+ if (row.key) SGLyricsChooseSource(_track, row.key);
+ else SGLyricsChooseAutomatic(_track);
+ [self dismissViewControllerAnimated:YES completion:nil];
+}
+@end
+
+static UIAction *lyricsSourceItem(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 *> *)) {
- NSArray<NSString *> *asking = nil;
- NSDictionary<NSString *, SGLyricsResult *> *offers = SGLyricsOffersSoFar(track, &asking);
- completion(sourceItems(track, offers, asking));
+ UIAction *open = [UIAction actionWithTitle:@"Lyrics Source" image:symbol(@"quote.bubble") identifier:nil handler:^(UIAction *action) {
+ SGRLyricsSourcePanel *panel = [SGRLyricsSourcePanel new];
+ panel.track = track;
+ panel.preferredContentSize = CGSizeMake(kSourcePanelWidth, 200);
+ SGPresentPopover(panel, sg_moreButton);
}];
- UIMenu *menu = [UIMenu menuWithTitle:@"Lyrics Source" image:symbol(@"quote.bubble") identifier:nil options:0 children:@[sources]];
- menu.subtitle = SGLyricsCreditFor(track);
- return menu;
+ open.subtitle = SGLyricsCreditFor(track);
+ return open;
}
static NSArray<UIMenuElement *> *playerItems(void) {
@@ -126,7 +219,7 @@ static NSArray<UIMenuElement *> *playerItems(void) {
handler:^(UIAction *action) { SGRPlayerMenuSetBackground(kind); }]];
}
}
- UIMenu *lyrics = lyricsSourceMenu();
+ UIAction *lyrics = lyricsSourceItem();
if (lyrics) [items addObject:lyrics];
return items;
}
diff --git a/tweak/Sources/Settings/SGPageStyle.h b/tweak/Sources/Settings/SGPageStyle.h
index 9defe6e5..ea789f35 100644
--- a/tweak/Sources/Settings/SGPageStyle.h
+++ b/tweak/Sources/Settings/SGPageStyle.h
@@ -53,3 +53,6 @@ void SGOpenURL(NSString *url);
extern NSString *const SGRepoURL;
// The controller on top of the key window, through whatever is presented over it.
UIViewController *SGTopController(void);
+// `panel` as a dark popover from `from`, at its preferredContentSize, a popover on iPhone too. Picked from a
+// system menu, which is still going away, it waits for the menu.
+void SGPresentPopover(UIViewController *panel, UIView *from);
diff --git a/tweak/Sources/Settings/SGPageStyle.m b/tweak/Sources/Settings/SGPageStyle.m
index 3bbcbdd1..569bd1b5 100644
--- a/tweak/Sources/Settings/SGPageStyle.m
+++ b/tweak/Sources/Settings/SGPageStyle.m
@@ -290,6 +290,41 @@ UIViewController *SGTopController(void) {
return top;
}
+@interface SGPopoverStyle : NSObject <UIPopoverPresentationControllerDelegate>
+@end
+
+@implementation SGPopoverStyle
+- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
+ traitCollection:(UITraitCollection *)traits {
+ return UIModalPresentationNone;
+}
+@end
+
+void SGPresentPopover(UIViewController *panel, UIView *from) {
+ if (!from.window) return;
+ static SGPopoverStyle *style;
+ if (!style) style = [SGPopoverStyle new];
+ panel.modalPresentationStyle = UIModalPresentationPopover;
+ UIPopoverPresentationController *popover = panel.popoverPresentationController;
+ popover.sourceView = from;
+ popover.sourceRect = from.bounds;
+ popover.permittedArrowDirections = UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown;
+ popover.delegate = style;
+ SGPresentDark(panel);
+ __block int tries = 0;
+ __block void (^present)(void);
+ present = ^{
+ UIViewController *top = SGTopController();
+ if ((top.isBeingDismissed || top.isBeingPresented || top.transitionCoordinator) && ++tries < 20) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), present);
+ return;
+ }
+ present = nil;
+ [top presentViewController:panel animated:YES completion:nil];
+ };
+ dispatch_async(dispatch_get_main_queue(), present);
+}
+
// The fork's repo. Its links stay hidden while this is nil.
NSString *const SGRepoURL = @"https://github.com/My-Name-Is-Jeff/vitrine";
diff --git a/tweak/Sources/Shared/LyricsSources/LyricsPick.m b/tweak/Sources/Shared/LyricsSources/LyricsPick.m
index 94116bd4..f78e45cf 100644
--- a/tweak/Sources/Shared/LyricsSources/LyricsPick.m
+++ b/tweak/Sources/Shared/LyricsSources/LyricsPick.m
@@ -12,6 +12,7 @@
#import "Shared/Lyrics/Lyrics.h"
NSNotificationName const SGLyricsSourceChosenNotification = @"spotifyglass.lyricsSourceChosen";
+NSNotificationName const SGLyricsOffersDidChangeNotification = @"spotifyglass.lyricsOffersDidChange";
// Each track's asks are kept for the menu opened on it again; the picks are kept for the replays, and what
// Automatic puts back, which holds lines, for as many tracks as the walk keeps.
@@ -84,6 +85,9 @@ static void askMissing(SGLyricsOfferAsk *ask) {
failed ? @", a request failed on the way; not kept" : @"");
if (!failed) ask.answers[key] = result.karaokeLines.count ? result : NSNull.null;
[ask.asking removeObject:key];
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [NSNotificationCenter.defaultCenter postNotificationName:SGLyricsOffersDidChangeNotification object:trackID];
+ });
if (ask.asking.count) return;
NSArray *waiting = [ask.waiting copy];
[ask.waiting removeAllObjects];
@@ -108,10 +112,14 @@ static SGLyricsOfferAsk *askFor(NSString *trackID) {
return ask;
}
+void SGLyricsAskOffers(NSString *trackID) {
+ askFor(trackID);
+}
+
NSDictionary<NSString *, SGLyricsResult *> *SGLyricsOffersSoFar(NSString *trackID, NSArray<NSString *> **asking) {
- SGLyricsOfferAsk *ask = askFor(trackID);
- if (asking) *asking = ask.asking.allObjects;
- return offersIn(ask);
+ SGLyricsOfferAsk *ask = trackID ? sg_asks[trackID] : nil;
+ if (asking) *asking = ask.asking.allObjects ?: @[];
+ return ask ? offersIn(ask) : @{};
}
void SGLyricsOffers(NSString *trackID, NSTimeInterval wait, void (^done)(NSDictionary<NSString *, SGLyricsResult *> *offers)) {
diff --git a/tweak/Sources/Shared/LyricsSources/LyricsSources.h b/tweak/Sources/Shared/LyricsSources/LyricsSources.h
index 4fa3b3df..fc417156 100644
--- a/tweak/Sources/Shared/LyricsSources/LyricsSources.h
+++ b/tweak/Sources/Shared/LyricsSources/LyricsSources.h
@@ -243,8 +243,12 @@ 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.
+// The same asks started, with no answer awaited.
+void SGLyricsAskOffers(NSString *trackID);
+// What they have answered, asking nothing: the sources with lines so far, and in `asking` the keys still out.
NSDictionary<NSString *, SGLyricsResult *> *SGLyricsOffersSoFar(NSString *trackID, NSArray<NSString *> **asking);
+// Posted on the main queue (object the track's id) each time one of those sources answers.
+extern NSNotificationName const SGLyricsOffersDidChangeNotification;
// 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);
diff --git a/tweak/Sources/Shared/Player/SpeedPitchMenu.x b/tweak/Sources/Shared/Player/SpeedPitchMenu.x
index 13127baa..bcbb90cb 100644
--- a/tweak/Sources/Shared/Player/SpeedPitchMenu.x
+++ b/tweak/Sources/Shared/Player/SpeedPitchMenu.x
@@ -525,7 +525,7 @@ static NSString *pitchText(float pitch) {
// A popover, so it takes the system's glass and closes on a tap outside it. On iPhone a popover becomes a
// sheet unless its delegate says otherwise.
-@interface SGSpeedPitchPanel : UIViewController <UIPopoverPresentationControllerDelegate>
+@interface SGSpeedPitchPanel : UIViewController
@end
@implementation SGSpeedPitchPanel
@@ -534,37 +534,12 @@ static NSString *pitchText(float pitch) {
block.panelOnly = YES;
self.view = block;
}
-
-- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
- traitCollection:(UITraitCollection *)traits {
- return UIModalPresentationNone;
-}
@end
void SGPlayerShowSpeedPitchPanel(UIView *from) {
- if (!from.window) return;
SGSpeedPitchPanel *panel = [SGSpeedPitchPanel new];
- panel.modalPresentationStyle = UIModalPresentationPopover;
panel.preferredContentSize = CGSizeMake(320, kGrid + 3 * kSliderBlockHeight + kSwitchRowHeight + kPanelBottom);
- UIPopoverPresentationController *popover = panel.popoverPresentationController;
- popover.sourceView = from;
- popover.sourceRect = from.bounds;
- popover.permittedArrowDirections = UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown;
- popover.delegate = panel;
- SGPresentDark(panel);
- // Picked from the system menu, which is still going away: the panel waits for it.
- __block int tries = 0;
- __block void (^present)(void);
- present = ^{
- UIViewController *top = SGTopController();
- if ((top.isBeingDismissed || top.isBeingPresented || top.transitionCoordinator) && ++tries < 20) {
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), present);
- return;
- }
- present = nil;
- [top presentViewController:panel animated:YES completion:nil];
- };
- dispatch_async(dispatch_get_main_queue(), present);
+ SGPresentPopover(panel, from);
}
#pragma mark - the player's more button