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

chore: debug builds no longer write Spotify's player state to the log

My-Name-Is-Jeffedf5eda09ab0
diff --git a/tweak/Sources/Core/SGLog.m b/tweak/Sources/Core/SGLog.m
index 601b7177..30a5543e 100644
--- a/tweak/Sources/Core/SGLog.m
+++ b/tweak/Sources/Core/SGLog.m
@@ -9,8 +9,6 @@ static NSMutableArray<NSDictionary *> *sg_logLines;
static uint64_t sg_logSeq;
void SGLogRemember(NSString *line) {
- // The player's state dumps run to hundreds of parts each and would push every other line out.
- if ([line hasPrefix:@"player state "] || [line hasPrefix:@"player track metadata"]) return;
NSTimeInterval now = NSDate.date.timeIntervalSince1970;
os_unfair_lock_lock(&sg_logLock);
if (!sg_logLines) sg_logLines = [NSMutableArray array];
diff --git a/tweak/Sources/Diagnostics/PlayerState.x b/tweak/Sources/Diagnostics/PlayerState.x
index bf63dec0..be08652b 100644
--- a/tweak/Sources/Diagnostics/PlayerState.x
+++ b/tweak/Sources/Diagnostics/PlayerState.x
@@ -1,91 +1,7 @@
-// Temporary diagnostics (debug builds only): what the player core says about the track it is on,
-// for the reports that songs cannot be paused or scrubbed while podcasts can. Spotify grays its
-// pause button and its scrubber from the state's restrictions, and nothing about them reaches the
-// system log, so the state object is read out here: every property and object ivar of it, the
-// restrictions inside it one level deeper, and the track's metadata, which names an ad.
-//
-// A line arrives on every track change and whenever the readout changes, at most one a second.
+// Debug builds only: the player the driver reads its state from (Driver.m).
#import "Core/SGCore.h"
#import "Diagnostics.h"
#import "Headers/SPTPlayer.h"
-#import <objc/runtime.h>
-
-static NSString *summarize(id value, NSUInteger depth);
-
-// Long collections and the queues would bury the line; their size is enough.
-static NSString *summarizeCollection(id value) {
- if ([value isKindOfClass:NSArray.class]) return [NSString stringWithFormat:@"[%lu]", (unsigned long)[value count]];
- if ([value isKindOfClass:NSSet.class]) return [NSString stringWithFormat:@"{%lu}", (unsigned long)[value count]];
- return nil;
-}
-
-static NSString *readable(id value, NSUInteger depth) {
- if (!value) return @"nil";
- if ([value isKindOfClass:NSString.class] || [value isKindOfClass:NSNumber.class] || [value isKindOfClass:NSURL.class]) {
- return [value description];
- }
- NSString *collection = summarizeCollection(value);
- if (collection) return collection;
- if ([value isKindOfClass:NSDictionary.class]) return [value description];
- return depth > 0 ? summarize(value, depth - 1) : NSStringFromClass([value class]);
-}
-
-// Every property the class chain declares, then the object ivars no property covers, so a restriction
-// set kept in an ivar alone still shows.
-static NSString *summarize(id object, NSUInteger depth) {
- if (!object) return @"nil";
- NSMutableArray<NSString *> *parts = [NSMutableArray array];
- NSMutableSet<NSString *> *seen = [NSMutableSet set];
- for (Class cls = [object class]; cls && cls != NSObject.class; cls = class_getSuperclass(cls)) {
- unsigned count = 0;
- objc_property_t *properties = class_copyPropertyList(cls, &count);
- for (unsigned i = 0; i < count; i++) {
- NSString *name = @(property_getName(properties[i]));
- if ([seen containsObject:name]) continue;
- [seen addObject:name];
- id value = nil;
- @try {
- value = [object valueForKey:name];
- } @catch (NSException *exception) {
- continue;
- }
- [parts addObject:[NSString stringWithFormat:@"%@=%@", name, readable(value, depth)]];
- }
- free(properties);
-
- count = 0;
- Ivar *ivars = class_copyIvarList(cls, &count);
- for (unsigned i = 0; i < count; i++) {
- const char *type = ivar_getTypeEncoding(ivars[i]);
- if (!type || type[0] != '@') continue;
- NSString *name = [@(ivar_getName(ivars[i])) stringByReplacingOccurrencesOfString:@"_" withString:@""];
- if ([seen containsObject:name]) continue;
- [seen addObject:name];
- id value = nil;
- @try {
- value = object_getIvar(object, ivars[i]);
- } @catch (NSException *exception) {
- continue;
- }
- [parts addObject:[NSString stringWithFormat:@"%@=%@", name, readable(value, depth)]];
- }
- free(ivars);
- }
- return [NSString stringWithFormat:@"<%@ %@>", NSStringFromClass([object class]), [parts componentsJoinedByString:@" "]];
-}
-
-static void report(SPTPlayerState *state) {
- static NSString *last;
- static NSDate *lastAt;
- if (lastAt && -lastAt.timeIntervalSinceNow < 1) return;
- NSString *line = summarize(state, 2);
- if ([line isEqualToString:last]) return;
- last = line;
- lastAt = NSDate.date;
- SGLogLong(@"player state", line);
- SPTPlayerTrack *track = state.track;
- if (track) SGLogLong(@"player track metadata", track.metadata.description);
-}
static __weak id sg_player;
@@ -95,28 +11,13 @@ id SGDiagnosticsPlayer(void) {
%hook SPTEsperantoPlayer
- (id)state {
- id state = %orig;
sg_player = self;
- if (SGIsDebugBuild() && [state isKindOfClass:NSClassFromString(@"SPTPlayerState")]) report(state);
- return state;
-}
-%end
-
-// Who grays the button out: Encore draws it disabled at half alpha, and the caller says which of
-// Spotify's units decided it.
-%hook _TtC28EncoreConsumerMobile_BaseKit14PlayButtonView
-- (void)setEnabled:(BOOL)enabled {
- %orig;
- if (!SGIsDebugBuild() || enabled) return;
- static NSUInteger logged;
- if (logged++ >= 4) return;
- SGLogLong(@"play button disabled", [NSThread.callStackSymbols componentsJoinedByString:@"\n"]);
+ return %orig;
}
%end
%ctor {
if (!SGIsDebugBuild()) return;
%init;
- SGRequireClasses(@[@"SPTEsperantoPlayer", @"_TtC28EncoreConsumerMobile_BaseKit14PlayButtonView"]);
- SGLog(@"debug build: the player's state is logged as it changes");
+ SGRequireClasses(@[@"SPTEsperantoPlayer"]);
}