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 check update endpoint
Vojtěch Škopekf2a163cde6c9
diff --git a/.gitignore b/.gitignoreindex bad757a6..d7561408 100644--- a/.gitignore+++ b/.gitignore@@ -17,3 +17,4 @@ tweak/Sources/Shared/Flags/SGFlagList.m/trees/cleanharness/*/build/vendor/*/build/+/videodiff --git a/tweak/Sources/App/About/About.h b/tweak/Sources/App/About/About.hindex 92ac9d14..92db3ddf 100644--- a/tweak/Sources/App/About/About.h+++ b/tweak/Sources/App/About/About.h@@ -6,7 +6,7 @@#import <UIKit/UIKit.h>#import "Settings/SGModPage.h"-extern NSString *const SGUpdateURL; // the site and the repo are in Settings/SGPageStyle.h+extern NSString *const SGUpdateURL; // spoti.pw's; the site and the repo are in Settings/SGPageStyle.hextern NSString *const SGUpdateCheckedNotification; // on the main thread, after a check ends either way// One line of a release's changelog: what changed, under the heading Release Please put it under,@@ -33,6 +33,13 @@ NSString *SGUpdateStatus(void);void SGCheckForUpdate(BOOL force);UIViewController *SGUpdatePage(void); // UpdatePage.m: the state and the changelog+// Usage.m: the body the check posts to spoti.pw, nil while the switch is off. The key sits outside+// "spotifyglass." so that Reset all settings neither switches the count off nor undoes an opt-out.+#define SGKeyUsage @"spotipw.usage"+NSData *SGUsageBody(void);+BOOL SGUsageOwed(void); // on, and not yet sent this UTC day+void SGUsageNoteAsked(void);+// UpdateNotice.m: the sheet a release newer than this build brings on its own, a few seconds after// Spotify comes up, once per release. Watched from the settings %ctor; the switch is on the Updates// page and takes effect at once.diff --git a/tweak/Sources/App/About/Update.m b/tweak/Sources/App/About/Update.mindex 243b2729..a0701f7a 100644--- a/tweak/Sources/App/About/Update.m+++ b/tweak/Sources/App/About/Update.m@@ -4,12 +4,13 @@// commit, each ending in a link to it. One request brings the last twenty releases rather than only// the newest, which is what lets the Updates page show every version between this build and the// newest one. Asked a few seconds after Spotify comes up (UpdateNotice.m) and when Mod Settings-// opens, at most once every six hours either way, and on demand from the page; nothing but the-// request itself leaves.+// opens, at most once every six hours either way, and on demand from the page. spoti.pw is asked+// first and hands on GitHub's list; the request carries Usage.m's body. GitHub itself is the fallback.#import "Core/SGCore.h"#import "About.h"-NSString *const SGUpdateURL = @"https://api.github.com/repos/skopevoj/spoti.pw/releases?per_page=20";+NSString *const SGUpdateURL = @"https://spoti.pw/api/update";+static NSString *const kGitHubURL = @"https://api.github.com/repos/skopevoj/spoti.pw/releases?per_page=20";NSString *const SGUpdateCheckedNotification = @"spotifyglass.update.checked.notification";static NSString *const kChecked = @"spotifyglass.update.checked";@@ -178,25 +179,38 @@ static NSArray<NSDictionary *> *releasesFrom(NSData *data) {return entries.count ? entries : nil;}-void SGCheckForUpdate(BOOL force) {- NSUserDefaults *store = NSUserDefaults.standardUserDefaults;- NSTimeInterval last = [store doubleForKey:kChecked];- if (sg_running) return;- if (!force && last > 0 && NSDate.date.timeIntervalSince1970 - last < kInterval) return;-- sg_running = YES;- sg_failure = nil;+static void ask(NSString *url, NSData *body, void (^done)(NSArray<NSDictionary *> *releases, NSInteger status, NSError *error)) {NSURLSessionConfiguration *configuration = NSURLSessionConfiguration.ephemeralSessionConfiguration;configuration.timeoutIntervalForRequest = 10;- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:SGUpdateURL]+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]cachePolicy:NSURLRequestReloadIgnoringLocalCacheDatatimeoutInterval:10];[request setValue:@"application/vnd.github+json" forHTTPHeaderField:@"Accept"];+ if (body) {+ request.HTTPMethod = @"POST";+ request.HTTPBody = body;+ [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];+ }NSURLSessionDataTask *task = [[NSURLSession sessionWithConfiguration:configuration]dataTaskWithRequest:requestcompletionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {- NSArray<NSDictionary *> *releases = releasesFrom(data);NSInteger status = [response isKindOfClass:NSHTTPURLResponse.class] ? ((NSHTTPURLResponse *)response).statusCode : 0;+ done(status == 200 ? releasesFrom(data) : nil, status, error);+ }];+ [task resume];+}++void SGCheckForUpdate(BOOL force) {+ NSUserDefaults *store = NSUserDefaults.standardUserDefaults;+ NSTimeInterval last = [store doubleForKey:kChecked];+ if (sg_running) return;+ // The day's count goes out with the first check of the day, whatever the six hours say.+ BOOL owed = SGUsageOwed();+ if (!force && !owed && last > 0 && NSDate.date.timeIntervalSince1970 - last < kInterval) return;++ sg_running = YES;+ sg_failure = nil;+ void (^finish)(NSArray<NSDictionary *> *, NSInteger, NSError *) = ^(NSArray<NSDictionary *> *releases, NSInteger status, NSError *error) {dispatch_async(dispatch_get_main_queue(), ^{sg_running = NO;if (!releases) {@@ -208,10 +222,17 @@ void SGCheckForUpdate(BOOL force) {} else {[store setObject:releases forKey:kReleases];[store setDouble:NSDate.date.timeIntervalSince1970 forKey:kChecked];- SGLog(@"update check: GitHub's newest is %@, this build is %s", releases.firstObject[@"version"], SG_VERSION);+ SGLog(@"update check: the newest is %@, this build is %s", releases.firstObject[@"version"], SG_VERSION);}[NSNotificationCenter.defaultCenter postNotificationName:SGUpdateCheckedNotification object:nil];});- }];- [task resume];+ };+ NSData *body = SGUsageBody();+ if (body) SGUsageNoteAsked();+ SGLog(@"update check: asking spoti.pw %@", body ? @"with the usage body" : @"without the usage body");+ ask(SGUpdateURL, body, ^(NSArray<NSDictionary *> *releases, NSInteger status, NSError *error) {+ if (releases) return finish(releases, status, error);+ SGLog(@"update check: spoti.pw answered HTTP %ld, asking GitHub", (long)status);+ ask(kGitHubURL, nil, finish);+ });}diff --git a/tweak/Sources/App/About/UpdateNotice.m b/tweak/Sources/App/About/UpdateNotice.mindex 1e976774..90a560dc 100644--- a/tweak/Sources/App/About/UpdateNotice.m+++ b/tweak/Sources/App/About/UpdateNotice.m@@ -78,34 +78,39 @@ static void offerWhenClear(NSInteger tries) {SGLog(@"update notice: offered %@ over %@", version, NSStringFromClass(top.class));}-// The first time Spotify is in front, and once: a check every launch would ask GitHub far more often-// than the six hours the cache allows anyway, and what a check already landed is enough to go on.void SGWatchForUpdates(void) {// TEMPORARY, remove before committing: forgets which release this phone has been told about, so the// sheet is offered again for one it has already had (0.20.0 was marked told on 2026-09-20 by a// manual Check now, which is what let the sheet through in the first place).[NSUserDefaults.standardUserDefaults removeObjectForKey:kTold];- if (!SGEnabled(SGKeyUpdateNotice)) return;- __block id token = [NSNotificationCenter.defaultCenter addObserverForName:UIApplicationDidBecomeActiveNotification- object:nil- queue:NSOperationQueue.mainQueue- usingBlock:^(NSNotification *note) {- [NSNotificationCenter.defaultCenter removeObserver:token];+ // Every time Spotify comes to the front, not only the first: it lives for days behind other apps,+ // and the day's usage count has to go out on a day it was merely brought back. The sheet is still+ // once per launch.+ static BOOL launched;+ [NSNotificationCenter.defaultCenter addObserverForName:UIApplicationDidBecomeActiveNotification+ object:nil+ queue:NSOperationQueue.mainQueue+ usingBlock:^(NSNotification *note) {+ BOOL first = !launched;+ launched = YES;+ if (!first && !SGUsageOwed()) return;dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kSettle * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{- if (SGUpdateVersion()) { // the last check knows one already+ BOOL tell = first && SGEnabled(SGKeyUpdateNotice);+ if (tell && SGUpdateVersion()) { // the last check knows one alreadyofferWhenClear(kTries);- return;+ } else if (tell) {+ __block id landed = [NSNotificationCenter.defaultCenter addObserverForName:SGUpdateCheckedNotification+ object:nil+ queue:NSOperationQueue.mainQueue+ usingBlock:^(NSNotification *n) {+ [NSNotificationCenter.defaultCenter removeObserver:landed];+ offerWhenClear(kTries);+ }];}- __block id landed = [NSNotificationCenter.defaultCenter addObserverForName:SGUpdateCheckedNotification- object:nil- queue:NSOperationQueue.mainQueue- usingBlock:^(NSNotification *n) {- [NSNotificationCenter.defaultCenter removeObserver:landed];- offerWhenClear(kTries);- }];// Inside the six hours this does nothing and no check lands, which is the point: the- // sheet is for a release that turned up, not for every launch.- SGCheckForUpdate(NO);+ // sheet is for a release that turned up, not for every launch. The day's usage count is+ // the exception, and it goes out whether or not the sheet is wanted.+ if (tell || SGUsageOwed()) SGCheckForUpdate(NO);});}];}diff --git a/tweak/Sources/App/About/Usage.m b/tweak/Sources/App/About/Usage.mnew file mode 100644index 00000000..b25862ea--- /dev/null+++ b/tweak/Sources/App/About/Usage.m@@ -0,0 +1,104 @@+// What the update check tells spoti.pw about this install, so installs can be counted: versions,+// device, look, and which big switches are on. Nothing of the account or of what is played.+#import <dlfcn.h>+#import <sys/utsname.h>+#import "Core/SGCore.h"+#import "About.h"+#import "Native/Appearance/Appearance.h"+#import "Native/Player/NowPlaying.h"+#import "Shared/AdBlock/AdBlock.h"+#import "Shared/ArtistBlock/ArtistBlock.h"+#import "Shared/Gestures/Gestures.h"+#import "Shared/Haptics/Haptics.h"+#import "Shared/JamesDSP/JamesDSP.h"+#import "Shared/LiveActivity/LiveActivity.h"+#import "Shared/LockScreenLyrics/LockScreenLyrics.h"+#import "Shared/LyricsSources/LyricsSources.h"+#import "Shared/Privacy/Privacy.h"++// Outside "spotifyglass." on purpose: Reset all settings must not mint a second install, and a+// settings backup restored on another phone must not carry this one's id along.+static NSString *const kInstall = @"spotipw.install";+static NSString *const kAsked = @"spotipw.asked";++// Not SGEnabled: after a reset that reads every unset switch as off, and this is not one of them.+static BOOL usageOn(void) {+ id stored = [NSUserDefaults.standardUserDefaults objectForKey:SGKeyUsage];+ return stored ? [stored boolValue] : YES;+}++// Asked on every return to the front, so the formatter is made once.+static NSString *today(void) {+ static NSDateFormatter *format;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ format = [NSDateFormatter new];+ format.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];+ format.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];+ format.dateFormat = @"yyyy-MM-dd";+ });+ return [format stringFromDate:NSDate.date];+}++BOOL SGUsageOwed(void) {+ return usageOn() && ![[NSUserDefaults.standardUserDefaults stringForKey:kAsked] isEqualToString:today()];+}++// Marked when asked, not when answered: a day spoti.pw is down costs that day's count, not a request+// on every launch.+void SGUsageNoteAsked(void) {+ [NSUserDefaults.standardUserDefaults setObject:today() forKey:kAsked];+}++static NSString *installID(void) {+ NSUserDefaults *store = NSUserDefaults.standardUserDefaults;+ NSString *stored = [store stringForKey:kInstall];+ if ([[NSUUID alloc] initWithUUIDString:stored ?: @""]) return stored;+ NSString *made = NSUUID.UUID.UUIDString.lowercaseString;+ [store setObject:made forKey:kInstall];+ return made;+}++static NSString *device(void) {+ struct utsname name;+ return uname(&name) == 0 ? @(name.machine) : nil;+}++// A dylib inside the app's bundle was put into the IPA; one outside it was injected by a jailbreak.+static NSString *installKind(void) {+ NSString *bundle = NSBundle.mainBundle.bundlePath;+ Dl_info info;+ if (dladdr(&installKind, &info) && info.dli_fname && ![@(info.dli_fname) hasPrefix:bundle]) return @"jailbreak";+ NSString *marker = [bundle.stringByDeletingLastPathComponent stringByAppendingPathComponent:@"_TrollStore"];+ return [NSFileManager.defaultManager fileExistsAtPath:marker] ? @"trollstore" : @"sideload";+}++NSData *SGUsageBody(void) {+ if (!usageOn()) return nil;+ NSMutableDictionary *body = [NSMutableDictionary dictionary];+ body[@"id"] = installID();+ body[@"mod"] = @SG_VERSION;+ body[@"spotify"] = NSBundle.mainBundle.infoDictionary[@"CFBundleShortVersionString"];+ body[@"ios"] = UIDevice.currentDevice.systemVersion;+ body[@"device"] = device();+ body[@"ui"] = SGRedesignedUI() ? @"redesigned" : @"native";+ body[@"kind"] = installKind();+ body[@"lang"] = NSLocale.currentLocale.languageCode;+ body[@"region"] = NSLocale.currentLocale.countryCode;+ body[@"features"] = @{+ @"dsp": @(SGHidden(SGKeyDSP)),+ @"liveActivity": @(SGFlag(SGKeyLiveActivity, NO)),+ @"lockScreenLyrics": @(SGFlag(SGKeyLockScreenLyrics, NO)),+ @"musicHaptics": @(SGFlag(SGKeyMusicHaptics, NO)),+ @"controlHaptics": @(SGEnabled(SGKeyControlHaptics)),+ @"artistBlock": @(SGFlag(SGKeyArtistBlock, NO)),+ @"gestures": @(SGFlag(SGKeyGestures, NO)),+ @"blockTelemetry": @(SGEnabled(SGKeyBlockTelemetry)),+ @"hideAds": @(SGHidden(SGKeyHideAds)),+ @"fakePremium": @(SGHidden(SGKeyFakePremium)),+ @"lyricsCard": @(SGFlag(SGKeyLyricsCard, NO)),+ @"amoled": @(SGFlag(SGKeyAmoled, NO)),+ };+ body[@"lyrics"] = SGLyricsOrder();+ return [NSJSONSerialization dataWithJSONObject:body options:0 error:NULL];+}