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 new Home look on large iPhones, its menu and test builds

My-Name-Is-Jeff012679f14460
diff --git a/tweak/Sources/Core/SGViewTree.h b/tweak/Sources/Core/SGViewTree.h
index 596f6c17..26c2d8d6 100644
--- a/tweak/Sources/Core/SGViewTree.h
+++ b/tweak/Sources/Core/SGViewTree.h
@@ -5,6 +5,8 @@ void SGForEachView(UIView *view, void (^fn)(UIView *));
CGRect SGFrameIn(UIView *view, UIView *target);
// Whether `view` sits under `root`, stopping at a visual effect view on the way up.
BOOL SGIsInside(UIView *view, UIView *root);
+// Whether no view from `view` up to (not including) `root` is hidden.
+BOOL SGShownUnder(UIView *view, UIView *root);
// The first wide stack view under `host` with at least two arranged children: a player row, or
// the row of items in the tab bar.
UIStackView *SGRowIn(UIView *host);
diff --git a/tweak/Sources/Core/SGViewTree.m b/tweak/Sources/Core/SGViewTree.m
index 18f46e71..61b74781 100644
--- a/tweak/Sources/Core/SGViewTree.m
+++ b/tweak/Sources/Core/SGViewTree.m
@@ -18,6 +18,13 @@ BOOL SGIsInside(UIView *view, UIView *root) {
return NO;
}
+BOOL SGShownUnder(UIView *view, UIView *root) {
+ for (UIView *v = view; v && v != root; v = v.superview) {
+ if (v.hidden) return NO;
+ }
+ return YES;
+}
+
UIStackView *SGRowIn(UIView *host) {
__block UIStackView *row = nil;
SGForEachView(host, ^(UIView *v) {
diff --git a/tweak/Sources/Redesigned/Home/Home.h b/tweak/Sources/Redesigned/Home/Home.h
index fc0e2afa..37f80fe1 100644
--- a/tweak/Sources/Redesigned/Home/Home.h
+++ b/tweak/Sources/Redesigned/Home/Home.h
@@ -22,8 +22,8 @@
// The Home look (the first row of the Home page): Top picks and the color behind it, the tinted glass shortcut
// pills with their bold names, the title's glass pill with the filter menu and the page's color. Off, none of
-// those hooks install and Home is as the redesign drew it before (main at 5051da55). On until switched off; read
-// at launch (SGRHomeLook).
+// those hooks install and Home has the plain shortcuts and title. On until switched off; read at launch
+// (SGRHomeLook).
#define SGRKeyHomeLook @"spotifyglass.redesign.home.look"
BOOL SGRHomeLook(void);
// Top picks (HomeTopPicks.x): the shelf nearest the top drawn large above the shortcuts. On until switched off.
diff --git a/tweak/Sources/Redesigned/Home/HomeCards.x b/tweak/Sources/Redesigned/Home/HomeCards.x
index fe017e39..769b2d11 100644
--- a/tweak/Sources/Redesigned/Home/HomeCards.x
+++ b/tweak/Sources/Redesigned/Home/HomeCards.x
@@ -91,7 +91,8 @@ static void relayoutButtonAround(UIView *view);
static void retextedUnder(UIView *label) {
CFTimeInterval began = SGRHomeProbeBegin();
- BOOL ours = [label.accessibilityIdentifier hasSuffix:@"-internal"] || [label.accessibilityIdentifier hasSuffix:@".playback"];
+ NSString *identifier = label.accessibilityIdentifier;
+ BOOL ours = [identifier hasSuffix:@"-internal"] || [identifier hasSuffix:@".playback"];
if (ours) relayoutButtonAround(label);
SGRHomeProbeEnd(SGRHomeProbeLabels, began);
if (ours) SGRHomeProbeEnd(SGRHomeProbeLabelsMatched, began);
diff --git a/tweak/Sources/Redesigned/Home/HomeHeader.x b/tweak/Sources/Redesigned/Home/HomeHeader.x
index ffa19ea5..e14e0fb0 100644
--- a/tweak/Sources/Redesigned/Home/HomeHeader.x
+++ b/tweak/Sources/Redesigned/Home/HomeHeader.x
@@ -133,17 +133,13 @@ static BOOL chosen(UIControl *chip) {
return solid;
}
-static void press(UIControl *control) {
- [control sendActionsForControlEvents:UIControlEventTouchUpInside | UIControlEventPrimaryActionTriggered];
-}
-
static NSArray<UIMenuElement *> *menuElements(void) {
NSMutableArray<UIMenuElement *> *elements = [NSMutableArray array];
NSMutableArray<UIMenuElement *> *filters = [NSMutableArray array];
for (UIControl *chip in chips(sg_stack)) {
__weak UIControl *weakChip = chip;
UIAction *action = [UIAction actionWithTitle:chip.accessibilityLabel ?: @"" image:nil identifier:nil handler:^(UIAction *a) {
- if (weakChip) press(weakChip);
+ if (weakChip) SGRActivate(weakChip);
}];
action.state = chosen(chip) ? UIMenuElementStateOn : UIMenuElementStateOff;
[filters addObject:action];
@@ -154,7 +150,7 @@ static NSArray<UIMenuElement *> *menuElements(void) {
if (connect) {
__weak UIControl *weakConnect = connect;
[more addObject:[UIAction actionWithTitle:@"Devices" image:[UIImage systemImageNamed:@"hifispeaker"] identifier:nil handler:^(UIAction *a) {
- if (weakConnect) press(weakConnect);
+ if (weakConnect) SGRActivate(weakConnect);
}]];
}
NSString *title = nil;
@@ -163,7 +159,7 @@ static NSArray<UIMenuElement *> *menuElements(void) {
__weak UIControl *weakShowAll = showAll;
[more addObject:[UIAction actionWithTitle:title.length ? [NSString stringWithFormat:@"Show all · %@", title] : @"Show all"
image:[UIImage systemImageNamed:@"rectangle.stack"] identifier:nil handler:^(UIAction *a) {
- if (weakShowAll) press(weakShowAll);
+ if (weakShowAll) SGRActivate(weakShowAll);
}]];
}
if (more.count) [elements addObject:[UIMenu menuWithTitle:@"" image:nil identifier:nil options:UIMenuOptionsDisplayInline children:more]];
diff --git a/tweak/Sources/Redesigned/Home/HomeHeadings.x b/tweak/Sources/Redesigned/Home/HomeHeadings.x
index b01e8907..e2b94067 100644
--- a/tweak/Sources/Redesigned/Home/HomeHeadings.x
+++ b/tweak/Sources/Redesigned/Home/HomeHeadings.x
@@ -45,13 +45,6 @@ static UIView *headingAround(UIView *button) {
return nil;
}
-static BOOL shown(UIView *view, UIView *root) {
- for (UIView *v = view; v && v != root; v = v.superview) {
- if (v.hidden) return NO;
- }
- return YES;
-}
-
// The label that is the title: the largest text showing under the button, its own label aside. A label the stack
// has not sized yet counts, since the constraints take its place from the layout rather than from its bounds.
static UILabel *titleLabelIn(UIView *button, UILabel *mine) {
@@ -59,7 +52,7 @@ static UILabel *titleLabelIn(UIView *button, UILabel *mine) {
SGForEachView(button, ^(UIView *v) {
if (v == mine || ![v isKindOfClass:UILabel.class]) return;
UILabel *label = (UILabel *)v;
- if (!label.text.length || !shown(label, button)) return;
+ if (!label.text.length || !SGShownUnder(label, button)) return;
if (!title || label.font.pointSize > title.font.pointSize) title = label;
});
return title;
@@ -113,7 +106,7 @@ static void restyle(UIView *button) {
// Whether "Show all" is offered is read off the hidden flags, not off its width: it has none to go by until
// the layout resolves, and a title held to the heading's own edge then ran under it.
UIView *showAll = SGRFindByIdentifier(heading, @"Components.UI.NavigationButtonHome", &kShowAllKey);
- BOOL offered = showAll && shown(showAll, heading);
+ BOOL offered = showAll && SGShownUnder(showAll, heading);
UIView *limit = offered ? showAll : heading;
if (added || held.label != theirs || held.limit != limit) {
if (held.constraints) [NSLayoutConstraint deactivateConstraints:held.constraints];
diff --git a/tweak/Sources/Redesigned/Home/HomePerf.x b/tweak/Sources/Redesigned/Home/HomePerf.x
index b3c28588..e1d442f4 100644
--- a/tweak/Sources/Redesigned/Home/HomePerf.x
+++ b/tweak/Sources/Redesigned/Home/HomePerf.x
@@ -39,6 +39,8 @@ static BOOL probing(void) {
// Home at rest: once a second, the calls and time of each hook since the last line, the list's layouts and the
// frames the display link saw late, logged only for a second in which any of them happened. A Home that is
// still and quiet logs nothing, which is the proof that nothing fires at rest (`make log | grep "home perf/s"`).
+// Off unless asked for: its display link holds the screen at up to 120 Hz while Spotify is open
+// (scripts/phone.py pref --key spotifyglass.debug.homeRestMeter --value 1, then relaunch).
static NSUInteger sg_restFrames, sg_restHitches, sg_listLayouts;
static CFTimeInterval sg_restLast;
@interface SGRHomeRestMeter : NSObject
@@ -58,7 +60,7 @@ static void startRestMeter(void) {
static NSUInteger calls[SGRHomeProbeCount];
static CFTimeInterval time[SGRHomeProbeCount];
static SGRHomeRestMeter *meter;
- if (timer) return;
+ if (timer || !SGFlag(@"spotifyglass.debug.homeRestMeter", NO)) return;
meter = [SGRHomeRestMeter new];
CADisplayLink *link = [CADisplayLink displayLinkWithTarget:meter selector:@selector(tick:)];
if (@available(iOS 15.0, *)) link.preferredFrameRateRange = CAFrameRateRangeMake(80, 120, 120);
diff --git a/tweak/Sources/Redesigned/Home/HomeSettings.m b/tweak/Sources/Redesigned/Home/HomeSettings.m
index d5d22088..64839383 100644
--- a/tweak/Sources/Redesigned/Home/HomeSettings.m
+++ b/tweak/Sources/Redesigned/Home/HomeSettings.m
@@ -17,9 +17,9 @@ UIViewController *SGRHomeSettingsPage(void) {
SGModRow *look = SGSwitchRow(@"Home look", @"Top picks, the tinted shortcut pills and the title's glass pill; off, Home as the redesign had it", SGRKeyHomeLook);
SGModRow *topPicks = SGRHomeTopPicksRow();
topPicks.waitsOn = SGRKeyHomeLook;
- from.waitsOn = SGRKeyHomeLook;
+ from.waitsOn = SGRKeyHomeTopPicks;
SGModRow *colour = SGSwitchRow(@"Color behind Top picks", nil, SGRKeyHomeTopPicksColour);
- colour.waitsOn = SGRKeyHomeLook;
+ colour.waitsOn = SGRKeyHomeTopPicks;
NSMutableArray<SGModRow *> *rows = [NSMutableArray array];
for (NSString *identity in shelves) [rows addObject:SGShownRow(identity, nil, SGRHomeShelfHideKey(identity))];
diff --git a/tweak/Sources/Redesigned/Home/HomeShelves.m b/tweak/Sources/Redesigned/Home/HomeShelves.m
index 5c4a86a5..f2379c07 100644
--- a/tweak/Sources/Redesigned/Home/HomeShelves.m
+++ b/tweak/Sources/Redesigned/Home/HomeShelves.m
@@ -18,13 +18,6 @@
static const NSTimeInterval kSeenFor = 30 * 24 * 3600, kSeenWriteEvery = 3600;
static char kHeadingKey;
-static BOOL shown(UIView *view, UIView *root) {
- for (UIView *v = view; v && v != root; v = v.superview) {
- if (v.hidden) return NO;
- }
- return YES;
-}
-
// The labels found last time, good while the title label is the same one with the same text: a shelf is measured
// and laid out many times a scroll, and the walk (and the layout it forces first) would run on each.
@interface SGRHomeHeadingCache : NSObject
@@ -58,7 +51,7 @@ static BOOL headingLabels(UIView *shelf, UILabel **title, UILabel **over) {
SGForEachView(button, ^(UIView *v) {
if (![v isKindOfClass:UILabel.class] || ![v.accessibilityIdentifier containsString:@"Encore.Label"]) return;
UILabel *label = (UILabel *)v;
- if (!label.text.length || !shown(label, button)) return;
+ if (!label.text.length || !SGShownUnder(label, button)) return;
if (!largest || label.font.pointSize > largest.font.pointSize) {
if (largest) small = largest;
largest = label;
diff --git a/tweak/Sources/Redesigned/Home/HomeTopPicks.x b/tweak/Sources/Redesigned/Home/HomeTopPicks.x
index aa925e56..0224c6e4 100644
--- a/tweak/Sources/Redesigned/Home/HomeTopPicks.x
+++ b/tweak/Sources/Redesigned/Home/HomeTopPicks.x
@@ -298,9 +298,7 @@ static CGFloat keptAbove(UICollectionView *shelf) {
NSNumber *asked = objc_getAssociatedObject(layout, &kAskedKey);
if (asked && asked.doubleValue == size.height) return;
objc_setAssociatedObject(layout, &kAskedKey, @(size.height), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
- UIView *cell = shelf.superview;
- while (cell && ![cell isKindOfClass:UICollectionViewCell.class]) cell = cell.superview;
- dispatch_async(dispatch_get_main_queue(), ^{ [cell invalidateIntrinsicContentSize]; });
+ SGRHomeMeasureAgain(shelf);
}
// VoiceOver reads a list's cells in their index order, which the swap no longer draws: the page's list reads
@@ -362,10 +360,7 @@ UIControl *SGRHomeTopPicksShowAll(NSString **title) {
if (!control) SGForEachView(showAll, ^(UIView *v) {
if (!control && [v isKindOfClass:UIControl.class]) control = (UIControl *)v;
});
- if (!control || showAll.bounds.size.width < 1) return nil;
- for (UIView *v = showAll; v && v != shelf; v = v.superview) {
- if (v.hidden) return nil;
- }
+ if (!control || showAll.bounds.size.width < 1 || !SGShownUnder(showAll, shelf)) return nil;
if (title) *title = SGRHomeShelfTitle(shelf);
return control;
}
@@ -392,20 +387,13 @@ static UILabel *footerLabel(UIFont *font, UIColor *color) {
return label;
}
-static BOOL shown(UIView *view, UIView *root) {
- for (UIView *v = view; v && v != root; v = v.superview) {
- if (v.hidden) return NO;
- }
- return YES;
-}
-
// Spotify's labels with text, top to bottom: its first line, then its second (the kind over the name on a
// "More like" card, the name over "Album • Artist" in Recents), then the sponsored line when there is one.
static NSArray<UILabel *> *spotifyLabels(UIView *card, SGRLargeCardParts *parts) {
NSMutableArray<UILabel *> *labels = [NSMutableArray array];
SGForEachView(card, ^(UIView *v) {
if (![v isKindOfClass:UILabel.class] || v == parts.lead || v == parts.second) return;
- if (((UILabel *)v).text.length && shown(v, card)) [labels addObject:(UILabel *)v];
+ if (((UILabel *)v).text.length && SGShownUnder(v, card)) [labels addObject:(UILabel *)v];
});
return [labels sortedArrayUsingComparator:^NSComparisonResult(UILabel *a, UILabel *b) {
CGFloat ya = [a convertRect:a.bounds toView:card].origin.y, yb = [b convertRect:b.bounds toView:card].origin.y;
@@ -416,6 +404,13 @@ static NSArray<UILabel *> *spotifyLabels(UIView *card, SGRLargeCardParts *parts)
static void restore(UIView *card, SGRLargeCardParts *parts) {
UIView *holder = SGRFindByIdentifier(card, @"Encore.ImageView", &kCoverKey);
if (holder && !CGAffineTransformIsIdentity(holder.transform)) holder.transform = CGAffineTransformIdentity;
+ // The corners go back to all four; roundCover (HomeCards.x) sets the small card's radius on its next pass.
+ CACornerMask all = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner | kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
+ for (UIView *sub in holder.subviews) {
+ if ([sub isKindOfClass:UIImageView.class] && sub.layer.maskedCorners != all) sub.layer.maskedCorners = all;
+ }
+ card.layer.cornerRadius = 0;
+ card.layer.masksToBounds = NO;
[parts.surface removeFromSuperview];
[parts.lead removeFromSuperview];
[parts.second removeFromSuperview];
@@ -481,7 +476,8 @@ static BOOL styleLargeCard(UIView *card) {
for (UIView *sub in holder.subviews) {
if ([sub isKindOfClass:UIImageView.class]) cover = (UIImageView *)sub;
}
- if (card.bounds.size.width < kLargeCard || !cover) {
+ // In the large shelf, not just wide: a shortcut tile is 200pt on a 440pt phone.
+ if (!SGRHomeInTopPicks(card) || card.bounds.size.width < kLargeCard || !cover) {
if (parts) restore(card, parts);
return NO;
}
diff --git a/tweak/Sources/Redesigned/Kit/SGRPalette.m b/tweak/Sources/Redesigned/Kit/SGRPalette.m
index aaef881d..870b61a2 100644
--- a/tweak/Sources/Redesigned/Kit/SGRPalette.m
+++ b/tweak/Sources/Redesigned/Kit/SGRPalette.m
@@ -210,15 +210,22 @@ static BOOL dominantColorOf(CGImageRef image, CGFloat out[3]) {
return found;
}
+// Saturation lifted by `lift` up to `max`, in HSB on the encoded color; `linear` in and out in linear light.
+static void liftSaturation(CGFloat linear[3], CGFloat lift, CGFloat max) {
+ CGFloat r = toEncoded(linear[0]), g = toEncoded(linear[1]), b = toEncoded(linear[2]), h = 0, s = 0, v = 0, a = 1;
+ [[UIColor colorWithRed:r green:g blue:b alpha:1] getHue:&h saturation:&s brightness:&v alpha:&a];
+ [[UIColor colorWithHue:h saturation:MIN(max, MAX(s, s * lift)) brightness:v alpha:1] getRed:&r green:&g blue:&b alpha:&a];
+ linear[0] = toLinear(r), linear[1] = toLinear(g), linear[2] = toLinear(b);
+}
+
#pragma mark - flow
// A dominant color in linear light made fit for a moving field: a little more colorful, and within
// the luminance band that keeps white text readable on it.
static UIColor *flowColorFor(const CGFloat linear[3], CGFloat ceiling) {
- CGFloat r = toEncoded(linear[0]), g = toEncoded(linear[1]), b = toEncoded(linear[2]), h = 0, s = 0, v = 0, a = 1;
- [[UIColor colorWithRed:r green:g blue:b alpha:1] getHue:&h saturation:&s brightness:&v alpha:&a];
- [[UIColor colorWithHue:h saturation:MIN(kFlowSaturationMax, MAX(s, s * kFlowSaturationLift)) brightness:v alpha:1] getRed:&r green:&g blue:&b alpha:&a];
- CGFloat lr = toLinear(r), lg = toLinear(g), lb = toLinear(b);
+ CGFloat lifted[3] = {linear[0], linear[1], linear[2]};
+ liftSaturation(lifted, kFlowSaturationLift, kFlowSaturationMax);
+ CGFloat lr = lifted[0], lg = lifted[1], lb = lifted[2];
CGFloat luminance = 0.2126 * lr + 0.7152 * lg + 0.0722 * lb;
CGFloat k = 1;
if (luminance > ceiling) k = ceiling / luminance;
@@ -250,13 +257,7 @@ static UIColor *tintOf(CGImageRef image, UIColor *surface, BOOL strong) {
CGFloat linear[3];
CGFloat r = 0, g = 0, b = 0, a = 1;
if (!dominantColorOf(image, linear) || ![surface getRed:&r green:&g blue:&b alpha:&a]) return nil;
- if (strong) {
- // The saturation lift, in HSB on the encoded color, then back to linear light for the luminance cap.
- CGFloat h = 0, s = 0, v = 0, lr = 0, lg = 0, lb = 0;
- [[UIColor colorWithRed:toEncoded(linear[0]) green:toEncoded(linear[1]) blue:toEncoded(linear[2]) alpha:1] getHue:&h saturation:&s brightness:&v alpha:&a];
- [[UIColor colorWithHue:h saturation:MIN(kTintSaturationMax, MAX(s, s * kTintSaturationLift)) brightness:v alpha:1] getRed:&lr green:&lg blue:&lb alpha:&a];
- linear[0] = toLinear(lr), linear[1] = toLinear(lg), linear[2] = toLinear(lb);
- }
+ if (strong) liftSaturation(linear, kTintSaturationLift, kTintSaturationMax);
CGFloat cap = strong ? kTintLuminance : kFaintTintLuminance;
CGFloat luminance = 0.2126 * linear[0] + 0.7152 * linear[1] + 0.0722 * linear[2];
if (luminance > cap) {