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: dump view tree on background

Vojtěch Škopekfdfbde07ac82
diff --git a/README.md b/README.md
index 098a7897..8d1656c0 100644
--- a/README.md
+++ b/README.md
@@ -17,4 +17,6 @@ with your own certificate and push it to the iPhone over USB; put `SIGN_P12`, `S
Runtime log lines are prefixed `[spotifyglass]`. With the phone on USB, `./dump-log.sh > out/spotifyglass.log`
then relaunch Spotify captures them on the Mac; on the phone they are in FLEX → System Log (long-press
-a row to copy it). The first layout of each bar dumps its full view hierarchy in numbered parts.
+a row to copy it). The first layout of each bar dumps its full view hierarchy in numbered parts, and in a FLEX build every
+time the app goes to the background it dumps the whole visible screen: classes, frames, colours, radii,
+label text and the view controller tree. Open a screen, swipe to the home screen, and the tree is in the log.
diff --git a/tweak/Tweak.x b/tweak/Tweak.x
index e46f2137..d716d91f 100644
--- a/tweak/Tweak.x
+++ b/tweak/Tweak.x
@@ -18,6 +18,10 @@
- (NSString *)recursiveDescription;
@end
+@interface UIViewController (SpotifyGlassPrivate)
+- (NSString *)_printHierarchy;
+@end
+
#define SGLog(fmt, ...) NSLog(@"[spotifyglass] " fmt, ##__VA_ARGS__)
// The unified log cuts a message at about 1 KB, so long dumps go out as numbered parts.
@@ -327,6 +331,54 @@ static void styleTabBar(UIView *tabBar) {
- (BOOL)prefersLiquidGlassNavigationBar { return YES; }
%end
+#pragma mark - screen dumps (debug builds only, when FLEX is injected)
+
+static NSString *hexColor(CGColorRef color) {
+ CGFloat r = 0, g = 0, b = 0, a = 0;
+ [[UIColor colorWithCGColor:color] getRed:&r green:&g blue:&b alpha:&a];
+ return [NSString stringWithFormat:@"#%02X%02X%02X@%.2f", (int)(r * 255), (int)(g * 255), (int)(b * 255), a];
+}
+
+static void appendTree(UIView *view, NSUInteger depth, NSMutableString *out) {
+ NSMutableString *line = [NSMutableString stringWithFormat:@"%*s%@ %@", (int)depth * 2, "", NSStringFromClass(view.class), NSStringFromCGRect(view.frame)];
+ CGColorRef bg = view.layer.backgroundColor;
+ if (bg && CGColorGetAlpha(bg) > 0) [line appendFormat:@" bg=%@", hexColor(bg)];
+ if (view.layer.cornerRadius > 0) [line appendFormat:@" r=%.1f", view.layer.cornerRadius];
+ if (view.alpha < 1) [line appendFormat:@" a=%.2f", view.alpha];
+ if (view.hidden) [line appendString:@" hidden"];
+ if (view.layer.mask) [line appendString:@" masked"];
+ if (view.clipsToBounds) [line appendString:@" clips"];
+ if ([view isKindOfClass:UILabel.class]) {
+ UILabel *label = (UILabel *)view;
+ [line appendFormat:@" \"%@\" %.0fpt %@", label.text, label.font.pointSize, hexColor(label.textColor.CGColor)];
+ }
+ if ([view isKindOfClass:UIImageView.class] && ((UIImageView *)view).image) {
+ CGSize size = ((UIImageView *)view).image.size;
+ [line appendFormat:@" img=%.0fx%.0f", size.width, size.height];
+ }
+ [out appendString:line];
+ [out appendString:@"\n"];
+ for (UIView *sub in view.subviews) appendTree(sub, depth + 1, out);
+}
+
+static void dumpScreen(NSString *reason) {
+ NSMutableString *out = [NSMutableString string];
+ UIViewController *root = nil;
+ for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
+ if (![scene isKindOfClass:UIWindowScene.class]) continue;
+ for (UIWindow *window in ((UIWindowScene *)scene).windows) {
+ if (window.hidden || [NSStringFromClass(window.class) containsString:@"FLEX"]) continue;
+ if (!root || window.isKeyWindow) root = window.rootViewController;
+ [out appendFormat:@"== window %@ level %.0f\n", window.class, window.windowLevel];
+ appendTree(window, 0, out);
+ }
+ }
+ if ([root respondsToSelector:@selector(_printHierarchy)]) {
+ [out appendFormat:@"== view controllers\n%@\n", [root _printHierarchy]];
+ }
+ SGLogLong([@"screen dump " stringByAppendingString:reason], out);
+}
+
#pragma mark - diagnostics
static void logClassMethods(NSString *name) {
@@ -357,4 +409,10 @@ static void logClassMethods(NSString *name) {
SGLog(@"loaded, UIGlassEffect %@", NSClassFromString(@"UIGlassEffect") ? @"available" : @"missing");
logClassMethods(@"UICornerConfiguration");
logClassMethods(@"UICornerRadius");
+ if (NSClassFromString(@"FLEXManager")) {
+ [NSNotificationCenter.defaultCenter addObserverForName:UIApplicationDidEnterBackgroundNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
+ dumpScreen(@"on background");
+ }];
+ SGLog(@"debug build: backgrounding the app dumps the visible screen's view tree");
+ }
}
diff --git a/tweak/control b/tweak/control
index c83bceb9..867f31a3 100644
--- a/tweak/control
+++ b/tweak/control
@@ -1,6 +1,6 @@
Package: com.vojta.spotifyglass
Name: spotifyglass
-Version: 0.2.2
+Version: 0.2.3
Architecture: iphoneos-arm
Description: Liquid Glass for the Spotify iOS app
Maintainer: vojta