Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: the Updates page, the changelog of every release newer than the build, read from the repo's GitHub Releases
Vojtěch Škopekbca0efeb77e5
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex acad5aa2..1020b592 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -189,7 +189,9 @@ App:ModSettings.x the root page and the rows that open it from Spotify's settings and the side drawerPages.m the Appearance card with Redesigned UI, the Player and Lyrics pages, which Navbar page opens- About/ the update check, backup, the signing warning and the Mod page with the reset+ About/ the update check against the repo's GitHub Releases and the Updates page it fills (the state,+ and the changelog of every release newer than the build, a line per commit), backup, the+ signing warning and the Mod page with the resetOnboarding/ the welcome page over Home on the first launch, with Redesigned UI, offered again from the Mod pageEvery key a feature stores starts with `spotifyglass.`, whatever it holds: Reset all settings on@@ -250,8 +252,10 @@ an Ad and upsell flags page under them, every switch there forcing a flag SpotifSpoof Premium; Block telemetry; then what the adblocking and the telemetry blocking have stopped) and Labs (features Spotify built and did not ship,AI Chat (Martini) first). Last, All flags, Spotify's remote-config flags with a search field and an-Auto / Off / On control per flag (a text field for the number and text ones), and Mod: the update-check, the build and Spotify's version, the site and the repo, the welcome tour again and Reset all+Auto / Off / On control per flag (a text field for the number and text ones), and Mod: Updates+(the row reads out where the build stands and opens the changelog of everything newer than it, read+from the releases Release Please cuts, with Check now, the release to get and all the releases), the+build and Spotify's version, the site and the repo, the welcome tour again and Reset allsettings. A flag switch on a page forces that one flag and off leaves Spotify's own value, so the Allflags page is where a flag goes back to Auto. Spotify ships its newer design behind several flags atonce, and the redesign is built on it (the glass navigation bar, the new player slider, the sheet stylediff --git a/harness/update/README.md b/harness/update/README.mdnew file mode 100644index 00000000..efe1be28--- /dev/null+++ b/harness/update/README.md@@ -0,0 +1,16 @@+# Updates harness++`SGUpdatePage()` on the simulator, running the real check against the repo's GitHub Releases: the+state rows, the changelog of every release newer than the build, and the page rebuilding itself when+a check lands. Only `Update.m`, `UpdatePage.m` and the page style are compiled; nothing of Spotify's+is needed, so the page looks as it does on the phone apart from the fonts, which Mod Settings takes+off Spotify's own list at runtime.++ ./build.sh [version] # what the page believes it is running, 0.18.0 by default+ xcrun simctl install booted build/UpdateHarness.app+ xcrun simctl launch --console-pty booted com.vojta.updateharness [wipe] [recheck]++`wipe` clears what an earlier run stored, so the page opens as it does on a phone that has never+checked; `recheck` taps Check now five seconds in. A version behind the newest release (`0.18.0`)+shows the update and everything since; the newest one (`0.19.0`) shows "up to date" and what went+into this build; an old one (`0.17.0`) shows several releases, newest first.diff --git a/harness/update/build.sh b/harness/update/build.shnew file mode 100755index 00000000..3c7ae4c0--- /dev/null+++ b/harness/update/build.sh@@ -0,0 +1,38 @@+#!/bin/sh+# Builds the Updates harness for the simulator: Update.m's check and UpdatePage.m's changelog, run+# for real against GitHub. SG_VERSION is what the page believes it is running; pass one as the first+# argument to try another (./build.sh 0.12.0).+set -e+SRC=$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)+OUT=$(dirname "$0")/build+VERSION=${1:-0.18.0}+rm -rf "$OUT"; mkdir -p "$OUT/UpdateHarness.app"++SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)+xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-arc -g -O0 \+ -I"$SRC" -isysroot "$SDK" -Wno-deprecated-declarations -DSG_VERSION="\"$VERSION\"" \+ "$(dirname "$0")/main.m" \+ "$SRC"/App/About/Update.m "$SRC"/App/About/UpdatePage.m \+ "$SRC"/Settings/SGPage.m "$SRC"/Settings/SGPageStyle.m \+ "$SRC"/Core/SGLog.m "$SRC"/Core/SGPrefs.m "$SRC"/Core/SGViewTree.m "$SRC"/Core/SGGlass.m \+ "$SRC"/Core/SGBackdrop.m "$SRC"/Core/SGFlagForce.m "$SRC"/Core/SGUIMode.m \+ -framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation \+ -o "$OUT/UpdateHarness.app/UpdateHarness"++cat > "$OUT/UpdateHarness.app/Info.plist" <<'PLIST'+<?xml version="1.0" encoding="UTF-8"?>+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">+<plist version="1.0"><dict>+<key>CFBundleExecutable</key><string>UpdateHarness</string>+<key>CFBundleIdentifier</key><string>com.vojta.updateharness</string>+<key>CFBundleName</key><string>UpdateHarness</string>+<key>CFBundleVersion</key><string>1</string>+<key>CFBundleShortVersionString</key><string>1.0</string>+<key>UIUserInterfaceStyle</key><string>Dark</string>+<key>UILaunchScreen</key><dict/>+<key>UIApplicationSceneManifest</key><dict>+ <key>UIApplicationSupportsMultipleScenes</key><false/>+</dict>+</dict></plist>+PLIST+echo "built $OUT/UpdateHarness.app"diff --git a/harness/update/main.m b/harness/update/main.mnew file mode 100644index 00000000..584fa9bc--- /dev/null+++ b/harness/update/main.m@@ -0,0 +1,40 @@+// The Updates page on the simulator: SGUpdatePage() in a navigation controller, with the real check+// running against the repo's GitHub Releases. The build it claims to be is SG_VERSION, set by+// build.sh, so `0.18.0` shows a version behind the newest and `99.0.0` shows one that is current.+// `wipe` clears what an earlier run stored, so the page opens as it does on a phone that has never+// checked, and `recheck` taps Check now five seconds in.+#import <UIKit/UIKit.h>+#import "App/About/About.h"++@interface Delegate : UIResponder <UIApplicationDelegate>+@property (nonatomic, strong) UIWindow *window;+@end++@implementation Delegate++- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)options {+ NSArray<NSString *> *arguments = NSProcessInfo.processInfo.arguments;+ if ([arguments containsObject:@"wipe"]) {+ for (NSString *key in @[@"spotifyglass.update.checked", @"spotifyglass.update.releases"])+ [NSUserDefaults.standardUserDefaults removeObjectForKey:key];+ }+ self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];+ UINavigationController *stack = [[UINavigationController alloc] initWithRootViewController:SGUpdatePage()];+ stack.navigationBar.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ self.window.rootViewController = stack;+ self.window.backgroundColor = UIColor.blackColor;+ [self.window makeKeyAndVisible];+ if ([arguments containsObject:@"recheck"])+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ SGCheckForUpdate(YES);+ });+ return YES;+}++@end++int main(int argc, char *argv[]) {+ @autoreleasepool {+ return UIApplicationMain(argc, argv, nil, NSStringFromClass(Delegate.class));+ }+}diff --git a/tweak/Sources/App/About/About.h b/tweak/Sources/App/About/About.hindex 204a2280..b7214730 100644--- a/tweak/Sources/App/About/About.h+++ b/tweak/Sources/App/About/About.h@@ -1,14 +1,37 @@-// About: where the build points its user, and whether GitHub has a newer release (Update.m). The-// status is a string for the Updates row; the page's ticker reads it, so the check needs no-// callback. SGCheckForUpdate(NO) respects a six hour cache, SGCheckForUpdate(YES) always asks.+// About: where the build points its user, and whether GitHub has a newer release (Update.m,+// UpdatePage.m). The status is a string for the Updates row; the page's ticker reads it, so the+// check needs no callback, and a check that lands posts SGUpdateCheckedNotification for the page+// that is open at the time. SGCheckForUpdate(NO) respects a six hour cache, SGCheckForUpdate(YES)+// always asks.#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 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,+// and the commit it came from.+@interface SGUpdateChange : NSObject+@property (nonatomic, copy) NSString *kind; // "Features", "Fixes", ... as the release names it+@property (nonatomic, copy) NSString *text;+@property (nonatomic, copy) NSString *url; // the commit, nil for a line written by hand+@end++// One GitHub release, as the last check stored it.+@interface SGUpdateRelease : NSObject+@property (nonatomic, copy) NSString *version; // without the tag's v+@property (nonatomic, copy) NSString *date; // ISO 8601, as GitHub publishes it+@property (nonatomic, copy) NSString *url; // the release page, where the .deb is+@property (nonatomic, copy) NSArray<SGUpdateChange *> *changes;+@end++NSArray<SGUpdateRelease *> *SGUpdateReleases(void); // newest first, empty until a check lands+SGUpdateRelease *SGUpdateNewestRelease(void);NSString *SGUpdateVersion(void); // nil unless GitHub has a release newer than this build-NSString *SGUpdateNotes(void);+BOOL SGUpdateIsNewer(NSString *version); // whether that release is newer than the build runningNSString *SGUpdateStatus(void);void SGCheckForUpdate(BOOL force);+UIViewController *SGUpdatePage(void); // UpdatePage.m: the state and the changelog// Whether the now playing card on the lock screen can open this build. It depends on the signature,diff --git a/tweak/Sources/App/About/AboutSettings.m b/tweak/Sources/App/About/AboutSettings.mindex a72dc033..1f795cb3 100644--- a/tweak/Sources/App/About/AboutSettings.m+++ b/tweak/Sources/App/About/AboutSettings.m@@ -38,11 +38,13 @@ UIViewController *SGAboutPage(void) {SGModRow *reset = withSymbol(SGActionRow(@"Reset all settings", @"Every switch off, Spotify as it came, then a restart", ^{ confirmReset(); }), @"trash");reset.color = SGRed();NSString *spotify = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"] ?: @"unknown";+ // The row reads out where the build stands and opens the changelog of everything newer than it.+ SGModRow *updates = SGPageRow(@"Updates", ^UIViewController *{ return SGUpdatePage(); });+ updates.subtitle = @"What is new on GitHub, and whether this build is behind";+ updates.value = ^NSString *{ return SGUpdateStatus(); };return [[SGModPage alloc] initWithTitle:@"Mod" intro:nil sections:@[SGSection(nil, @[- SGStatActionRow(@"Updates", @"Asks GitHub for the newest release; tap to check now", ^NSString *{- return SGUpdateStatus();- }, ^{ SGCheckForUpdate(YES); }),+ updates,SGStatRow(@"Version", ^NSString *{ return @(SG_VERSION); }),SGStatRow(@"Spotify", ^NSString *{ return spotify; }),]),diff --git a/tweak/Sources/App/About/Update.m b/tweak/Sources/App/About/Update.mindex 37ff59e3..54e29dd6 100644--- a/tweak/Sources/App/About/Update.m+++ b/tweak/Sources/App/About/Update.m@@ -1,20 +1,29 @@-// The repo's latest GitHub Release, so a build that is already on someone's phone can tell them a-// newer one exists. Fetched when the Mod Settings page opens, at most once every six hours, and on-// demand from the Updates row; nothing but the request itself leaves. Builds from before 0.18 ask-// spoti.pw/version.json instead, which the site still writes from the same release.+// The repo's GitHub Releases, so a build that is already on someone's phone can tell them a newer one+// exists and show what changed in it. Release Please cuts every release from the commits, so the+// release body is the changelog itself: a "### Features" or "### Fixes" heading over a line per+// 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 when Mod Settings opens, at most once every six hours, and on demand from the+// page; nothing but the request itself leaves.#import "Core/SGCore.h"#import "About.h"-NSString *const SGUpdateURL = @"https://api.github.com/repos/skopevoj/spoti.pw/releases/latest";+NSString *const SGUpdateURL = @"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";-static NSString *const kLatest = @"spotifyglass.update.latest";-static NSString *const kNotes = @"spotifyglass.update.notes";+static NSString *const kReleases = @"spotifyglass.update.releases";static const NSTimeInterval kInterval = 6 * 60 * 60;static NSString *sg_failure;static BOOL sg_running;+@implementation SGUpdateChange+@end++@implementation SGUpdateRelease+@end+// "0.14.1" against "0.15": the numbers position by position, a missing one counting zero.static BOOL isNewer(NSString *candidate, NSString *current) {NSArray<NSString *> *left = [candidate componentsSeparatedByString:@"."];@@ -27,13 +36,106 @@ static BOOL isNewer(NSString *candidate, NSString *current) {return NO;}-NSString *SGUpdateVersion(void) {- NSString *latest = [NSUserDefaults.standardUserDefaults stringForKey:kLatest];- return latest && isNewer(latest, @(SG_VERSION)) ? latest : nil;+static NSString *stringOr(id value, NSString *fallback) {+ return [value isKindOfClass:NSString.class] ? value : fallback;}-NSString *SGUpdateNotes(void) {- return [NSUserDefaults.standardUserDefaults stringForKey:kNotes] ?: @"";+#pragma mark - the changelog out of the release's markdown++// "[the text](https://…)" is left as its text, and what release-please writes around a scope --+// "**player:** …" -- loses its stars. Nothing else in a body of its is markup.+static NSString *plainText(NSString *markdown) {+ static NSRegularExpression *link;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ link = [NSRegularExpression regularExpressionWithPattern:@"\\[([^\\]]*)\\]\\([^)]*\\)" options:0 error:NULL];+ });+ NSString *text = [link stringByReplacingMatchesInString:markdown options:0+ range:NSMakeRange(0, markdown.length) withTemplate:@"$1"];+ text = [text stringByReplacingOccurrencesOfString:@"**" withString:@""];+ return [text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];+}++// The commit a line ends with -- " ([4b63f35](https://github.com/…/commit/4b63f35…))" -- taken off the+// text and kept as the line's link. A line written by hand has none and keeps all of itself.+static NSString *takeCommitURL(NSString **line) {+ static NSRegularExpression *trailer;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ trailer = [NSRegularExpression regularExpressionWithPattern:@"\\s*\\(\\[[0-9a-f]{6,}\\]\\(([^)]+)\\)\\)\\s*$" options:0 error:NULL];+ });+ NSString *text = *line;+ NSTextCheckingResult *match = [trailer firstMatchInString:text options:0 range:NSMakeRange(0, text.length)];+ if (!match) return nil;+ *line = [text substringToIndex:match.range.location];+ return [text substringWithRange:[match rangeAtIndex:1]];+}++// A release body into its lines: "### Features" names what follows, "* …" is a line of it, and a+// line that wraps onto the next one is joined back together. Anything else -- the "## [0.19.0](…)"+// heading release-please leads with, blank lines -- is dropped, the version being known already.+static NSArray<SGUpdateChange *> *changesIn(NSString *body) {+ NSMutableArray<SGUpdateChange *> *changes = [NSMutableArray array];+ NSString *kind = @"Changes";+ SGUpdateChange *open = nil;+ for (NSString *raw in [body componentsSeparatedByCharactersInSet:NSCharacterSet.newlineCharacterSet]) {+ NSString *line = [raw stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceCharacterSet];+ if ([line hasPrefix:@"###"]) {+ kind = plainText([line stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"# "]]);+ open = nil;+ } else if ([line hasPrefix:@"* "] || [line hasPrefix:@"- "]) {+ NSString *text = [line substringFromIndex:2];+ NSString *url = takeCommitURL(&text);+ text = plainText(text);+ if (!text.length) { open = nil; continue; }+ open = [SGUpdateChange new];+ open.kind = kind;+ open.text = text;+ open.url = url;+ [changes addObject:open];+ } else if (line.length && ![line hasPrefix:@"#"] && open) {+ // A line too long for one, wrapped by whoever edited the release by hand.+ NSString *text = line;+ NSString *url = takeCommitURL(&text);+ open.text = [open.text stringByAppendingFormat:@" %@", plainText(text)];+ if (url) open.url = url;+ } else {+ open = nil;+ }+ }+ return changes;+}++#pragma mark - what the last check left++NSArray<SGUpdateRelease *> *SGUpdateReleases(void) {+ NSArray *stored = [NSUserDefaults.standardUserDefaults arrayForKey:kReleases];+ NSMutableArray<SGUpdateRelease *> *releases = [NSMutableArray array];+ for (id entry in stored) {+ if (![entry isKindOfClass:NSDictionary.class]) continue;+ NSString *version = stringOr(entry[@"version"], nil);+ if (!version.length) continue;+ SGUpdateRelease *release = [SGUpdateRelease new];+ release.version = version;+ release.date = stringOr(entry[@"date"], @"");+ release.url = stringOr(entry[@"url"], nil);+ release.changes = changesIn(stringOr(entry[@"notes"], @""));+ [releases addObject:release];+ }+ return releases;+}++SGUpdateRelease *SGUpdateNewestRelease(void) {+ return SGUpdateReleases().firstObject;+}++BOOL SGUpdateIsNewer(NSString *version) {+ return version.length && isNewer(version, @(SG_VERSION));+}++NSString *SGUpdateVersion(void) {+ NSString *newest = SGUpdateNewestRelease().version;+ return SGUpdateIsNewer(newest) ? newest : nil;}// What the Updates row shows on the right; the page's own ticker reads it while the page is open,@@ -47,6 +149,34 @@ NSString *SGUpdateStatus(void) {return @"not checked";}+#pragma mark - the check++// Drafts and pre-releases are not builds anyone is meant to be sent to, so they count for neither the+// newest version nor the changelog. GitHub answers newest first; the sort keeps that true whatever+// order a hand-made release lands in.+static NSArray<NSDictionary *> *releasesFrom(NSData *data) {+ id json = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL] : nil;+ if (![json isKindOfClass:NSArray.class]) return nil;+ NSMutableArray<NSDictionary *> *entries = [NSMutableArray array];+ for (id item in (NSArray *)json) {+ if (![item isKindOfClass:NSDictionary.class]) continue;+ NSDictionary *release = item;+ if ([release[@"draft"] boolValue] || [release[@"prerelease"] boolValue]) continue;+ NSString *tag = stringOr(release[@"tag_name"], nil);+ if (!tag.length) continue;+ [entries addObject:@{+ @"version": [tag hasPrefix:@"v"] ? [tag substringFromIndex:1] : tag,+ @"notes": stringOr(release[@"body"], @""),+ @"date": stringOr(release[@"published_at"], @""),+ @"url": stringOr(release[@"html_url"], @""),+ }];+ }+ [entries sortUsingComparator:^NSComparisonResult(NSDictionary *a, NSDictionary *b) {+ return isNewer(a[@"version"], b[@"version"]) ? NSOrderedAscending : NSOrderedDescending;+ }];+ return entries.count ? entries : nil;+}+void SGCheckForUpdate(BOOL force) {NSUserDefaults *store = NSUserDefaults.standardUserDefaults;NSTimeInterval last = [store doubleForKey:kChecked];@@ -64,23 +194,22 @@ void SGCheckForUpdate(BOOL force) {NSURLSessionDataTask *task = [[NSURLSession sessionWithConfiguration:configuration]dataTaskWithRequest:requestcompletionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {- NSDictionary *json = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL] : nil;- if (![json isKindOfClass:NSDictionary.class]) json = nil;- // Release Please tags v0.18.0; the body is the release's changelog.- NSString *tag = [json[@"tag_name"] isKindOfClass:NSString.class] ? json[@"tag_name"] : nil;- NSString *version = [tag hasPrefix:@"v"] ? [tag substringFromIndex:1] : tag;- NSString *notes = [json[@"body"] isKindOfClass:NSString.class] ? json[@"body"] : @"";+ NSArray<NSDictionary *> *releases = releasesFrom(data);+ NSInteger status = [response isKindOfClass:NSHTTPURLResponse.class] ? ((NSHTTPURLResponse *)response).statusCode : 0;dispatch_async(dispatch_get_main_queue(), ^{sg_running = NO;- if (!version) {- sg_failure = @"check failed";- SGLog(@"update check failed: %@", error.localizedDescription ?: @"no version in the reply");- return;+ if (!releases) {+ // Unauthenticated GitHub allows sixty requests an hour per address; a phone behind a+ // carrier NAT can be told to wait, and that is worth reading apart from a dead network.+ sg_failure = status == 403 || status == 429 ? @"asked too often" : @"check failed";+ SGLog(@"update check failed: HTTP %ld, %@", (long)status,+ error.localizedDescription ?: @"no release in the reply");+ } 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);}- [store setObject:version forKey:kLatest];- [store setObject:notes forKey:kNotes];- [store setDouble:NSDate.date.timeIntervalSince1970 forKey:kChecked];- SGLog(@"update check: GitHub has %@, this build is %s", version, SG_VERSION);+ [NSNotificationCenter.defaultCenter postNotificationName:SGUpdateCheckedNotification object:nil];});}];[task resume];diff --git a/tweak/Sources/App/About/UpdatePage.m b/tweak/Sources/App/About/UpdatePage.mnew file mode 100644index 00000000..2c3aa41a--- /dev/null+++ b/tweak/Sources/App/About/UpdatePage.m@@ -0,0 +1,304 @@+// What the Updates row opens: where this build stands against GitHub's releases, and the changelog of+// every release newer than it -- a section per release and heading, a row per line, each opening the+// commit it came from. Everything here is read out of what the last check stored (Update.m), so the+// page draws whatever is known the moment it opens and asks GitHub only if the six hours are up.+// A check that lands rebuilds it where it stands, which is what makes Check now worth having: the+// changelog of a release nobody had heard of a second ago fills the page in without leaving it.+#import "Core/SGCore.h"+#import "Settings/SGPage.h"+#import "Settings/SGPageStyle.h"+#import "About.h"++// A row of this page: a line of a changelog, or one of the three at the top that do something.+@interface SGUpdateRow : NSObject+@property (nonatomic, copy) NSString *title;+@property (nonatomic, copy) NSString *subtitle;+@property (nonatomic, copy) NSString *symbol;+@property (nonatomic, copy) NSString *(^value)(void); // read out on the right, again once a second+@property (nonatomic, copy) void (^action)(void);+@end++@interface SGUpdateGroup : NSObject+@property (nonatomic, copy) NSString *title;+@property (nonatomic, copy) NSArray<SGUpdateRow *> *rows;+@end++@implementation SGUpdateRow+@end++@implementation SGUpdateGroup+@end++static SGUpdateRow *linkRow(NSString *title, NSString *subtitle, NSString *symbol, NSString *url) {+ SGUpdateRow *row = [SGUpdateRow new];+ row.title = title;+ row.subtitle = subtitle;+ row.symbol = symbol;+ row.action = ^{ SGOpenURL(url); };+ return row;+}++static SGUpdateGroup *group(NSString *title, NSArray<SGUpdateRow *> *rows) {+ SGUpdateGroup *section = [SGUpdateGroup new];+ section.title = title;+ section.rows = rows;+ return section;+}++// "2026-09-18T17:25:02Z" written out, and the empty string for a release GitHub never dated. Every+// word of the mod's is English, so the month is too, whatever the phone is set to.+static NSString *dateInWords(NSString *published, NSString *format) {+ static NSISO8601DateFormatter *reader;+ static NSDateFormatter *writer;+ static dispatch_once_t once;+ dispatch_once(&once, ^{+ reader = [NSISO8601DateFormatter new];+ writer = [NSDateFormatter new];+ writer.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];+ });+ NSDate *date = published.length ? [reader dateFromString:published] : nil;+ if (!date) return @"";+ writer.dateFormat = format;+ return [writer stringFromDate:date];+}++static NSString *shortDate(NSString *published) { // 18 Sep 2026+ return dateInWords(published, @"d MMM yyyy");+}++static NSString *longDate(NSString *published) { // 18 September 2026+ return dateInWords(published, @"d MMMM yyyy");+}++#pragma mark - the page++@interface SGUpdatePageController : SGPage+@end++@implementation SGUpdatePageController {+ NSArray<SGUpdateGroup *> *_groups;+ UIView *_intro;+ UIView *_footer;+ NSTimer *_ticker;+}++- (instancetype)init {+ if (!(self = [super initWithStyle:UITableViewStyleInsetGrouped])) return nil;+ self.title = @"Updates";+ _groups = [self build];+ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(checkLanded)+ name:SGUpdateCheckedNotification object:nil];+ return self;+}++- (void)dealloc {+ [NSNotificationCenter.defaultCenter removeObserver:self];+ [_ticker invalidate];+}++// The releases whose changelog this page shows: everything newer than the build, newest first.+// Nothing newer means the build is the newest release, and its own notes are what there is to read.+static NSArray<SGUpdateRelease *> *releasesToShow(void) {+ NSArray<SGUpdateRelease *> *releases = SGUpdateReleases();+ NSMutableArray<SGUpdateRelease *> *shown = [NSMutableArray array];+ for (SGUpdateRelease *release in releases) {+ if (!SGUpdateIsNewer(release.version)) break;+ [shown addObject:release];+ }+ if (!shown.count && releases.firstObject) [shown addObject:releases.firstObject];+ return shown;+}++- (NSString *)introText {+ SGUpdateRelease *newest = SGUpdateNewestRelease();+ if (!newest) return [NSString stringWithFormat:@"This build is %s. Nothing has been asked of GitHub yet.", SG_VERSION];+ NSString *date = longDate(newest.date);+ NSString *when = date.length ? [@" came out on " stringByAppendingString:date] : @" is out";+ if (SGUpdateVersion())+ return [NSString stringWithFormat:@"%@%@, and this build is %s. Everything in between is below.",+ newest.version, when, SG_VERSION];+ return [NSString stringWithFormat:@"This build, %s, is GitHub's newest release; it%@. What went into it is below.",+ SG_VERSION, when];+}++// The three rows at the top, then a section per release and heading: "0.19.0 · Features".+- (NSArray<SGUpdateGroup *> *)build {+ NSMutableArray<SGUpdateGroup *> *groups = [NSMutableArray array];+ SGUpdateRow *check = [SGUpdateRow new];+ check.title = @"Check now";+ check.symbol = @"arrow.clockwise";+ check.value = ^NSString *{ return SGUpdateStatus(); };+ check.action = ^{ SGCheckForUpdate(YES); };+ NSMutableArray<SGUpdateRow *> *top = [NSMutableArray arrayWithObject:check];+ SGUpdateRelease *newest = SGUpdateNewestRelease();+ if (SGUpdateVersion() && newest.url.length)+ [top addObject:linkRow([@"Get " stringByAppendingString:newest.version],+ @"The release on GitHub, where its .deb is", @"arrow.down.circle", newest.url)];+ [top addObject:linkRow(@"All releases", @"Every version, this one and the ones before it",+ @"clock.arrow.circlepath", [SGRepoURL stringByAppendingString:@"/releases"])];+ [groups addObject:group(nil, top)];++ for (SGUpdateRelease *release in releasesToShow()) {+ NSMutableArray<NSString *> *kinds = [NSMutableArray array];+ NSMutableDictionary<NSString *, NSMutableArray<SGUpdateRow *> *> *byKind = [NSMutableDictionary dictionary];+ for (SGUpdateChange *change in release.changes) {+ NSMutableArray<SGUpdateRow *> *rows = byKind[change.kind];+ if (!rows) {+ rows = [NSMutableArray array];+ byKind[change.kind] = rows;+ [kinds addObject:change.kind];+ }+ SGUpdateRow *row = [SGUpdateRow new];+ row.title = change.text;+ if (change.url.length) row.action = ^{ SGOpenURL(change.url); };+ [rows addObject:row];+ }+ NSString *date = shortDate(release.date);+ if (!kinds.count) {+ SGUpdateRow *empty = [SGUpdateRow new];+ empty.title = @"Nothing written down";+ empty.subtitle = release.url.length ? @"Tap to read the release on GitHub" : nil;+ if (release.url.length) empty.action = ^{ SGOpenURL(release.url); };+ [groups addObject:group([NSString stringWithFormat:@"%@%@", release.version,+ date.length ? [@" · " stringByAppendingString:date] : @""], @[empty])];+ continue;+ }+ [kinds enumerateObjectsUsingBlock:^(NSString *kind, NSUInteger i, BOOL *stop) {+ // The date goes on the first heading of a release, so several releases read as dated blocks.+ NSString *title = [NSString stringWithFormat:@"%@ · %@%@", release.version, kind,+ i == 0 && date.length ? [@" · " stringByAppendingString:date] : @""];+ [groups addObject:group(title, byKind[kind])];+ }];+ }+ return groups;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ _intro = SGNote([self introText]);+ _footer = SGNote(@"Releases are cut from the commits, so every line here is one change and opens it on GitHub. The mod asks for them when Mod Settings opens, at most once every six hours.");+ self.tableView.tableHeaderView = _intro;+ self.tableView.tableFooterView = _footer;+}++- (void)viewWillLayoutSubviews {+ [super viewWillLayoutSubviews];+ SGFitNote(self.tableView, _intro, 24, 0);+ SGFitNote(self.tableView, _footer, 16, 24);+}++- (void)viewDidLayoutSubviews {+ [super viewDidLayoutSubviews];+ SGInsetForBars(self.tableView);+}++- (void)viewWillAppear:(BOOL)animated {+ [super viewWillAppear:animated];+ [self.tableView reloadData];+ // Only the status reads out on the right, and only it moves on its own while the page is open;+ // it is written into the cell so that a reload never lands under a tap.+ [_ticker invalidate];+ _ticker = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(readStatus) userInfo:nil repeats:YES];+}++- (void)viewDidDisappear:(BOOL)animated {+ [super viewDidDisappear:animated];+ [_ticker invalidate];+ _ticker = nil;+}++- (void)readStatus {+ for (UITableViewCell *cell in self.tableView.visibleCells) {+ SGUpdateRow *row = [self rowAt:[self.tableView indexPathForCell:cell]];+ UILabel *label = (UILabel *)cell.accessoryView;+ if (!row.value || ![label isKindOfClass:UILabel.class]) continue;+ label.text = row.value();+ [label sizeToFit];+ [cell setNeedsLayout];+ }+}++// A check that lands may have brought a release nobody had heard of: the whole page is built again,+// intro and all, and faded in where it stands.+- (void)checkLanded {+ _groups = [self build];+ UILabel *note = (UILabel *)_intro.subviews.firstObject;+ note.text = [self introText];+ [self.view setNeedsLayout];+ [UIView transitionWithView:self.tableView duration:0.25 options:UIViewAnimationOptionTransitionCrossDissolve+ animations:^{ [self.tableView reloadData]; } completion:nil];+}++- (SGUpdateRow *)rowAt:(NSIndexPath *)path {+ if (!path) return nil;+ return _groups[(NSUInteger)path.section].rows[(NSUInteger)path.row];+}++- (NSInteger)numberOfSectionsInTableView:(UITableView *)table {+ return (NSInteger)_groups.count;+}++- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section {+ return (NSInteger)_groups[(NSUInteger)section].rows.count;+}++- (UIView *)tableView:(UITableView *)table viewForHeaderInSection:(NSInteger)section {+ NSString *title = _groups[(NSUInteger)section].title;+ return title ? SGSectionHeader(table, title) : nil;+}++- (CGFloat)tableView:(UITableView *)table heightForHeaderInSection:(NSInteger)section {+ return _groups[(NSUInteger)section].title ? SGSectionHeaderHeight : SGSectionGap;+}++- (UIView *)tableView:(UITableView *)table viewForFooterInSection:(NSInteger)section {+ return nil;+}++- (CGFloat)tableView:(UITableView *)table heightForFooterInSection:(NSInteger)section {+ return CGFLOAT_MIN;+}++- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)path {+ SGUpdateRow *row = [self rowAt:path];+ UITableViewCell *cell = SGDequeueCell(table, row.symbol ? @"tiled" : @"line");+ SGFillCell(cell, row.title, row.subtitle, nil, nil);+ if (row.symbol) {+ UIListContentConfiguration *content = (UIListContentConfiguration *)cell.contentConfiguration;+ content.image = SGTileImage(row.symbol);+ content.imageToTextPadding = 14;+ cell.contentConfiguration = content;+ }+ cell.separatorInset = UIEdgeInsetsMake(0, row.symbol ? 58 : 16, 0, 0);+ if (row.value) {+ UILabel *label = [UILabel new];+ label.font = SGTitleFont();+ label.textColor = SGGrey();+ label.text = row.value();+ [label sizeToFit];+ cell.accessoryView = label;+ }+ cell.selectionStyle = row.action ? UITableViewCellSelectionStyleDefault : UITableViewCellSelectionStyleNone;+ cell.accessibilityTraits = row.action ? UIAccessibilityTraitButton : UIAccessibilityTraitStaticText;+ return cell;+}++- (BOOL)tableView:(UITableView *)table shouldHighlightRowAtIndexPath:(NSIndexPath *)path {+ return [self rowAt:path].action != nil;+}++- (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)path {+ [table deselectRowAtIndexPath:path animated:YES];+ SGUpdateRow *row = [self rowAt:path];+ if (row.action) row.action();+ // Check now goes grey to "checking…" the moment it is tapped rather than on the next tick.+ if (row.value) [self readStatus];+}++@end++UIViewController *SGUpdatePage(void) {+ // Opening the page counts as asking, but the six hours still hold: Check now is the way past them.+ SGCheckForUpdate(NO);+ return [SGUpdatePageController new];+}