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: add telemetry blocking

Vojtěch Škopek6c4facf3e0fa
diff --git a/README.md b/README.md
index d6aa9d15..a618f60f 100644
--- a/README.md
+++ b/README.md
@@ -7,8 +7,8 @@ signed and installed from the Mac.
## Layout
- tweak/src/ui/*.x the tweaks: NowPlayingBar, TabBar, Navbar, NowPlayingView, Lyrics, SearchField, Flags, Amoled, HomeGradient, Declutter, Repaint, Settings
- tweak/src/SG* shared helpers (glass panes, view walking, logging, screen dumps); SGFlagList.m is generated
+ tweak/src/ui/*.x the tweaks: NowPlayingBar, TabBar, Navbar, NowPlayingView, Lyrics, SearchField, Flags, Amoled, HomeGradient, Declutter, Playlist, Repaint, Settings
+ tweak/src/SG* shared helpers (glass panes, view walking, logging, screen dumps) and SGPrivacy, the telemetry blocking; SGFlagList.m is generated
scripts/ pipeline.sh (build + inject), install.sh (sign + install), record-trees.py, dump-log.sh, extract-flags.py
trees/ recorded view trees, one per screen; the input for every new tweak
plist/ Info.plist overrides merged into the app (turns UIDesignRequiresCompatibility off)
@@ -24,12 +24,14 @@ signed and installed from the Mac.
make log # stream [spotifyglass] log lines from the phone
make flags # regenerate the flag table in tweak/src/SGFlagList.m from the IPA
-In the app, Settings → Mod Settings has three pages of switches, UI Tweaks (tab bar, search
-field, Spotify's own glass, AMOLED), Home (a gradient background, hide sections of the Home tab)
-and Now Playing (glass, a few of Spotify's player flags, hide buttons and cards of the full
-screen player), plus Navbar, the tab bar's own composition, and All flags, Spotify's
-remote-config flags with a search field and an Auto / Off / On control per flag (a text field for
-the number and text ones); a change shows after Spotify restarts.
+In the app, Settings → Mod Settings has four pages of switches, UI Tweaks (tab bar, search
+field, Spotify's own glass, AMOLED), Home (a gradient background, hide sections of the Home tab),
+Playlist (hide the cover, the header's text and buttons, the curation pills) and Now Playing
+(glass, a few of Spotify's player flags, hide buttons and cards of the full screen player), plus
+Privacy, telemetry blocking with a count of what it has stopped, Navbar, the tab bar's own
+composition, and All flags, Spotify's remote-config flags with a search field and an Auto / Off /
+On control per flag (a text field for the number and text ones); a change shows after Spotify
+restarts.
Navbar is the exception and applies as soon as the bar lays out again. It lists the tabs in the
order the bar shows them: drag to reorder, tap to hide or show, and Add a tab puts a page of
diff --git a/tweak/control b/tweak/control
index 2b39a841..34a6d074 100644
--- a/tweak/control
+++ b/tweak/control
@@ -1,6 +1,6 @@
Package: com.vojta.spotifyglass
Name: spotifyglass
-Version: 0.13.0
+Version: 0.14.1
Architecture: iphoneos-arm
Description: Liquid Glass for the Spotify iOS app
Maintainer: vojta
diff --git a/tweak/src/SGCommon.h b/tweak/src/SGCommon.h
index a1f64d5b..29c28d37 100644
--- a/tweak/src/SGCommon.h
+++ b/tweak/src/SGCommon.h
@@ -75,6 +75,7 @@ extern NSString *const SGKeySearchField;
extern NSString *const SGKeySpotifyGlass;
extern NSString *const SGKeyAmoled;
extern NSString *const SGKeyHomeGradient; // off unless it is asked for
+extern NSString *const SGKeyBlockTelemetry;
BOOL SGFlag(NSString *key, BOOL fallback);
BOOL SGEnabled(NSString *key);
void SGSetEnabled(NSString *key, BOOL on);
@@ -135,6 +136,25 @@ void SGSetFlagOverride(NSString *key, id value);
#define SGHideHomeDJ @"spotifyglass.hide.homeDJ"
BOOL SGHidden(NSString *key);
+// Playlist switches from ui/Settings.x, read by ui/Playlist.x; an unset switch is off.
+#define SGHidePlaylistArtwork @"spotifyglass.hide.playlistArtwork"
+#define SGHidePlaylistDescription @"spotifyglass.hide.playlistDescription"
+#define SGHidePlaylistCreator @"spotifyglass.hide.playlistCreator"
+#define SGHidePlaylistLength @"spotifyglass.hide.playlistLength"
+#define SGHidePlaylistVideo @"spotifyglass.hide.playlistVideo"
+#define SGHidePlaylistAddTo @"spotifyglass.hide.playlistAddTo"
+#define SGHidePlaylistDownload @"spotifyglass.hide.playlistDownload"
+#define SGHidePlaylistShare @"spotifyglass.hide.playlistShare"
+#define SGHidePlaylistMore @"spotifyglass.hide.playlistMore"
+#define SGHidePlaylistPills @"spotifyglass.hide.playlistPills"
+#define SGHidePlaylistFind @"spotifyglass.hide.playlistFind"
+
+// Telemetry blocking (SGPrivacy.x): the destinations it knows in the order it lists them, how many
+// requests to one of them it has answered instead of letting out (nil label for all of them).
+NSArray<NSString *> *SGBlockedLabels(void);
+NSUInteger SGBlockedCount(NSString *label);
+void SGResetBlocked(void);
+
// Diagnostics (SGDiagnostics.x)
BOOL SGIsDebugBuild(void);
NSString *SGScreenTree(void);
diff --git a/tweak/src/SGCommon.m b/tweak/src/SGCommon.m
index 9bf44068..2ce8ac04 100644
--- a/tweak/src/SGCommon.m
+++ b/tweak/src/SGCommon.m
@@ -57,6 +57,7 @@ NSString *const SGKeySearchField = @"spotifyglass.searchField";
NSString *const SGKeySpotifyGlass = @"spotifyglass.spotifyGlass";
NSString *const SGKeyAmoled = @"spotifyglass.amoled";
NSString *const SGKeyHomeGradient = @"spotifyglass.homeGradient";
+NSString *const SGKeyBlockTelemetry = @"spotifyglass.blockTelemetry";
BOOL SGFlag(NSString *key, BOOL fallback) {
id value = [NSUserDefaults.standardUserDefaults objectForKey:key];
diff --git a/tweak/src/SGPrivacy.x b/tweak/src/SGPrivacy.x
new file mode 100644
index 00000000..6cc19a73
--- /dev/null
+++ b/tweak/src/SGPrivacy.x
@@ -0,0 +1,150 @@
+// Telemetry blocking: an NSURLProtocol that answers the analytics endpoints itself instead of
+// letting them out, and keeps a count of what it stopped for the Privacy page.
+//
+// Spotify sends its own events to spclient's /gabo-receiver-service/, and each SDK it carries has
+// somewhere of its own to send to: Firebase to app-measurement.com, the Facebook SDK to
+// graph.facebook.com/<id>/activities, then Branch, Comscore, Segment. Nothing on the list carries
+// playback, search, sign-in or deep links, which is why whole hosts are named where the host does
+// nothing else and a path is named where it does.
+//
+// A protocol handed to +registerClass: is only consulted by NSURLConnection and the shared
+// session, so both session configurations are given it as well: that is what the SDKs build their
+// sessions from. What the core sends over its own sockets is out of reach either way, and the
+// counter is what tells the two apart -- Spotify events climbing in it means those events travel
+// over NSURLSession after all.
+#import "SGCommon.h"
+
+typedef struct { const char *host, *path, *label; } SGBlockRule;
+
+// host matched on the domain and its subdomains, path as a substring; no path means the whole host.
+static const SGBlockRule kRules[] = {
+ {"spotify.com", "/gabo-receiver-service/", "Spotify events"},
+ {"app-measurement.com", NULL, "Firebase"},
+ {"crashlytics.com", NULL, "Crashlytics"},
+ {"facebook.com", "/activities", "Facebook"},
+ {"ep1.facebook.com", NULL, "Facebook"},
+ {"ep2.facebook.com", NULL, "Facebook"},
+ {"branch.io", "/v1/event", "Branch"},
+ {"scorecardresearch.com", NULL, "Comscore"},
+ {"segment.io", NULL, "Segment"},
+ {"zqtk.net", NULL, "Segment"},
+ {"google-analytics.com", NULL, "Google"},
+ {"googleadservices.com", NULL, "Google"},
+ {"doubleclick.net", NULL, "Google"},
+};
+static const size_t kRuleCount = sizeof(kRules) / sizeof(kRules[0]);
+
+static NSString *const kCounts = @"spotifyglass.privacy.counts";
+static NSMutableDictionary<NSString *, NSNumber *> *sg_counts;
+
+@interface SGBlockProtocol : NSURLProtocol
+@end
+
+// The class object stands in for a lock: counting happens on whichever thread the request was made
+// on, the Privacy page reads on the main one.
+static NSMutableDictionary<NSString *, NSNumber *> *countsLocked(void) {
+ if (!sg_counts) {
+ sg_counts = [[NSUserDefaults.standardUserDefaults dictionaryForKey:kCounts] mutableCopy] ?: [NSMutableDictionary dictionary];
+ }
+ return sg_counts;
+}
+
+static void countOne(NSString *label) {
+ @synchronized (SGBlockProtocol.class) {
+ NSMutableDictionary<NSString *, NSNumber *> *counts = countsLocked();
+ counts[label] = @(counts[label].unsignedIntegerValue + 1);
+ [NSUserDefaults.standardUserDefaults setObject:counts forKey:kCounts];
+ }
+}
+
+static NSString *labelFor(NSURL *url) {
+ NSString *host = url.host.lowercaseString;
+ if (!host) return nil;
+ NSString *path = url.path ?: @"";
+ for (size_t i = 0; i < kRuleCount; i++) {
+ NSString *domain = @(kRules[i].host);
+ if (![host isEqualToString:domain] && ![host hasSuffix:[@"." stringByAppendingString:domain]]) continue;
+ if (kRules[i].path && ![path containsString:@(kRules[i].path)]) continue;
+ return @(kRules[i].label);
+ }
+ return nil;
+}
+
+NSArray<NSString *> *SGBlockedLabels(void) {
+ NSMutableArray<NSString *> *labels = [NSMutableArray array];
+ for (size_t i = 0; i < kRuleCount; i++) {
+ NSString *label = @(kRules[i].label);
+ if (![labels containsObject:label]) [labels addObject:label];
+ }
+ return labels;
+}
+
+NSUInteger SGBlockedCount(NSString *label) {
+ @synchronized (SGBlockProtocol.class) {
+ NSDictionary<NSString *, NSNumber *> *counts = countsLocked();
+ if (label) return counts[label].unsignedIntegerValue;
+ NSUInteger total = 0;
+ for (NSNumber *count in counts.allValues) total += count.unsignedIntegerValue;
+ return total;
+ }
+}
+
+void SGResetBlocked(void) {
+ @synchronized (SGBlockProtocol.class) {
+ sg_counts = [NSMutableDictionary dictionary];
+ [NSUserDefaults.standardUserDefaults removeObjectForKey:kCounts];
+ }
+}
+
+@implementation SGBlockProtocol
+
++ (BOOL)canInitWithRequest:(NSURLRequest *)request {
+ return labelFor(request.URL) != nil;
+}
+
++ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)request {
+ return request;
+}
+
+- (void)startLoading {
+ NSString *label = labelFor(self.request.URL);
+ if (label) countOne(label);
+ // 204 rather than an error: the sender takes it for delivered and queues no retry behind it.
+ NSHTTPURLResponse *answer = [[NSHTTPURLResponse alloc] initWithURL:self.request.URL statusCode:204 HTTPVersion:@"HTTP/1.1" headerFields:@{}];
+ [self.client URLProtocol:self didReceiveResponse:answer cacheStoragePolicy:NSURLCacheStorageNotAllowed];
+ [self.client URLProtocolDidFinishLoading:self];
+}
+
+- (void)stopLoading {
+}
+
+@end
+
+static NSURLSessionConfiguration *carryingProtocol(NSURLSessionConfiguration *configuration) {
+ if (!configuration || [configuration.protocolClasses containsObject:SGBlockProtocol.class]) return configuration;
+ NSMutableArray *classes = [configuration.protocolClasses mutableCopy] ?: [NSMutableArray array];
+ [classes insertObject:SGBlockProtocol.class atIndex:0];
+ configuration.protocolClasses = classes;
+ return configuration;
+}
+
+%hook NSURLSessionConfiguration
+
++ (NSURLSessionConfiguration *)defaultSessionConfiguration {
+ NSURLSessionConfiguration *configuration = %orig;
+ return carryingProtocol(configuration);
+}
+
++ (NSURLSessionConfiguration *)ephemeralSessionConfiguration {
+ NSURLSessionConfiguration *configuration = %orig;
+ return carryingProtocol(configuration);
+}
+
+%end
+
+%ctor {
+ if (SGEnabled(SGKeyBlockTelemetry)) {
+ [NSURLProtocol registerClass:SGBlockProtocol.class];
+ %init;
+ }
+}
diff --git a/tweak/src/ui/Playlist.x b/tweak/src/ui/Playlist.x
new file mode 100644
index 00000000..ca74f139
--- /dev/null
+++ b/tweak/src/ui/Playlist.x
@@ -0,0 +1,183 @@
+// Playlist: hides parts of a playlist page, one switch each in Mod Settings > Playlist. Album and
+// artist pages are built by another framework and are left alone.
+//
+// The header parts are hidden from the layout pass that places them, not from the view
+// controller's: the elements arrive after the page does, and a controller whose own view is not
+// dirty never hears about it, so anything hidden a level up flashes first.
+//
+// Tree (trees/playlist.txt): HeaderContentLayout holds the cover in a ShadowContainer over a block
+// of title, description, the creator row, the length and the button row, a UIStackView of
+// ActionViews -- the video deck, add, download, share and more. Each names itself by what it holds
+// except share and more, which are plain icon buttons and go by their place in the row, more being
+// the last. Find on page and Sort are a header view of their own, over the list.
+//
+// The header's height is not measured from what it shows: -[SPTFreeTierPlaylistEncoreHeaderViewController
+// update] adds three numbers into a stored fullHeaderHeight and pins headerViewHeightConstraint to
+// it, so a hidden cover leaves the room it was counted for. collapseCover() takes that room back.
+#import "SGCommon.h"
+
+@interface NSObject (SGPlaylistHeader)
+- (NSLayoutConstraint *)headerViewHeightConstraint;
+- (NSLayoutConstraint *)layoutGuideHeightConstraint;
+@end
+
+static UIView *viewNamed(UIView *root, NSString *marker) {
+ __block UIView *found = nil;
+ SGForEachView(root, ^(UIView *v) {
+ if (!found && [NSStringFromClass(v.class) containsString:marker]) found = v;
+ });
+ return found;
+}
+
+// Only ever hides. A switch turned off again shows after Spotify restarts, like every other one.
+static void hide(UIView *view, NSString *key) {
+ if (view && SGHidden(key)) view.hidden = YES;
+}
+
+// The header layout is Encore's own class, so the hook asks whose page it is before touching it.
+static UIViewController *playlistHeaderOf(UIView *view) {
+ for (UIResponder *r = view; r; r = r.nextResponder) {
+ if (![r isKindOfClass:UIViewController.class]) continue;
+ return [NSStringFromClass(r.class) containsString:@"FreeTierPlaylist"] ? (UIViewController *)r : nil;
+ }
+ return nil;
+}
+
+static UIView *coverIn(UIView *layout) {
+ for (UIView *v in layout.subviews) {
+ if ([NSStringFromClass(v.class) containsString:@"ShadowContainer"]) return v;
+ }
+ return nil;
+}
+
+// Title, description, the creator row and the length share one column, and only the description
+// names a class of its own, so the column is reached through it and its rows go by what they hold.
+// The length is the last row rather than the second stack: a byline without faces is a stack too.
+static void applyColumn(UIView *header) {
+ UIView *column = nil;
+ for (UIView *v = viewNamed(header, @"ExpandableTextView"); v && v != header; v = v.superview) {
+ if (![NSStringFromClass(v.superview.class) containsString:@"AutoLayoutStackView"]) continue;
+ column = v;
+ break;
+ }
+ for (UIView *row in column.subviews) {
+ BOOL last = row == column.subviews.lastObject && [NSStringFromClass(row.class) containsString:@"StackView"];
+ if (SGHasClass(row, @"ExpandableTextView")) hide(row, SGHidePlaylistDescription);
+ else if (SGHasClass(row, @"FacepileView")) hide(row, SGHidePlaylistCreator);
+ else if (last) hide(row, SGHidePlaylistLength);
+ }
+}
+
+// The button row is a real stack view, so a hidden button leaves no gap behind it. Buttons Spotify
+// hides itself stay in the count, so that hiding more never shifts share into its place.
+static void applyActions(UIView *header) {
+ __block UIStackView *row = nil;
+ SGForEachView(header, ^(UIView *v) {
+ if (row || ![v isKindOfClass:UIStackView.class]) return;
+ for (UIView *item in ((UIStackView *)v).arrangedSubviews) {
+ if ([NSStringFromClass(item.class) containsString:@"ActionView"]) row = (UIStackView *)v;
+ }
+ });
+ NSMutableArray<UIView *> *plain = [NSMutableArray array];
+ for (UIView *action in row.arrangedSubviews) {
+ if (SGHasClass(action, @"WatchFeed")) hide(action, SGHidePlaylistVideo);
+ else if (SGHasClass(action, @"AddToButton")) hide(action, SGHidePlaylistAddTo);
+ else if (SGHasClass(action, @"GranularDownloadButton")) hide(action, SGHidePlaylistDownload);
+ else [plain addObject:action];
+ }
+ for (UIView *action in plain) {
+ hide(action, action == plain.lastObject ? SGHidePlaylistMore : SGHidePlaylistShare);
+ }
+}
+
+// Find on page and Sort sit in a header view of their own, one that holds nothing else.
+static void applyFindBar(UIView *header) {
+ for (UIView *v = viewNamed(header, @"EncoreTextField"); v && v != header; v = v.superview) {
+ if (![NSStringFromClass(v.class) containsString:@"HeaderView"]) continue;
+ hide(v, SGHidePlaylistFind);
+ return;
+ }
+}
+
+// Takes back the room the hidden cover was measured into: everything beside the cover moves up to
+// where the cover began, and the header's height constraints come down by what that frees. Both
+// numbers are read back from the frames Spotify has just set, so once the header has shrunk the
+// next pass finds nothing left to take and stops. The constraint is only touched when it is the
+// one sizing this layout; otherwise the room stays and the log says why.
+static void collapseCover(UIViewController *headerVC, UIView *layout, UIView *cover) {
+ if (![headerVC respondsToSelector:@selector(headerViewHeightConstraint)]) return;
+ NSLayoutConstraint *height = [headerVC headerViewHeightConstraint];
+ CGFloat full = CGRectGetHeight(layout.bounds);
+ if (fabs(height.constant - full) > 1) {
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{ SGLog(@"playlist header: constraint %.0f does not size the %.0f layout", height.constant, full); });
+ return;
+ }
+
+ CGFloat top = CGFLOAT_MAX, bottom = 0;
+ for (UIView *v in layout.subviews) {
+ if (v == cover) continue;
+ top = MIN(top, CGRectGetMinY(v.frame));
+ bottom = MAX(bottom, CGRectGetMaxY(v.frame));
+ }
+ if (top == CGFLOAT_MAX) return;
+
+ CGFloat coverTop = CGRectGetMinY(cover.frame);
+ CGFloat shift = coverTop > 0 && coverTop < top ? top - coverTop : 0;
+ for (UIView *v in layout.subviews) {
+ if (v != cover && shift > 0) v.frame = CGRectOffset(v.frame, 0, -shift);
+ }
+ CGFloat drop = full - (bottom - shift);
+ if (drop < 1) return;
+ height.constant -= drop;
+ if ([headerVC respondsToSelector:@selector(layoutGuideHeightConstraint)]) {
+ NSLayoutConstraint *guide = [headerVC layoutGuideHeightConstraint];
+ if (guide.constant > drop) guide.constant -= drop;
+ }
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{ SGLog(@"playlist header: %.0f -> %.0f, cover took %.0f", full, full - drop, drop); });
+}
+
+%hook _TtC28EncoreConsumerMobile_BaseKit19HeaderContentLayout
+- (void)layoutSubviews {
+ %orig;
+ UIViewController *headerVC = playlistHeaderOf((UIView *)self);
+ if (!headerVC) return;
+ UIView *layout = (UIView *)self, *cover = coverIn(layout);
+ hide(cover, SGHidePlaylistArtwork);
+ applyColumn(layout);
+ applyActions(layout);
+ if (cover.hidden) collapseCover(headerVC, layout, cover);
+}
+%end
+
+// The find bar is not in the header layout, and it fades in on its own rather than appearing, so
+// the controller's pass is soon enough for it.
+%hook SPTFreeTierPlaylistEncoreHeaderViewController
+- (void)viewDidLayoutSubviews {
+ %orig;
+ UIView *header = ((UIViewController *)self).viewIfLoaded;
+ if (header) applyFindBar(header);
+}
+%end
+
+%hook _TtC35ListUXPlatform_FreeTierPlaylistImpl25ElementCollectionViewCell
+- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)attributes {
+ UICollectionViewLayoutAttributes *result = %orig;
+ if (!SGHidden(SGHidePlaylistPills) || !SGHasClass((UIView *)self, @"CurationActionsToolbar")) return result;
+ result.size = CGSizeMake(result.size.width, 0);
+ ((UIView *)self).clipsToBounds = YES;
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{ SGLog(@"collapsed the curation pills"); });
+ return result;
+}
+%end
+
+%ctor {
+ %init;
+ SGRequireClasses(@[
+ @"_TtC28EncoreConsumerMobile_BaseKit19HeaderContentLayout",
+ @"SPTFreeTierPlaylistEncoreHeaderViewController",
+ @"_TtC35ListUXPlatform_FreeTierPlaylistImpl25ElementCollectionViewCell",
+ ]);
+}
diff --git a/tweak/src/ui/Settings.x b/tweak/src/ui/Settings.x
index df639744..aa088cb5 100644
--- a/tweak/src/ui/Settings.x
+++ b/tweak/src/ui/Settings.x
@@ -1,5 +1,5 @@
// Settings: a Mod Settings row at the end of Spotify's settings list opens the mod's own pages:
-// UI Tweaks, Home and Now Playing, each sections of switches (the mod's own and a few of
+// UI Tweaks, Home, Playlist and Now Playing, each sections of switches (the mod's own and a few of
// Spotify's remote-config flags), Navbar, the tab bar's own composition, and All flags, a
// searchable list of every flag with an override per flag. The tweaks read the switches when they
// run, so a change shows after Spotify restarts; the Navbar page is the exception and applies as
@@ -109,7 +109,9 @@ static BOOL sg_pagesConform;
@end
// A row is a switch when it has a key and a link to another page when it has a page. A flag row
-// switches one of Spotify's remote-config flags: on forces it, off leaves Spotify's value.
+// switches one of Spotify's remote-config flags: on forces it, off leaves Spotify's value. A row
+// with a value reads one out on the right and is asked again while the page is open; a row with an
+// action runs it when tapped.
@interface SGModRow : NSObject
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@@ -117,6 +119,8 @@ static BOOL sg_pagesConform;
@property (nonatomic) BOOL defaultOn;
@property (nonatomic) BOOL flag;
@property (nonatomic, copy) UIViewController *(^page)(void);
+@property (nonatomic, copy) NSString *(^value)(void);
+@property (nonatomic, copy) void (^action)(void);
@end
@implementation SGModRow
@@ -158,6 +162,21 @@ static SGModRow *flagRow(NSString *title, NSString *key) {
return row;
}
+static SGModRow *statRow(NSString *title, NSString *(^value)(void)) {
+ SGModRow *row = [SGModRow new];
+ row.title = title;
+ row.value = value;
+ return row;
+}
+
+static SGModRow *actionRow(NSString *title, NSString *subtitle, void (^action)(void)) {
+ SGModRow *row = [SGModRow new];
+ row.title = title;
+ row.subtitle = subtitle;
+ row.action = action;
+ return row;
+}
+
static SGModRow *pageRow(NSString *title, NSString *subtitle, UIViewController *(^page)(void)) {
SGModRow *row = [SGModRow new];
row.title = title;
@@ -223,6 +242,8 @@ static UITableViewCell *dequeue(UITableView *table, NSString *identifier) {
NSArray<SGModSection *> *_sections;
UIView *_intro;
UIView *_footer;
+ NSTimer *_ticker;
+ BOOL _live;
}
- (instancetype)initWithTitle:(NSString *)title intro:(NSString *)intro sections:(NSArray<SGModSection *> *)sections footer:(NSString *)footer {
@@ -231,6 +252,7 @@ static UITableViewCell *dequeue(UITableView *table, NSString *identifier) {
_sections = sections;
_intro = intro ? note(intro) : nil;
_footer = footer ? note(footer) : nil;
+ for (SGModSection *s in sections) for (SGModRow *row in s.rows) _live |= row.value != nil;
return self;
}
@@ -255,6 +277,32 @@ static UITableViewCell *dequeue(UITableView *table, NSString *identifier) {
insetForBars(self.tableView);
}
+- (void)viewWillAppear:(BOOL)animated {
+ [super viewWillAppear:animated];
+ if (!_live) return;
+ [self.tableView reloadData];
+ // The counters climb while the page is open; the labels are written straight into the cells so
+ // that a reload never lands under a switch being dragged.
+ _ticker = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(readValues) userInfo:nil repeats:YES];
+}
+
+- (void)viewDidDisappear:(BOOL)animated {
+ [super viewDidDisappear:animated];
+ [_ticker invalidate];
+ _ticker = nil;
+}
+
+- (void)readValues {
+ for (UITableViewCell *cell in self.tableView.visibleCells) {
+ SGModRow *row = [self rowAt:[self.tableView indexPathForCell:cell]];
+ UILabel *label = (UILabel *)cell.accessoryView;
+ if (!row.value || ![label isKindOfClass:UILabel.class]) continue;
+ label.text = row.value();
+ [label sizeToFit];
+ [cell setNeedsLayout];
+ }
+}
+
- (SGModRow *)rowAt:(NSIndexPath *)path {
return _sections[(NSUInteger)path.section].rows[(NSUInteger)path.row];
}
@@ -295,6 +343,15 @@ static UITableViewCell *dequeue(UITableView *table, NSString *identifier) {
} else if (row.page) {
cell.accessoryView = symbol(@"chevron.right", 13, UIImageSymbolWeightSemibold, 16);
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
+ } else if (row.value) {
+ UILabel *label = [UILabel new];
+ label.font = titleFont();
+ label.textColor = grey();
+ label.text = row.value();
+ [label sizeToFit];
+ cell.accessoryView = label;
+ } else if (row.action) {
+ cell.selectionStyle = UITableViewCellSelectionStyleDefault;
}
return cell;
}
@@ -302,6 +359,10 @@ static UITableViewCell *dequeue(UITableView *table, NSString *identifier) {
- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {
SGModRow *row = [self rowAt:path];
if (row.page) [self.navigationController pushViewController:row.page() animated:YES];
+ if (!row.action) return;
+ row.action();
+ [table deselectRowAtIndexPath:path animated:YES];
+ [self readValues];
}
- (void)toggled:(UISwitch *)toggle {
@@ -831,6 +892,28 @@ static UIViewController *homePage(void) {
] footer:@"The shelves (Your top mixes, Jump back in, Recents and the rest) all share one card type, so they cannot be told apart yet."];
}
+static UIViewController *playlistPage(void) {
+ return [[SGModPage alloc] initWithTitle:@"Playlist" intro:kRestart sections:@[
+ section(@"Hide in the header", @[
+ hideRow(@"Cover artwork", @"The square cover over the title", SGHidePlaylistArtwork),
+ hideRow(@"Description", @"The text under the title", SGHidePlaylistDescription),
+ hideRow(@"Creator and collaborators", @"The faces, the name and Message", SGHidePlaylistCreator),
+ hideRow(@"Length and saves", @"The line under the creator", SGHidePlaylistLength),
+ ]),
+ section(@"Hide header buttons", @[
+ hideRow(@"Video", @"The stack of clips at the start of the row", SGHidePlaylistVideo),
+ hideRow(@"Add to library", @"The plus", SGHidePlaylistAddTo),
+ hideRow(@"Download", @"The download arrow", SGHidePlaylistDownload),
+ hideRow(@"Share", @"The button that opens the share sheet", SGHidePlaylistShare),
+ hideRow(@"More", @"The three dots at the end of the row", SGHidePlaylistMore),
+ ]),
+ section(@"Hide over the tracks", @[
+ hideRow(@"Curation pills", @"Add, Mix, Video, Edit, Sort and the rest", SGHidePlaylistPills),
+ hideRow(@"Find and sort bar", @"Find on page and Sort, under the header", SGHidePlaylistFind),
+ ]),
+ ] footer:@"Hiding the cover pulls the rest of the header up into the space it stood in. Albums and artists are pages of another kind and keep everything."];
+}
+
static UIViewController *nowPlayingPage(void) {
return [[SGModPage alloc] initWithTitle:@"Now Playing" intro:kRestart sections:@[
section(@"Liquid Glass", @[
@@ -877,6 +960,27 @@ static UIViewController *nowPlayingPage(void) {
] footer:@"A flag switch forces one of Spotify's remote-config flags on; off leaves whatever Spotify sends. All flags lists every one of them."];
}
+static UIViewController *privacyPage(void) {
+ NSMutableArray<SGModRow *> *counts = [NSMutableArray array];
+ for (NSString *label in SGBlockedLabels()) {
+ [counts addObject:statRow(label, ^NSString *{
+ return @(SGBlockedCount(label)).stringValue;
+ })];
+ }
+ [counts addObject:statRow(@"Total", ^NSString *{
+ return @(SGBlockedCount(nil)).stringValue;
+ })];
+ return [[SGModPage alloc] initWithTitle:@"Privacy" intro:kRestart sections:@[
+ section(@"Telemetry", @[
+ switchRow(@"Block telemetry", @"Answer the analytics endpoints with an empty reply instead of letting the request out", SGKeyBlockTelemetry),
+ ]),
+ section(@"Blocked so far", counts),
+ section(nil, @[
+ actionRow(@"Reset the counters", @"Start counting from zero", ^{ SGResetBlocked(); }),
+ ]),
+ ] footer:@"Spotify's own events go to the gabo receiver, the rest belong to the SDKs it carries: Firebase, Crashlytics, the Facebook SDK, Branch, Comscore, Segment and Google. Playback, search, sign-in and shared links are not on the list. Only what the app sends through NSURLSession can be counted, so anything its core sends over sockets of its own passes unseen."];
+}
+
static UIViewController *modSettingsPage(void) {
NSString *spotify = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *about = [NSString stringWithFormat:@"spotifyglass %s · Spotify %@\n"
@@ -886,7 +990,9 @@ static UIViewController *modSettingsPage(void) {
pageRow(@"UI Tweaks", @"Liquid Glass • AMOLED background", ^UIViewController *{ return uiTweaksPage(); }),
pageRow(@"Navbar", @"Reorder the tabs, hide them, add your own", ^UIViewController *{ return [SGNavbarPage new]; }),
pageRow(@"Home", @"Gradient background, hide sections of the Home tab", ^UIViewController *{ return homePage(); }),
+ pageRow(@"Playlist", @"Hide the cover, the header buttons and the pills", ^UIViewController *{ return playlistPage(); }),
pageRow(@"Now Playing", @"Glass, Spotify's player flags, hide buttons and cards", ^UIViewController *{ return nowPlayingPage(); }),
+ pageRow(@"Privacy", @"Block telemetry, and what it has blocked so far", ^UIViewController *{ return privacyPage(); }),
pageRow(@"All flags", @"Search and force any of Spotify's remote-config flags", ^UIViewController *{ return [SGFlagsPage new]; }),
]),
] footer:about];
@@ -911,8 +1017,11 @@ static UIViewController *modSettingsPage(void) {
_title.text = @"Mod Settings";
_title.textColor = UIColor.whiteColor;
_subtitle = [UILabel new];
- _subtitle.text = @"UI Tweaks • Navbar • Home • Now Playing • Flags";
+ _subtitle.text = @"UI Tweaks • Navbar • Home • Playlist • Now Playing • Privacy • Flags";
_subtitle.textColor = grey();
+ // One page too many for the row on a narrow phone.
+ _subtitle.adjustsFontSizeToFitWidth = YES;
+ _subtitle.minimumScaleFactor = 0.8;
_chevron = symbol(@"chevron.right", 11, UIImageSymbolWeightSemibold, 12);
for (UIView *v in @[_icon, _title, _subtitle, _chevron]) [self addSubview:v];
[self addTarget:self action:@selector(open) forControlEvents:UIControlEventTouchUpInside];
@@ -980,12 +1089,47 @@ static void placeRow(UICollectionView *list, SGModSettingsRow *row) {
list.contentInset = inset;
}
+// Media quality, Playback, Account and most of the rest of settings are the same controller class
+// as the list they were opened from, which is why the row turned up at the end of all of them.
+// What is on the navigation stack is not that controller though: every page in the app is wrapped
+// in a MusicAppPageHostingViewController (trees/settings notifications opened.txt), and Spotify
+// pushes a settings sub page as a page of its own, leaving the list it came from on the stack
+// underneath. So the settings list inside the lowest wrapper that holds one is the list the row
+// belongs at the end of, and a controller with no stack to be found on keeps the row rather than
+// losing it.
+static UIViewController *settingsListIn(UIViewController *page, Class kind) {
+ if ([page isKindOfClass:kind]) return page;
+ for (UIViewController *child in page.childViewControllers) {
+ UIViewController *found = settingsListIn(child, kind);
+ if (found) return found;
+ }
+ return nil;
+}
+
+static BOOL isSettingsRoot(UIViewController *list) {
+ for (UIViewController *page in list.navigationController.viewControllers) {
+ UIViewController *found = settingsListIn(page, list.class);
+ if (found) return found == list;
+ }
+ return YES;
+}
+
%hook _TtC21Settings_PlatformImpl26SettingsListViewController
- (void)viewDidLayoutSubviews {
%orig;
+ BOOL root = isSettingsRoot((UIViewController *)self);
for (UIView *sub in ((UIViewController *)self).view.subviews) {
- if (![sub isKindOfClass:UICollectionView.class] || objc_getAssociatedObject(sub, &kRowKey)) continue;
- SGModSettingsRow *row = [[SGModSettingsRow alloc] initWithFrame:CGRectZero];
+ if (![sub isKindOfClass:UICollectionView.class]) continue;
+ SGModSettingsRow *row = objc_getAssociatedObject(sub, &kRowKey);
+ // A page that laid itself out before it was on the stack looked like the list for as long
+ // as that took; the row goes again as soon as it can be seen for what it is.
+ if (!root) {
+ [row removeFromSuperview];
+ objc_setAssociatedObject(sub, &kRowKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ continue;
+ }
+ if (row) continue;
+ row = [[SGModSettingsRow alloc] initWithFrame:CGRectZero];
objc_setAssociatedObject(sub, &kRowKey, row, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[sub addSubview:row];
}