Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
fix: close only the DJ region dialog, matched by its exact title (#203)
My-Name-Is-Jeffcd7ace640513
diff --git a/tweak/Sources/Shared/AdBlock/DJ.x b/tweak/Sources/Shared/AdBlock/DJ.xindex badec581..1919a38f 100644--- a/tweak/Sources/Shared/AdBlock/DJ.x+++ b/tweak/Sources/Shared/AdBlock/DJ.x@@ -15,14 +15,34 @@}%end-static NSString *dialogTitle(UIView *root) {- __block NSString *title;- SGForEachView(root, ^(UIView *view) {- if (!title && [view isKindOfClass:UILabel.class] && [view.accessibilityIdentifier isEqualToString:@"PopUp.Dialog.Title-internal"]) {- title = ((UILabel *)view).text;+static id stringsAsset(NSBundle *bundle, NSString *name) {+ NSData *data = [[NSDataAsset alloc] initWithName:name bundle:bundle].data;+ return data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;+}++// The region dialog's title as Spotify words it, in English and in the app's language, from Spotify's own strings:+// SPTStrings.bundle's _i18n.KEYS lists every key, _i18n.INDEX names each language's file, and each _i18n.<file>+// holds the values at the keys' indexes. Read once, at the first pop-up.+static NSSet<NSString *> *regionTitles(void) {+ static NSSet<NSString *> *titles;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ NSBundle *strings = [NSBundle bundleWithPath:[NSBundle.mainBundle pathForResource:@"SPTStrings" ofType:@"bundle"]];+ NSArray *keys = stringsAsset(strings, @"_i18n.KEYS");+ NSDictionary *files = stringsAsset(strings, @"_i18n.INDEX");+ NSUInteger at = [keys isKindOfClass:NSArray.class] ? [keys indexOfObject:@"SPTEndless_DJMusicImpl:sDJMRegionUnavailableDialogTitle"] : NSNotFound;+ NSMutableSet<NSString *> *found = [NSMutableSet set];+ for (NSString *language in [NSBundle.mainBundle.preferredLocalizations arrayByAddingObject:@"en"]) {+ if (at == NSNotFound) break;+ NSString *file = [files isKindOfClass:NSDictionary.class] && [files[language] isKindOfClass:NSString.class] ? files[language] : language;+ NSArray *values = stringsAsset(strings, [@"_i18n." stringByAppendingString:file]);+ id value = [values isKindOfClass:NSArray.class] && at < values.count ? values[at] : nil;+ if ([value isKindOfClass:NSString.class]) [found addObject:value];}+ SGLog(@"DJ: the region dialog's titles in Spotify's strings: %@", found.count ? [found.allObjects componentsJoinedByString:@" | "] : @"none, so it stays");+ titles = found;});- return title;+ return titles;}// The dialog comes in a window of its own, with no SPTEncorePopUpPresenter call to catch, and its title is set only@@ -32,12 +52,13 @@ static NSString *dialogTitle(UIView *root) {%orig;UIViewController *container = (UIViewController *)self;if (container.view.window.hidden) return;- // shortcut: the title is localized, and "DJ" is the one word every language keeps.- if (![dialogTitle(container.view) containsString:@"DJ"]) return;+ static char kTitleKey;+ NSString *title = ((UILabel *)SGFindIdentifier(container.view, @"PopUp.Dialog.Title-internal", &kTitleKey)).text;+ if (!title || ![regionTitles() containsObject:title]) return;container.view.window.hidden = YES;id presenter = [(id)%c(SPTEncorePopUpPresenter) valueForKey:@"shared"];[presenter dismissPopupWithAnimate:NO clearQueue:NO completion:nil];- SGLog(@"DJ: closed \"%@\"", dialogTitle(container.view));+ SGLog(@"DJ: closed \"%@\"", title);}%end