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: Share diagnostics, and the ad counts say what each hook checked

My-Name-Is-Jeffbad3c4610a37
diff --git a/tweak/Makefile b/tweak/Makefile
index ef41166a..fd97a072 100644
--- a/tweak/Makefile
+++ b/tweak/Makefile
@@ -30,7 +30,7 @@ spotifyglass_CFLAGS := -fobjc-arc -ISources -DSG_VERSION=\"$(SG_VERSION)\"
# SG_DRIVER=1 for those, and every other build (make release, the release workflow's .deb) leaves it out.
SG_DRIVER ?= 0
spotifyglass_CFLAGS += -DSG_DRIVER=$(SG_DRIVER)
-spotifyglass_FRAMEWORKS := UIKit QuartzCore UniformTypeIdentifiers MediaPlayer CoreImage AudioToolbox AVFoundation CoreHaptics Accelerate CoreMotion CoreML CoreText
+spotifyglass_FRAMEWORKS := UIKit QuartzCore UniformTypeIdentifiers MediaPlayer CoreImage AudioToolbox AVFoundation CoreHaptics Accelerate CoreMotion CoreML CoreText OSLog
# zlib unpacks KuGou's KRC lyrics (Shared/LyricsSources/KuGou.m).
spotifyglass_LIBRARIES := z
# Runtime swizzling instead of Substrate so the dylib has no extra dependency inside the IPA.
diff --git a/tweak/Sources/App/About/About.h b/tweak/Sources/App/About/About.h
index 03b01a6f..bcb0bb17 100644
--- a/tweak/Sources/App/About/About.h
+++ b/tweak/Sources/App/About/About.h
@@ -72,5 +72,9 @@ SGModRow *SGSigningExpiryRow(void); // "Signed until …", nil without a profi
// what is set and restarting.
void SGExportSettings(void);
void SGImportSettings(void);
+// A text file for a bug report through the share sheet: the versions and switches, the ad counts, this launch's
+// log lines and the config Spotify's server last sent (Shared/AdBlock/Premium.m). No account details or settings
+// values beyond the switches named; the log can name songs played.
+void SGShareDiagnostics(void);
UIViewController *SGAboutPage(void); // the Mod page
diff --git a/tweak/Sources/App/About/AboutSettings.m b/tweak/Sources/App/About/AboutSettings.m
index db5528fa..5aa14d2c 100644
--- a/tweak/Sources/App/About/AboutSettings.m
+++ b/tweak/Sources/App/About/AboutSettings.m
@@ -66,6 +66,8 @@ UIViewController *SGAboutPage(void) {
SGSection(nil, @[
withSymbol(SGActionRow(@"Export settings", nil, ^{ SGExportSettings(); }), @"square.and.arrow.up"),
withSymbol(SGActionRow(@"Import settings", nil, ^{ SGImportSettings(); }), @"square.and.arrow.down"),
+ withSymbol(SGActionRow(@"Share diagnostics", @"For a bug report: versions, ad counts, this launch's log and Spotify's config. Song names can show.",
+ ^{ SGShareDiagnostics(); }), @"stethoscope"),
]),
SGSection(nil, @[reset]),
] footer:nil];
diff --git a/tweak/Sources/App/About/Backup.m b/tweak/Sources/App/About/Backup.m
index 4cc97260..f09b57e6 100644
--- a/tweak/Sources/App/About/Backup.m
+++ b/tweak/Sources/App/About/Backup.m
@@ -1,5 +1,9 @@
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
+#import <OSLog/OSLog.h>
+#import <sys/utsname.h>
#import "Core/SGCore.h"
+#import "Shared/AdBlock/AdBlock.h"
+#import "Shared/Lyrics/Lyrics.h"
#import "Settings/SGPageStyle.h"
#import "About.h"
#import "Redesigned/Player/Player.h"
@@ -47,6 +51,50 @@ void SGExportSettings(void) {
[top presentViewController:sheet animated:YES completion:nil];
}
+void SGShareDiagnostics(void) {
+ NSMutableString *text = [NSMutableString string];
+ struct utsname machine;
+ uname(&machine);
+ [text appendFormat:@"Vitrine %s, Spotify %@, iOS %@, %s\n", SG_VERSION,
+ [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: @"unknown",
+ UIDevice.currentDevice.systemVersion, machine.machine];
+ [text appendFormat:@"look %@, hide ads %d, hide upsells %d, spoof premium %d, EeveeSpotify %d\n\n",
+ SGRedesignedUIStored() ? @"redesign" : @"native", SGHidden(SGKeyHideAds), SGHidden(SGKeyHideUpsells),
+ SGHidden(SGKeyFakePremium), SGEeveeSpotifyInjected()];
+ [text appendString:@"== ads blocked (stopped of checked)\n"];
+ for (NSString *label in SGAdBlockLabels()) {
+ NSUInteger checked = SGAdBlockChecked(label);
+ [text appendFormat:@"%@: %lu%@\n", label, (unsigned long)SGAdBlockCount(label),
+ checked == NSNotFound ? @"" : [NSString stringWithFormat:@" of %lu", (unsigned long)checked]];
+ }
+ // This launch's lines, from the system log: release builds keep none of their own.
+ [text appendString:@"\n== log, this launch\n"];
+ NSError *error;
+ OSLogStore *store = [OSLogStore storeWithScope:OSLogStoreCurrentProcessIdentifier error:&error];
+ // FLEX builds dump the screen's views into the log, page after page; the report keeps the lines.
+ NSPredicate *ours = [NSPredicate predicateWithFormat:
+ @"composedMessage BEGINSWITH '[spotifyglass]' AND NOT composedMessage BEGINSWITH '[spotifyglass] screen dump'"];
+ NSMutableArray<NSString *> *lines = [NSMutableArray array];
+ for (OSLogEntry *entry in [store entriesEnumeratorWithOptions:0 position:nil predicate:ours error:&error]) {
+ [lines addObject:[NSString stringWithFormat:@"%@ %@", entry.date, [entry.composedMessage substringFromIndex:15]]];
+ }
+ // ponytail: the last 1500 lines only; a whole day's launch can hold tens of thousands.
+ NSUInteger keep = MIN(lines.count, 1500);
+ [text appendString:[[lines subarrayWithRange:NSMakeRange(lines.count - keep, keep)] componentsJoinedByString:@"\n"]];
+ if (!lines.count) [text appendFormat:@"(none: %@)", error.localizedDescription ?: @"the log is empty"];
+ NSURL *caches = [NSFileManager.defaultManager URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask].firstObject;
+ NSString *config = [NSString stringWithContentsOfURL:[caches URLByAppendingPathComponent:@"Vitrine/live-config.txt"]
+ encoding:NSUTF8StringEncoding error:nil];
+ [text appendFormat:@"\n\n== config Spotify's server last sent\n%@", config ?: @"(none yet: Spoof Premium is off, or no fetch so far)\n"];
+
+ NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"vitrine-diagnostics.txt"]];
+ [text writeToURL:url atomically:YES encoding:NSUTF8StringEncoding error:nil];
+ UIViewController *top = SGTopController();
+ UIActivityViewController *sheet = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:nil];
+ sheet.popoverPresentationController.sourceView = top.view;
+ [top presentViewController:sheet animated:YES completion:nil];
+}
+
static Class kindOf(id value) {
for (Class kind in @[NSNumber.class, NSString.class, NSArray.class, NSDictionary.class]) {
if ([value isKindOfClass:kind]) return kind;
diff --git a/tweak/Sources/Shared/AdBlock/AdBlock.h b/tweak/Sources/Shared/AdBlock/AdBlock.h
index 8e713ca9..d3212254 100644
--- a/tweak/Sources/Shared/AdBlock/AdBlock.h
+++ b/tweak/Sources/Shared/AdBlock/AdBlock.h
@@ -25,6 +25,12 @@ NSNumber *SGAdBlockForcedFlag(NSString *key);
void SGAdBlockCountOne(NSString *label);
NSArray<NSString *> *SGAdBlockLabels(void);
NSUInteger SGAdBlockCount(NSString *label);
+// What a hook looked at under `label`, stopped or not, so a 0 can tell a hook Spotify never calls from one that
+// found nothing. Kept with the counts but saved only with a stop or as Spotify leaves the screen: some hooks see a
+// request a second. SGAdBlockChecked is NSNotFound for a kind that counts no checks, and 0 for one whose hook has
+// not run, which on a new Spotify can mean it never will.
+void SGAdBlockSawOne(NSString *label);
+NSUInteger SGAdBlockChecked(NSString *label);
void SGResetAdBlock(void);
// Premium.m: the body of v1/customize, or the bootstrap message that wraps one, rewritten to a
diff --git a/tweak/Sources/Shared/AdBlock/AdBlock.m b/tweak/Sources/Shared/AdBlock/AdBlock.m
index e99c86c7..ec3f5ccf 100644
--- a/tweak/Sources/Shared/AdBlock/AdBlock.m
+++ b/tweak/Sources/Shared/AdBlock/AdBlock.m
@@ -120,11 +120,27 @@ static NSString *const labels[] = {
@"Ad services", @"Upsell services", @"Popups", @"Page components", @"Feed sections", @"Requests", @"Config rewrites",
};
static NSMutableDictionary<NSString *, NSNumber *> *sg_counts;
+static BOOL sg_unsaved; // checks counted since the counts were last written
+
+static NSString *checkedKey(NSString *label) {
+ return [label stringByAppendingString:@" checked"];
+}
+
+// The kinds whose hooks count what they look at. The services are stubs Spotify loads, with nothing to look at.
+static BOOL countsChecks(NSString *label) {
+ return [@[@"Popups", @"Page components", @"Feed sections", @"Requests", @"Config rewrites"] containsObject:label];
+}
// Counting happens on whichever thread the hook ran on, the page reads on the main one.
static NSMutableDictionary<NSString *, NSNumber *> *countsLocked(void) {
if (!sg_counts) {
sg_counts = [[NSUserDefaults.standardUserDefaults dictionaryForKey:kCounts] mutableCopy] ?: [NSMutableDictionary dictionary];
+ // Counts kept before checks were counted start again, so "stopped of checked" counts both from one moment.
+ if (sg_counts.count && !sg_counts[checkedKey(@"Requests")]) {
+ [sg_counts removeAllObjects];
+ sg_counts[checkedKey(@"Requests")] = @0;
+ [NSUserDefaults.standardUserDefaults setObject:sg_counts forKey:kCounts];
+ }
}
return sg_counts;
}
@@ -134,9 +150,37 @@ void SGAdBlockCountOne(NSString *label) {
NSMutableDictionary<NSString *, NSNumber *> *counts = countsLocked();
counts[label] = @(counts[label].unsignedIntegerValue + 1);
[NSUserDefaults.standardUserDefaults setObject:counts forKey:kCounts];
+ sg_unsaved = NO;
}
}
+void SGAdBlockSawOne(NSString *label) {
+ @synchronized (kCounts) {
+ NSMutableDictionary<NSString *, NSNumber *> *counts = countsLocked();
+ NSString *key = checkedKey(label);
+ counts[key] = @(counts[key].unsignedIntegerValue + 1);
+ sg_unsaved = YES;
+ }
+}
+
+NSUInteger SGAdBlockChecked(NSString *label) {
+ @synchronized (kCounts) {
+ return countsChecks(label) ? countsLocked()[checkedKey(label)].unsignedIntegerValue : NSNotFound;
+ }
+}
+
+// The checks counted since the last stop, written as Spotify leaves the screen.
+__attribute__((constructor)) static void saveChecksOnLeaving(void) {
+ [NSNotificationCenter.defaultCenter addObserverForName:UIApplicationWillResignActiveNotification object:nil queue:nil
+ usingBlock:^(NSNotification *note) {
+ @synchronized (kCounts) {
+ if (!sg_unsaved) return;
+ [NSUserDefaults.standardUserDefaults setObject:countsLocked() forKey:kCounts];
+ sg_unsaved = NO;
+ }
+ }];
+}
+
NSArray<NSString *> *SGAdBlockLabels(void) {
return [NSArray arrayWithObjects:labels count:sizeof(labels) / sizeof(labels[0])];
}
@@ -146,7 +190,7 @@ NSUInteger SGAdBlockCount(NSString *label) {
NSDictionary<NSString *, NSNumber *> *counts = countsLocked();
if (label) return counts[label].unsignedIntegerValue;
NSUInteger total = 0;
- for (NSNumber *count in counts.allValues) total += count.unsignedIntegerValue;
+ for (NSString *each in SGAdBlockLabels()) total += counts[each].unsignedIntegerValue;
return total;
}
}
@@ -154,6 +198,7 @@ NSUInteger SGAdBlockCount(NSString *label) {
void SGResetAdBlock(void) {
@synchronized (kCounts) {
sg_counts = [NSMutableDictionary dictionary];
+ sg_unsaved = NO;
[NSUserDefaults.standardUserDefaults removeObjectForKey:kCounts];
}
}
diff --git a/tweak/Sources/Shared/AdBlock/AdBlockSettings.m b/tweak/Sources/Shared/AdBlock/AdBlockSettings.m
index 1d25660f..d8610d41 100644
--- a/tweak/Sources/Shared/AdBlock/AdBlockSettings.m
+++ b/tweak/Sources/Shared/AdBlock/AdBlockSettings.m
@@ -41,7 +41,9 @@ UIViewController *SGAdsSettingsPage(void) {
NSMutableArray<SGModRow *> *counts = [NSMutableArray array];
for (NSString *label in SGAdBlockLabels()) {
[counts addObject:SGStatRow(label, ^NSString *{
- return @(SGAdBlockCount(label)).stringValue;
+ NSUInteger checked = SGAdBlockChecked(label);
+ return checked == NSNotFound ? @(SGAdBlockCount(label)).stringValue
+ : [NSString stringWithFormat:@"%lu of %lu", (unsigned long)SGAdBlockCount(label), (unsigned long)checked];
})];
}
[counts addObject:SGStatRow(@"Total", ^NSString *{
@@ -65,7 +67,8 @@ UIViewController *SGAdsSettingsPage(void) {
SGWithSymbol(fakePremium, @"crown"),
], @"Free accounts only."),
SGPrivacySection(),
- SGSection(@"Ads blocked so far", counts),
+ SGNotedSection(@"Ads blocked so far", counts,
+ @"\"3 of 214\" is 3 stopped of 214 checked. 0 of 0 means Spotify never asked, so that part does nothing on this version."),
SGPrivacyCountersSection(),
] footer:nil];
}
diff --git a/tweak/Sources/Shared/AdBlock/AdHubs.x b/tweak/Sources/Shared/AdBlock/AdHubs.x
index b9dbda1c..2e9e7a83 100644
--- a/tweak/Sources/Shared/AdBlock/AdHubs.x
+++ b/tweak/Sources/Shared/AdBlock/AdHubs.x
@@ -72,6 +72,7 @@ static NSArray *filtered(NSArray *components) {
[kept addObject:component];
continue;
}
+ SGAdBlockSawOne(@"Page components");
if (isAd(component)) {
SGAdBlockCountOne(@"Page components");
SGLog(@"dropped page component %@", component[@"id"] ?: component[@"component"]);
diff --git a/tweak/Sources/Shared/AdBlock/AdNetwork.x b/tweak/Sources/Shared/AdBlock/AdNetwork.x
index 17ebe778..02e38c6d 100644
--- a/tweak/Sources/Shared/AdBlock/AdNetwork.x
+++ b/tweak/Sources/Shared/AdBlock/AdNetwork.x
@@ -101,6 +101,7 @@ static NSData *blockedReply(NSString *path) {
static NSData *patched(NSURL *url, NSData *body) {
NSString *path = url.path.lowercaseString ?: @"";
if (isFeed(path)) return SGStripFeed(body);
+ SGAdBlockSawOne(@"Config rewrites");
NSData *result = isBootstrap(path) ? SGPatchBootstrap(body) : SGPatchCustomize(body);
if (!result) {
SGLog(@"could not rewrite %@, passed through", path);
@@ -160,6 +161,7 @@ static void complete(id<NSURLSessionDataDelegate> delegate, NSURLSession *sessio
finish(nil);
return;
}
+ SGAdBlockSawOne(@"Requests");
switch (classify(url)) {
case SGNetBlock:
SGAdBlockCountOne(@"Requests");
@@ -228,6 +230,7 @@ static void complete(id<NSURLSessionDataDelegate> delegate, NSURLSession *sessio
BOOL spotify = has(host, @"spotify") || has(host, @"spclient");
if (spotify && elapsed() > 30 && (has(path, @"deletetoken") || has(path, @"signup/public") || has(path, @"pses/screenconfig")
|| isCustomize(path) || has(host, @"apresolve"))) {
+ SGAdBlockSawOne(@"Requests");
SGAdBlockCountOne(@"Requests");
SGLog(@"canceled %@%@ before it left", host, path);
[self cancel];
diff --git a/tweak/Sources/Shared/AdBlock/AdPopups.x b/tweak/Sources/Shared/AdBlock/AdPopups.x
index 2cfaa108..8b2edd7e 100644
--- a/tweak/Sources/Shared/AdBlock/AdPopups.x
+++ b/tweak/Sources/Shared/AdBlock/AdPopups.x
@@ -53,6 +53,7 @@ static id readKey(id object, NSString *key) {
%hook SPTEncorePopUpPresenter
- (void)presentPopUp:(id)popUp {
+ SGAdBlockSawOne(@"Popups");
id model = readKey(popUp, @"model") ?: popUp;
NSString *title = readKey(model, @"title") ?: readKey(model, @"dialogTitle");
NSString *body = readKey(model, @"descriptionText") ?: readKey(model, @"body") ?: readKey(model, @"subtitle");
diff --git a/tweak/Sources/Shared/AdBlock/Feeds.m b/tweak/Sources/Shared/AdBlock/Feeds.m
index e38d30bb..867c7460 100644
--- a/tweak/Sources/Shared/AdBlock/Feeds.m
+++ b/tweak/Sources/Shared/AdBlock/Feeds.m
@@ -55,6 +55,7 @@ NSData *SGStripFeed(NSData *body) {
NSMutableArray<SGPBField *> *kept = [NSMutableArray array];
for (SGPBField *section in sections) {
if (section.number != 1 || section.wire != 2) return nil;
+ SGAdBlockSawOne(@"Feed sections");
if (adSection(section.payload)) SGAdBlockCountOne(@"Feed sections");
else [kept addObject:section];
}
diff --git a/tweak/Sources/Shared/AdBlock/Premium.m b/tweak/Sources/Shared/AdBlock/Premium.m
index c55a3b75..4f6a15be 100644
--- a/tweak/Sources/Shared/AdBlock/Premium.m
+++ b/tweak/Sources/Shared/AdBlock/Premium.m
@@ -364,9 +364,31 @@ static void setValue(NSMutableArray<SGPBField *> *value, SGPBField *replacement)
[value addObject:replacement];
}
+// The configuration as the server sent it, one "scope.name = value" a line, in Caches/Vitrine/live-config.txt: what a
+// Free account in this country is told, to set beside a Premium one when ads still play. Names and values only;
+// replaced by each fetch.
+static void keepLiveConfiguration(NSArray<SGPBField *> *fields) {
+ NSMutableString *text = [NSMutableString string];
+ for (SGPBField *field in fields) {
+ NSArray<SGPBField *> *value = field.number == 3 && field.wire == 2 ? SGPBParse(field.payload) : nil;
+ NSArray<SGPBField *> *parts = SGPBFirst(value, 1) ? SGPBParse(SGPBFirst(value, 1).payload) : nil;
+ if (!parts) continue;
+ NSString *shown = @"?";
+ if (SGPBFirst(value, 3)) shown = SGPBFirst(SGPBParse(SGPBFirst(value, 3).payload), 1).varint ? @"true" : @"false";
+ else if (SGPBFirst(value, 4)) shown = @(SGPBFirst(SGPBParse(SGPBFirst(value, 4).payload), 1).varint).stringValue;
+ else if (SGPBFirst(value, 5)) shown = SGPBText(SGPBFirst(SGPBParse(SGPBFirst(value, 5).payload), 1)) ?: @"";
+ [text appendFormat:@"%@.%@ = %@\n", SGPBText(SGPBFirst(parts, 1)) ?: @"", SGPBText(SGPBFirst(parts, 2)) ?: @"", shown];
+ }
+ NSURL *caches = [NSFileManager.defaultManager URLsForDirectory:NSCachesDirectory inDomains:NSUserDomainMask].firstObject;
+ NSURL *folder = [caches URLByAppendingPathComponent:@"Vitrine" isDirectory:YES];
+ [NSFileManager.defaultManager createDirectoryAtURL:folder withIntermediateDirectories:YES attributes:nil error:nil];
+ [text writeToURL:[folder URLByAppendingPathComponent:@"live-config.txt"] atomically:YES encoding:NSUTF8StringEncoding error:nil];
+}
+
static NSData *patchConfiguration(NSData *configuration) {
NSMutableArray<SGPBField *> *fields = SGPBParse(configuration);
if (!fields) return nil;
+ keepLiveConfiguration(fields);
NSMutableArray<SGPBField *> *out = [NSMutableArray array];
NSMutableSet<NSString *> *present = [NSMutableSet set];
for (SGPBField *field in fields) {