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: add welcome tour

Vojtěch Škopek39745b3029c9
diff --git a/Makefile b/Makefile
index 251f190e..34d4690e 100644
--- a/Makefile
+++ b/Makefile
@@ -7,13 +7,17 @@ IPA ?= $(firstword $(wildcard ipa/*.ipa))
FLEX ?= 0
FLEX_ARG := $(if $(filter 0,$(FLEX)),--no-flex,)
-.PHONY: build release install trees log flags
+.PHONY: build release install publish push trees log flags
build: ## FLEX + glass IPA into out/
./scripts/pipeline.sh $(IPA)
release: ## glass only, no FLEX
./scripts/pipeline.sh $(IPA) --no-flex
install: ## build, sign with your certificate, push to the phone on USB (FLEX=1 to take FLEX too)
./scripts/pipeline.sh $(IPA) --install $(FLEX_ARG)
+publish: ## VERSION=0.15.0 NOTES="..." : build, upload to catbox, write the site's release.json, print the link
+ ./scripts/publish.sh stage "$(IPA)" "$(VERSION)" "$(NOTES)"
+push: ## commit and push the staged release in both repos (after testing the link)
+ ./scripts/publish.sh push
trees: ## record per-screen view trees into trees/ (needs a FLEX build on the phone)
./scripts/record-trees.py
log: ## stream the tweak's log lines from the phone
diff --git a/docs/tweaks.md b/docs/tweaks.md
index 500d31b5..5cea9e24 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -12,10 +12,9 @@
tweak/Sources/Features/ one directory per feature, see below
tweak/Sources/Diagnostics/ screen dumps and the tree server of FLEX builds
scripts/ pipeline.sh (build + inject), install.sh (sign + install), record-trees.py,
- dump-log.sh, extract-flags.py, make-manifests.py
+ dump-log.sh, extract-flags.py, publish.sh (release: build, catbox, site manifest)
trees/ recorded view trees, one per screen; the input for every new hook
plist/ Info.plist overrides merged into the app (turns UIDesignRequiresCompatibility off)
- site/ the manifests spoti.pw serves (version.json, AltStore and Scarlet sources)
vendor/ AutoFLEX deb
ipa/, out/ decrypted Spotify IPA in, built IPAs out (both gitignored)
@@ -43,6 +42,7 @@ app:
AdBlock/ EeveeSpotify's ad blocking: the ad and upsell services silenced (AdServices.x), ad components out of the
Hub JSON (AdHubs.x) and the feeds (Feeds.m), Premium pop-ups dropped (AdPopups.x), and the responses
rewritten on the way in (AdNetwork.x, Premium.m over the protobuf walker in Protobuf.m)
+ Onboarding/ the welcome tour over Home on the first launch (Onboarding.x, the pages in Tour.m), offered again from About
About/ the update check and the About section of the root page
A hook reads its switch when it runs (`SGEnabled`, `SGHidden`, `SGFlag` from Core/SGPrefs.h), so a
diff --git a/scripts/make-manifests.py b/scripts/make-manifests.py
deleted file mode 100755
index 0455e405..00000000
--- a/scripts/make-manifests.py
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/usr/bin/env python3
-"""Write site/version.json, site/altstore.json and site/scarlet.json for a built IPA.
-
-The IPA itself is never hosted here: --url is where it actually lives (catbox, archive.org), and
-the manifests are the only thing the site serves. version.json is what the Updates row in Mod
-Settings reads; the other two are the sources AltStore/SideStore and Scarlet subscribe to, so a
-user who has added one gets every later build without going looking for it.
-
- scripts/make-manifests.py --ipa out/Spotify-9.1.78-glass.ipa \
- --url https://files.catbox.moe/xxxxxx.ipa --notes "Adds the About section."
-"""
-import argparse, json, plistlib, re, zipfile
-from datetime import date
-from pathlib import Path
-
-ROOT = Path(__file__).resolve().parent.parent
-SITE = ROOT / 'site'
-
-# Everything the manifests say about the project, in one place.
-NAME = 'spotifyglass'
-SUBTITLE = 'Liquid Glass for Spotify'
-DEVELOPER = 'vojta'
-SITE_URL = 'https://spoti.pw'
-SOURCE_ID = 'pw.spoti.source'
-ICON_URL = f'{SITE_URL}/icon.png'
-TINT = '1ED760'
-MIN_IOS = '16.0'
-DESCRIPTION = (
- "Spotify's own Liquid Glass design, unhidden from its feature flags, plus a pure black AMOLED "
- "background, a decluttered player and Home, a tab bar you can reorder or add your own links to, "
- "an editor for all of Spotify's internal flags, and telemetry blocking.\n\n"
- "Purely cosmetic. It does not unlock Premium."
-)
-SCREENSHOTS = [f'{SITE_URL}/shot-{n}.png' for n in (1, 2, 3)]
-
-
-def tweak_version():
- return re.search(r'^Version: (.+)$', (ROOT / 'tweak' / 'control').read_text(), re.M).group(1).strip()
-
-
-def ipa_info(ipa):
- with zipfile.ZipFile(ipa) as z:
- name = next(n for n in z.namelist() if re.fullmatch(r'Payload/[^/]+\.app/Info\.plist', n))
- info = plistlib.loads(z.read(name))
- return info['CFBundleIdentifier'], info['CFBundleShortVersionString']
-
-
-def main():
- ap = argparse.ArgumentParser()
- ap.add_argument('--ipa', required=True, type=Path)
- ap.add_argument('--url', required=True, help='where the IPA is actually hosted')
- ap.add_argument('--notes', default='', help='changelog for this build')
- args = ap.parse_args()
-
- version = tweak_version()
- bundle_id, spotify = ipa_info(args.ipa)
- size = args.ipa.stat().st_size
- when = date.today().isoformat()
- # AltStore orders by the version string, so the mod's version carries Spotify's alongside it.
- full = f'{version}-{spotify}'
- SITE.mkdir(exist_ok=True)
-
- (SITE / 'version.json').write_text(json.dumps({
- 'version': version,
- 'spotify': spotify,
- 'date': when,
- 'notes': args.notes,
- 'url': SITE_URL,
- 'download': args.url,
- }, indent=2) + '\n')
-
- (SITE / 'altstore.json').write_text(json.dumps({
- 'name': NAME,
- 'identifier': SOURCE_ID,
- 'subtitle': SUBTITLE,
- 'website': SITE_URL,
- 'iconURL': ICON_URL,
- 'apps': [{
- 'name': NAME,
- 'bundleIdentifier': bundle_id,
- 'developerName': DEVELOPER,
- 'subtitle': SUBTITLE,
- 'localizedDescription': DESCRIPTION,
- 'iconURL': ICON_URL,
- 'tintColor': TINT,
- 'screenshotURLs': SCREENSHOTS,
- 'versions': [{
- 'version': full,
- 'date': when,
- 'localizedDescription': args.notes,
- 'downloadURL': args.url,
- 'size': size,
- 'minOSVersion': MIN_IOS,
- }],
- }],
- 'news': [],
- }, indent=2) + '\n')
-
- (SITE / 'scarlet.json').write_text(json.dumps({
- 'META': {'repoName': NAME, 'repoIcon': ICON_URL},
- 'Tweaked': [{
- 'name': NAME,
- 'version': full,
- 'bundleID': bundle_id,
- 'down': args.url,
- 'description': DESCRIPTION,
- 'icon': ICON_URL,
- 'dev': DEVELOPER,
- }],
- }, indent=2) + '\n')
-
- print(f'{NAME} {version} on Spotify {spotify}, {size / 1e6:.0f} MB -> {args.url}')
- for f in ('version.json', 'altstore.json', 'scarlet.json'):
- print(f' site/{f}')
-
-
-if __name__ == '__main__':
- main()
diff --git a/scripts/publish.sh b/scripts/publish.sh
new file mode 100755
index 00000000..5e169317
--- /dev/null
+++ b/scripts/publish.sh
@@ -0,0 +1,94 @@
+#!/usr/bin/env bash
+# Cuts a release in two steps, so the link gets tested before anything goes live.
+#
+# make publish VERSION=0.15.0 NOTES="..." bump control, build, upload to catbox, write the site's
+# content/release.json, print the link. Nothing is committed.
+# make push commit and push both repos once the link is tested;
+# Coolify rebuilds spoti.pw from that push.
+#
+# The IPA never touches git: it goes to catbox and only its URL lands in release.json, next to the
+# mod version, Spotify's version and build (read off the built IPA), size, date and notes.
+# CATBOX_USERHASH uploads under your catbox account instead of anonymously (files then show up in
+# its manager and can be deleted). WEB points at the site checkout, default ../custom_spotify_web.
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
+WEB="${WEB:-$ROOT/../custom_spotify_web}"
+RELEASE="$WEB/content/release.json"
+CONTROL="$ROOT/tweak/control"
+
+die() { echo "$*" >&2; exit 1; }
+control_version() { sed -n 's/^Version: //p' "$CONTROL"; }
+release_field() { python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))[sys.argv[2]])' "$RELEASE" "$1"; }
+
+stage() {
+ local ipa="$1" version="$2" notes="$3"
+ [ -f "$ipa" ] || die "no IPA: put a decrypted Spotify .ipa in ipa/, or pass one (make publish IPA=path.ipa ...)"
+ [[ "$version" =~ ^[0-9]+(\.[0-9]+)+$ ]] || die "VERSION must look like 0.15.0, got '${version:-nothing}'"
+ [ -n "$notes" ] || die "NOTES is empty: say what changed, it is the changelog on the site and in the app"
+ [ -d "$WEB/content" ] || die "no site checkout at $WEB (set WEB=...)"
+ [ "$version" = "$(control_version)" ] && echo "note: control already says $version" >&2
+
+ sed -i '' "s/^Version: .*/Version: $version/" "$CONTROL"
+
+ local out
+ out="$("$ROOT/scripts/pipeline.sh" "$ipa" --no-flex | tee /dev/stderr | sed -n 's/^==> done: //p')"
+ [ -f "$out" ] || die "pipeline did not report a built IPA"
+
+ local app_dir plist
+ app_dir="$(unzip -Z1 "$out" | grep -oE '^Payload/[^/]+\.app/' | head -1)"
+ plist="$(mktemp)"
+ unzip -p "$out" "${app_dir}Info.plist" > "$plist"
+ local spotify build bundle min_os
+ spotify="$(plutil -extract CFBundleShortVersionString raw -o - "$plist")"
+ build="$(plutil -extract CFBundleVersion raw -o - "$plist")"
+ bundle="$(plutil -extract CFBundleIdentifier raw -o - "$plist")"
+ min_os="$(plutil -extract MinimumOSVersion raw -o - "$plist")"
+ rm -f "$plist"
+
+ echo "==> uploading $(du -h "$out" | cut -f1) to catbox"
+ local url
+ url="$(curl -fsS -F reqtype=fileupload ${CATBOX_USERHASH:+-F "userhash=$CATBOX_USERHASH"} \
+ -F "fileToUpload=@$out" https://catbox.moe/user/api.php)"
+ [[ "$url" == https://files.catbox.moe/* ]] || die "catbox did not return a link: $url"
+
+ python3 - "$RELEASE" "$version" "$spotify" "$build" "$bundle" "$min_os" "$(stat -f %z "$out")" "$url" "$notes" <<'PY'
+import json, sys
+from datetime import date
+path, mod, spotify, build, bundle, min_os, size, url, notes = sys.argv[1:]
+json.dump({
+ "mod": mod, "version": spotify, "buildVersion": build, "bundleId": bundle, "minOS": min_os,
+ "bytes": int(size), "date": date.today().isoformat(), "ipaUrl": url, "notes": notes,
+}, open(path, "w"), indent=2)
+open(path, "a").write("\n")
+PY
+
+ cat <<MSG
+
+==> staged $version on Spotify $spotify
+ $url
+ $RELEASE
+Sign and install that link, check the About row says $version, then: make push
+MSG
+}
+
+push() {
+ local mod
+ mod="$(release_field mod)"
+ [ "$mod" = "$(control_version)" ] || die "release.json says $mod but control says $(control_version); run make publish"
+ [ -n "$(git -C "$WEB" status --porcelain -- content/release.json)" ] || die "release.json is unchanged; run make publish first"
+
+ git -C "$WEB" add content/release.json
+ git -C "$WEB" commit -m "release: $mod"
+ git -C "$WEB" push
+ git -C "$ROOT" add tweak/control
+ git -C "$ROOT" commit -m "release: $mod"
+ git -C "$ROOT" push
+ echo "==> $mod is live once Coolify finishes: $(release_field ipaUrl)"
+}
+
+case "${1:-}" in
+ stage) stage "$2" "$3" "$4" ;;
+ push) push ;;
+ *) sed -n '2,12p' "$0"; exit 1 ;;
+esac
diff --git a/site/altstore.json b/site/altstore.json
deleted file mode 100644
index d9fd23b2..00000000
--- a/site/altstore.json
+++ /dev/null
@@ -1,34 +0,0 @@
-{
- "name": "spotifyglass",
- "identifier": "pw.spoti.source",
- "subtitle": "Liquid Glass for Spotify",
- "website": "https://spoti.pw",
- "iconURL": "https://spoti.pw/icon.png",
- "apps": [
- {
- "name": "spotifyglass",
- "bundleIdentifier": "com.spotify.client",
- "developerName": "vojta",
- "subtitle": "Liquid Glass for Spotify",
- "localizedDescription": "Like and dislike back on the lock screen widget, speed control and trim silence for music and not only podcasts, Spotify's own Liquid Glass with every flag of it on at once, a pure black AMOLED background, picture in picture, lyrics translations and vocal removal, a tab bar you reorder or add your own links to, no ad on app open and no upsells or tooltips, telemetry blocking with a count of what it stopped, and an editor for every one of Spotify's internal flags.\n\nPurely cosmetic. It does not unlock Premium.",
- "iconURL": "https://spoti.pw/icon.png",
- "tintColor": "1ED760",
- "screenshotURLs": [
- "https://spoti.pw/shot-1.png",
- "https://spoti.pw/shot-2.png",
- "https://spoti.pw/shot-3.png"
- ],
- "versions": [
- {
- "version": "0.14.1-9.1.78",
- "date": "2026-09-07",
- "localizedDescription": "Adds an About section with the version, an update check and links.",
- "downloadURL": "https://files.catbox.moe/REPLACE.ipa",
- "size": 124769128,
- "minOSVersion": "16.0"
- }
- ]
- }
- ],
- "news": []
-}
diff --git a/site/scarlet.json b/site/scarlet.json
deleted file mode 100644
index 0293da87..00000000
--- a/site/scarlet.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "META": {
- "repoName": "spotifyglass",
- "repoIcon": "https://spoti.pw/icon.png"
- },
- "Tweaked": [
- {
- "name": "spotifyglass",
- "version": "0.14.1-9.1.78",
- "bundleID": "com.spotify.client",
- "down": "https://files.catbox.moe/REPLACE.ipa",
- "description": "Like and dislike back on the lock screen widget, speed control and trim silence for music and not only podcasts, Spotify's own Liquid Glass with every flag of it on at once, a pure black AMOLED background, picture in picture, lyrics translations and vocal removal, a tab bar you reorder or add your own links to, no ad on app open and no upsells or tooltips, telemetry blocking with a count of what it stopped, and an editor for every one of Spotify's internal flags.\n\nPurely cosmetic. It does not unlock Premium.",
- "icon": "https://spoti.pw/icon.png",
- "dev": "vojta"
- }
- ]
-}
diff --git a/site/version.json b/site/version.json
deleted file mode 100644
index 0fafb87e..00000000
--- a/site/version.json
+++ /dev/null
@@ -1,8 +0,0 @@
-{
- "version": "0.14.1",
- "spotify": "9.1.78",
- "date": "2026-09-07",
- "notes": "Adds an About section with the version, an update check and links.",
- "url": "https://spoti.pw",
- "download": "https://files.catbox.moe/REPLACE.ipa"
-}
diff --git a/tweak/Sources/Core/SGRuntime.h b/tweak/Sources/Core/SGRuntime.h
index ed0c7ca5..32a90e58 100644
--- a/tweak/Sources/Core/SGRuntime.h
+++ b/tweak/Sources/Core/SGRuntime.h
@@ -23,3 +23,16 @@
@interface UIViewController (SGPrivate)
- (NSString *)_printHierarchy;
@end
+
+@interface UIButtonConfiguration (SGiOS26)
++ (instancetype)glassButtonConfiguration;
++ (instancetype)prominentGlassButtonConfiguration;
+@end
+
+@interface UIImageView (SGiOS17)
+- (void)addSymbolEffect:(id)effect;
+@end
+
+@interface NSObject (SGiOS17)
++ (id)effect; // NSSymbolBounceEffect and the other symbol effects
+@end
diff --git a/tweak/Sources/Features/About/About.h b/tweak/Sources/Features/About/About.h
index 20a4f28b..5182e95b 100644
--- a/tweak/Sources/Features/About/About.h
+++ b/tweak/Sources/Features/About/About.h
@@ -21,5 +21,6 @@ NSString *SGSigningAppIdentifier(void); // App ID without the team prefix,
BOOL SGSigningOpensFromLockScreen(void); // YES when unreadable, so a build that works stays quiet
SGModRow *SGSigningWarningRow(void); // nil while the signature is sound
void SGCheckSigningOnce(void);
+void SGShowSigningFixIfPending(void); // the sheet the tour held back, if any
SGModSection *SGAboutSection(void);
diff --git a/tweak/Sources/Features/About/AboutSettings.m b/tweak/Sources/Features/About/AboutSettings.m
index 10ce2cc5..2de0785e 100644
--- a/tweak/Sources/Features/About/AboutSettings.m
+++ b/tweak/Sources/Features/About/AboutSettings.m
@@ -1,5 +1,6 @@
#import "Settings/SGPageStyle.h"
#import "About.h"
+#import "Features/Onboarding/Onboarding.h"
// Which build this is, whether the site has a newer one, and where to reach the mod: without these
// rows a build that is already installed has no way of telling its user that anything moved on.
@@ -13,5 +14,6 @@ SGModSection *SGAboutSection(void) {
}, ^{ SGCheckForUpdate(YES); }),
SGLinkRow(@"Website", @"Downloads, and the source to add to AltStore or SideStore", SGSiteURL),
SGLinkRow(@"GitHub", @"Source, releases and issues", SGRepoURL),
+ SGActionRow(@"Welcome tour", @"The pages from the first launch, again", ^{ SGShowOnboarding(); }),
]);
}
diff --git a/tweak/Sources/Features/About/Signing.m b/tweak/Sources/Features/About/Signing.m
index 2cb1d4a1..9fdf6621 100644
--- a/tweak/Sources/Features/About/Signing.m
+++ b/tweak/Sources/Features/About/Signing.m
@@ -9,11 +9,13 @@
#import "Core/SGCore.h"
#import "Settings/SGPageStyle.h"
#import "About.h"
+#import "Features/Onboarding/Onboarding.h"
#import <dlfcn.h>
NSString *const SGSigningHelpURL = @"https://github.com/skopevoj/spoti.pw#signing-it-yourself";
static NSString *const kWarned = @"spotifyglass.signing.warned";
+static BOOL sg_fixPending;
// SecTaskCopyValueForEntitlement is not in the iOS SDK, so it is resolved at runtime like the rest
// of the private API the mod uses. A build that cannot read its own entitlement stays quiet.
@@ -48,25 +50,12 @@ BOOL SGSigningOpensFromLockScreen(void) {
return !appID || [appID isEqualToString:NSBundle.mainBundle.bundleIdentifier];
}
-static UIViewController *topController(void) {
- UIViewController *top = nil;
- for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
- if (![scene isKindOfClass:UIWindowScene.class]) continue;
- for (UIWindow *window in ((UIWindowScene *)scene).windows) {
- if (window.hidden) continue;
- if (!top || window.isKeyWindow) top = window.rootViewController;
- }
- }
- while (top.presentedViewController) top = top.presentedViewController;
- return top;
-}
-
// The fix is one string, so the sheet leads with it and Copy is the first action: whoever reads this
// is on their way back to Feather to paste it into the identifier field.
static void showFix(void) {
NSString *appID = SGSigningAppIdentifier();
NSString *bundleID = NSBundle.mainBundle.bundleIdentifier ?: @"?";
- UIViewController *top = topController();
+ UIViewController *top = SGTopController();
if (!appID || !top) return;
NSString *message = [NSString stringWithFormat:
@"Sign Spotify again with the bundle id set to\n\n%@\n\n"
@@ -115,7 +104,15 @@ void SGCheckSigningOnce(void) {
usingBlock:^(NSNotification *note) {
[NSNotificationCenter.defaultCenter removeObserver:token];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- showFix();
+ // The welcome tour has the screen; it shows the fix when it goes.
+ if (SGOnboardingShowing()) sg_fixPending = YES;
+ else showFix();
});
}];
}
+
+void SGShowSigningFixIfPending(void) {
+ if (!sg_fixPending) return;
+ sg_fixPending = NO;
+ showFix();
+}
diff --git a/tweak/Sources/Features/AdBlock/AdBlock.h b/tweak/Sources/Features/AdBlock/AdBlock.h
index f3bd5013..4fc00437 100644
--- a/tweak/Sources/Features/AdBlock/AdBlock.h
+++ b/tweak/Sources/Features/AdBlock/AdBlock.h
@@ -11,6 +11,9 @@
#define SGKeyHideUpsells @"spotifyglass.adblock.upsells"
#define SGKeyFakePremium @"spotifyglass.adblock.premium"
+// What a switch turning Pretend to be Premium on is told first.
+extern NSString *const SGFakePremiumWarning;
+
// A flag the ads or upsells switch forces off while it is on. Flags.x asks, and the row for it locks.
BOOL SGAdBlockForcesFlagOff(NSString *key);
diff --git a/tweak/Sources/Features/AdBlock/AdBlockSettings.m b/tweak/Sources/Features/AdBlock/AdBlockSettings.m
index 47d331a7..4de8e879 100644
--- a/tweak/Sources/Features/AdBlock/AdBlockSettings.m
+++ b/tweak/Sources/Features/AdBlock/AdBlockSettings.m
@@ -1,6 +1,8 @@
#import "Settings/SGModPage.h"
#import "AdBlock.h"
+NSString *const SGFakePremiumWarning = @"This is the part of EeveeSpotify Spotify's takedown went after, and it has not been tested here. It can end in a forced logout or worse for the account. A Premium account gains nothing from it.";
+
UIViewController *SGAdBlockSettingsPage(void) {
NSMutableArray<SGModRow *> *counts = [NSMutableArray array];
for (NSString *label in SGAdBlockLabels()) {
@@ -12,7 +14,7 @@ UIViewController *SGAdBlockSettingsPage(void) {
return @(SGAdBlockCount(nil)).stringValue;
})];
SGModRow *fakePremium = SGOptionRow(@"Pretend to be Premium", @"Rewrite the product state and config the server sends to a Premium account's, and answer the logout it sends back as done. Free accounts only", SGKeyFakePremium);
- fakePremium.warning = @"This is the part of EeveeSpotify Spotify's takedown went after, and it has not been tested here. It can end in a forced logout or worse for the account. A Premium account gains nothing from it.";
+ fakePremium.warning = SGFakePremiumWarning;
return [[SGModPage alloc] initWithTitle:@"Ad blocking" intro:SGRestartNote sections:@[
SGSection(@"From EeveeSpotify", @[
SGOptionRow(@"Hide ads", @"The ad services never start, ad components leave Home and Search before they render, and the requests behind them are answered empty", SGKeyHideAds),
diff --git a/tweak/Sources/Features/Onboarding/Onboarding.h b/tweak/Sources/Features/Onboarding/Onboarding.h
new file mode 100644
index 00000000..c96582c9
--- /dev/null
+++ b/tweak/Sources/Features/Onboarding/Onboarding.h
@@ -0,0 +1,11 @@
+// Onboarding: a welcome tour over Home the first time this build runs, four pages of glass: what
+// the mod is, the look switches, the ad switches, and where Mod Settings lives with the repo to
+// star. The switches it sets are read at launch like every other, so a changed one ends the tour
+// in a restart. About offers the tour again.
+#import <UIKit/UIKit.h>
+
+#define SGKeyOnboardingSeen @"spotifyglass.onboarding.seen"
+
+// Presents the tour over the top of the app; does nothing while it is already up.
+void SGShowOnboarding(void);
+BOOL SGOnboardingShowing(void);
diff --git a/tweak/Sources/Features/Onboarding/Onboarding.x b/tweak/Sources/Features/Onboarding/Onboarding.x
new file mode 100644
index 00000000..00c40b75
--- /dev/null
+++ b/tweak/Sources/Features/Onboarding/Onboarding.x
@@ -0,0 +1,22 @@
+// The tour goes up the first time Home appears, not at launch: a fresh sideload lands on the login
+// screen first, and a tour over that is wrong. A moment after, so Home has drawn under the glass.
+#import "Core/SGCore.h"
+#import "Onboarding.h"
+
+%hook _TtC19Home_FunkisPageImpl20FunkisViewController
+- (void)viewDidAppear:(BOOL)animated {
+ %orig;
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ SGShowOnboarding();
+ });
+ });
+}
+%end
+
+%ctor {
+ if (SGFlag(SGKeyOnboardingSeen, NO)) return;
+ %init;
+ SGRequireClasses(@[@"_TtC19Home_FunkisPageImpl20FunkisViewController"]);
+}
diff --git a/tweak/Sources/Features/Onboarding/Tour.m b/tweak/Sources/Features/Onboarding/Tour.m
new file mode 100644
index 00000000..2a30f737
--- /dev/null
+++ b/tweak/Sources/Features/Onboarding/Tour.m
@@ -0,0 +1,484 @@
+#import "Core/SGCore.h"
+#import "Settings/SGPageStyle.h"
+#import "Onboarding.h"
+#import "Features/About/About.h"
+#import "Features/AdBlock/AdBlock.h"
+#import "Features/Appearance/Appearance.h"
+#import "Features/Flags/Flags.h"
+#import "Features/Home/Home.h"
+
+static const CGFloat kMargin = 24;
+static const CGFloat kCardRadius = 22;
+static const CGFloat kRowHeight = 60;
+
+#pragma mark - glass
+
+// A view whose glass pane follows its bounds; the panes in SGGlass.m are laid out by their hosts.
+@interface SGGlassView : UIView
+@property (nonatomic) CGFloat radius;
+@property (nonatomic) BOOL capsule;
+@end
+
+@implementation SGGlassView
+static char kPaneKey;
+- (void)layoutSubviews {
+ [super layoutSubviews];
+ UIVisualEffectView *pane = SGGlassFor(self, &kPaneKey);
+ pane.frame = self.bounds;
+ SGShapeGlass(pane, self.radius, self.capsule);
+}
+@end
+
+#pragma mark - rows
+
+typedef NS_ENUM(NSInteger, SGTourRowKind) { SGTourRowPlain, SGTourRowSwitch, SGTourRowAction };
+
+@interface SGTourRow : NSObject
+@property (nonatomic, copy) NSString *symbol, *title, *subtitle, *key, *warning;
+@property (nonatomic) SGTourRowKind kind;
+@property (nonatomic) BOOL defaultOn;
+@property (nonatomic, copy) void (^action)(void);
+@end
+@implementation SGTourRow
+@end
+
+static SGTourRow *plainRow(NSString *symbol, NSString *title, NSString *subtitle) {
+ SGTourRow *row = [SGTourRow new];
+ row.symbol = symbol; row.title = title; row.subtitle = subtitle;
+ return row;
+}
+
+static SGTourRow *switchRow(NSString *symbol, NSString *title, NSString *subtitle, NSString *key, BOOL defaultOn) {
+ SGTourRow *row = plainRow(symbol, title, subtitle);
+ row.kind = SGTourRowSwitch; row.key = key; row.defaultOn = defaultOn;
+ return row;
+}
+
+static SGTourRow *actionRow(NSString *symbol, NSString *title, NSString *subtitle, void (^action)(void)) {
+ SGTourRow *row = plainRow(symbol, title, subtitle);
+ row.kind = SGTourRowAction; row.action = action;
+ return row;
+}
+
+@interface SGTourRowView : UIControl
+- (instancetype)initWithRow:(SGTourRow *)row owner:(UIViewController *)owner;
+@end
+
+@implementation SGTourRowView {
+ SGTourRow *_row;
+ __weak UIViewController *_owner;
+ UISwitch *_toggle;
+}
+
+- (instancetype)initWithRow:(SGTourRow *)row owner:(UIViewController *)owner {
+ if (!(self = [super initWithFrame:CGRectZero])) return nil;
+ _row = row;
+ _owner = owner;
+
+ UIImageView *icon = SGSymbolView(row.symbol, 17, UIImageSymbolWeightSemibold, 36);
+ icon.tintColor = row.kind == SGTourRowAction ? SGGreen() : UIColor.whiteColor;
+ icon.backgroundColor = [UIColor colorWithWhite:1 alpha:0.10];
+ icon.layer.cornerRadius = 10;
+ icon.layer.cornerCurve = kCACornerCurveContinuous;
+
+ UILabel *title = [UILabel new];
+ title.text = row.title;
+ title.font = [UIFont systemFontOfSize:15 weight:UIFontWeightSemibold];
+ title.textColor = UIColor.whiteColor;
+ UILabel *subtitle = [UILabel new];
+ subtitle.text = row.subtitle;
+ subtitle.font = [UIFont systemFontOfSize:12];
+ subtitle.textColor = SGGrey();
+ subtitle.numberOfLines = 2;
+ UIStackView *text = [[UIStackView alloc] initWithArrangedSubviews:@[title, subtitle]];
+ text.axis = UILayoutConstraintAxisVertical;
+ text.spacing = 2;
+
+ UIView *trailing = nil;
+ if (row.kind == SGTourRowSwitch) {
+ _toggle = [UISwitch new];
+ _toggle.onTintColor = SGGreen();
+ _toggle.on = SGFlag(row.key, row.defaultOn);
+ [_toggle addTarget:self action:@selector(toggled) forControlEvents:UIControlEventValueChanged];
+ trailing = _toggle;
+ } else if (row.kind == SGTourRowAction) {
+ trailing = SGSymbolView(@"arrow.up.right", 13, UIImageSymbolWeightSemibold, 20);
+ ((UIImageView *)trailing).tintColor = SGGrey();
+ [self addTarget:self action:@selector(tapped) forControlEvents:UIControlEventTouchUpInside];
+ }
+
+ UIStackView *line = [[UIStackView alloc] initWithArrangedSubviews:trailing ? @[icon, text, trailing] : @[icon, text]];
+ line.alignment = UIStackViewAlignmentCenter;
+ line.spacing = 14;
+ line.translatesAutoresizingMaskIntoConstraints = NO;
+ line.userInteractionEnabled = row.kind == SGTourRowSwitch;
+ // The text gives way, so a long subtitle wraps instead of squeezing the switch.
+ [text setContentHuggingPriority:UILayoutPriorityDefaultLow - 1 forAxis:UILayoutConstraintAxisHorizontal];
+ [text setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh - 1 forAxis:UILayoutConstraintAxisHorizontal];
+ [self addSubview:line];
+ [NSLayoutConstraint activateConstraints:@[
+ [icon.widthAnchor constraintEqualToConstant:36],
+ [icon.heightAnchor constraintEqualToConstant:36],
+ [line.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:16],
+ [line.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-16],
+ [line.topAnchor constraintEqualToAnchor:self.topAnchor constant:11],
+ [line.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:-11],
+ [self.heightAnchor constraintGreaterThanOrEqualToConstant:kRowHeight],
+ ]];
+ return self;
+}
+
+- (void)setHighlighted:(BOOL)highlighted {
+ [super setHighlighted:highlighted];
+ if (_row.kind == SGTourRowAction) self.alpha = highlighted ? 0.5 : 1;
+}
+
+- (void)tapped {
+ if (_row.action) _row.action();
+}
+
+- (void)toggled {
+ SGSetEnabled(_row.key, _toggle.on);
+ if (!_toggle.on || !_row.warning) return;
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:_row.title
+ message:_row.warning
+ preferredStyle:UIAlertControllerStyleAlert];
+ [alert addAction:[UIAlertAction actionWithTitle:@"Keep it on" style:UIAlertActionStyleDestructive handler:nil]];
+ [alert addAction:[UIAlertAction actionWithTitle:@"Turn it off" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
+ [self->_toggle setOn:NO animated:YES];
+ SGSetEnabled(self->_row.key, NO);
+ }]];
+ [_owner presentViewController:alert animated:YES completion:nil];
+}
+
+@end
+
+#pragma mark - pages
+
+@interface SGTourPage : UIViewController
+@property (nonatomic, copy) NSString *symbol, *heading, *body;
+@property (nonatomic, copy) NSArray<SGTourRow *> *rows;
+@property (nonatomic) NSInteger index;
+@property (nonatomic, weak) UIViewController *owner;
+@end
+
+@implementation SGTourPage {
+ UIImageView *_hero;
+ BOOL _shown;
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ UIScrollView *scroll = [UIScrollView new];
+ scroll.alwaysBounceVertical = YES;
+ scroll.showsVerticalScrollIndicator = NO;
+ scroll.translatesAutoresizingMaskIntoConstraints = NO;
+ [self.view addSubview:scroll];
+
+ SGGlassView *halo = [SGGlassView new];
+ halo.capsule = YES;
+ _hero = SGSymbolView(self.symbol, 34, UIImageSymbolWeightMedium, 88);
+ _hero.translatesAutoresizingMaskIntoConstraints = NO;
+ [halo addSubview:_hero];
+
+ UILabel *heading = [UILabel new];
+ heading.text = self.heading;
+ heading.font = [UIFont systemFontOfSize:30 weight:UIFontWeightBold];
+ heading.textColor = UIColor.whiteColor;
+ heading.numberOfLines = 0;
+ UILabel *body = [UILabel new];
+ body.text = self.body;
+ body.font = [UIFont systemFontOfSize:15];
+ body.textColor = SGGrey();
+ body.numberOfLines = 0;
+
+ SGGlassView *card = [SGGlassView new];
+ card.radius = kCardRadius;
+ card.clipsToBounds = YES;
+ card.layer.cornerRadius = kCardRadius;
+ card.layer.cornerCurve = kCACornerCurveContinuous;
+ UIStackView *list = [UIStackView new];
+ list.axis = UILayoutConstraintAxisVertical;
+ list.translatesAutoresizingMaskIntoConstraints = NO;
+ for (SGTourRow *row in self.rows) {
+ if (list.arrangedSubviews.count) {
+ UIView *line = [UIView new];
+ line.backgroundColor = [UIColor colorWithWhite:1 alpha:0.12];
+ [line.heightAnchor constraintEqualToConstant:1 / UIScreen.mainScreen.scale].active = YES;
+ [list addArrangedSubview:line];
+ }
+ [list addArrangedSubview:[[SGTourRowView alloc] initWithRow:row owner:self.owner]];
+ }
+ [card addSubview:list];
+
+ // The column stretches its children to its width; the halo keeps its square inside a strip.
+ UIView *strip = [UIView new];
+ halo.translatesAutoresizingMaskIntoConstraints = NO;
+ [strip addSubview:halo];
+
+ UIStackView *column = [[UIStackView alloc] initWithArrangedSubviews:@[strip, heading, body, card]];
+ column.axis = UILayoutConstraintAxisVertical;
+ column.spacing = 10;
+ [column setCustomSpacing:28 afterView:strip];
+ [column setCustomSpacing:28 afterView:body];
+ column.translatesAutoresizingMaskIntoConstraints = NO;
+ [scroll addSubview:column];
+
+ UILayoutGuide *frame = scroll.frameLayoutGuide, *content = scroll.contentLayoutGuide;
+ [NSLayoutConstraint activateConstraints:@[
+ [scroll.topAnchor constraintEqualToAnchor:self.view.topAnchor],
+ [scroll.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],
+ [scroll.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
+ [scroll.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
+ [column.topAnchor constraintEqualToAnchor:content.topAnchor constant:24],
+ [column.bottomAnchor constraintEqualToAnchor:content.bottomAnchor constant:-24],
+ [column.leadingAnchor constraintEqualToAnchor:content.leadingAnchor constant:kMargin],
+ [column.trailingAnchor constraintEqualToAnchor:content.trailingAnchor constant:-kMargin],
+ [column.widthAnchor constraintEqualToAnchor:frame.widthAnchor constant:-2 * kMargin],
+ [halo.leadingAnchor constraintEqualToAnchor:strip.leadingAnchor],
+ [halo.topAnchor constraintEqualToAnchor:strip.topAnchor],
+ [halo.bottomAnchor constraintEqualToAnchor:strip.bottomAnchor],
+ [halo.widthAnchor constraintEqualToConstant:88],
+ [halo.heightAnchor constraintEqualToConstant:88],
+ [_hero.centerXAnchor constraintEqualToAnchor:halo.centerXAnchor],
+ [_hero.centerYAnchor constraintEqualToAnchor:halo.centerYAnchor],
+ [list.topAnchor constraintEqualToAnchor:card.topAnchor],
+ [list.bottomAnchor constraintEqualToAnchor:card.bottomAnchor],
+ [list.leadingAnchor constraintEqualToAnchor:card.leadingAnchor],
+ [list.trailingAnchor constraintEqualToAnchor:card.trailingAnchor],
+ ]];
+}
+
+// The symbol bounces the first time the page lands; the page is already on screen during the
+// swipe that brings it in, so nothing else animates. iOS 16 has no symbol effects and skips it.
+- (void)viewDidAppear:(BOOL)animated {
+ [super viewDidAppear:animated];
+ if (_shown) return;
+ _shown = YES;
+ Class bounce = NSClassFromString(@"NSSymbolBounceEffect");
+ if (bounce && [_hero respondsToSelector:@selector(addSymbolEffect:)]) [_hero addSymbolEffect:[bounce effect]];
+}
+
+@end
+
+#pragma mark - the tour
+
+@interface SGOnboardingController : UIViewController <UIPageViewControllerDataSource, UIPageViewControllerDelegate>
+@end
+
+@implementation SGOnboardingController {
+ UIPageViewController *_pager;
+ NSArray<SGTourPage *> *_pages;
+ UIPageControl *_dots;
+ UIButton *_primary;
+ NSDictionary<NSString *, NSNumber *> *_before; // every switch as the tour found it
+}
+
+- (instancetype)init {
+ if (!(self = [super initWithNibName:nil bundle:nil])) return nil;
+ self.modalPresentationStyle = UIModalPresentationOverFullScreen;
+ self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
+ return self;
+}
+
+- (SGTourPage *)pageWithSymbol:(NSString *)symbol heading:(NSString *)heading body:(NSString *)body rows:(NSArray<SGTourRow *> *)rows {
+ SGTourPage *page = [SGTourPage new];
+ page.symbol = symbol; page.heading = heading; page.body = body; page.rows = rows;
+ page.owner = self;
+ page.index = (NSInteger)_pages.count;
+ return page;
+}
+
+- (NSArray<SGTourPage *> *)buildPages {
+ __weak typeof(self) weakSelf = self;
+ SGTourRow *premium = switchRow(@"crown.fill", @"Pretend to be Premium", @"Free accounts only", SGKeyFakePremium, NO);
+ premium.warning = SGFakePremiumWarning;
+ NSMutableArray *pages = [NSMutableArray array];
+ _pages = pages;
+ [pages addObject:[self pageWithSymbol:@"music.note" heading:@"Spotify, in glass." body:@"Spotify with a Liquid Glass rebuild on top. Every piece sits behind its own switch; the next two pages are the ones worth choosing now." rows:@[
+ plainRow(@"play.circle.fill", @"Glass player and now playing bar", @"The header, the bar, search and lyrics in glass"),
+ plainRow(@"moon.fill", @"Pure black AMOLED", @"With a Home gradient in any of eight colours"),
+ plainRow(@"dock.rectangle", @"A tab bar you compose", @"Reorder, hide, add any Spotify link"),
+ plainRow(@"flag.fill", @"Every flag Spotify ships", @"Searchable, with the features it never released"),
+ ]]];
+ [pages addObject:[self pageWithSymbol:@"circle.lefthalf.filled" heading:@"Your look." body:@"Matters of taste. Pick now, change any time in Mod Settings." rows:@[
+ switchRow(@"moon.fill", @"AMOLED background", @"Pure black instead of Spotify's dark grey", SGKeyAmoled, YES),
+ switchRow(@"drop.fill", @"Spotify's own Liquid Glass", @"The glass navigation bar, slider and sheets Spotify shipped switched off", SGKeySpotifyGlass, YES),
+ switchRow(@"paintpalette.fill", @"Home gradient", @"A wash of colour behind the top of Home", SGKeyHomeGradient, NO),
+ ]]];
+ [pages addObject:[self pageWithSymbol:@"eye.slash.fill" heading:@"Ads and nags." body:@"From EeveeSpotify. All three are off until switched on, and none is needed on a Premium account." rows:@[
+ switchRow(@"speaker.slash.fill", @"Hide ads", @"Ad services never start, ad slots leave Home and Search", SGKeyHideAds, NO),
+ switchRow(@"hand.raised.fill", @"Hide upsells", @"Premium prompts, banners and sheets dropped", SGKeyHideUpsells, NO),
+ premium,
+ ]]];
+ [pages addObject:[self pageWithSymbol:@"slider.horizontal.3" heading:@"Everything lives in Mod Settings." body:@"Spotify's Settings, last row. Every switch, the tab bar editor and all of Spotify's flags.\n\nFree and open source. A star is what keeps it going." rows:@[
+ actionRow(@"star.fill", @"Star on GitHub", @"skopevoj/spoti.pw", ^{ SGOpenURL(SGRepoURL); }),
+ actionRow(@"square.and.arrow.up", @"Share spoti.pw", @"Send the site to someone", ^{ [weakSelf share]; }),
+ ]]];
+ return pages;
+}
+
+static UIButton *glassButton(NSString *title, BOOL prominent) {
+ UIButtonConfiguration *config;
+ if (prominent && [UIButtonConfiguration respondsToSelector:@selector(prominentGlassButtonConfiguration)]) {
+ config = [UIButtonConfiguration prominentGlassButtonConfiguration];
+ } else if (!prominent && [UIButtonConfiguration respondsToSelector:@selector(glassButtonConfiguration)]) {
+ config = [UIButtonConfiguration glassButtonConfiguration];
+ } else {
+ config = prominent ? [UIButtonConfiguration filledButtonConfiguration] : [UIButtonConfiguration grayButtonConfiguration];
+ }
+ config.cornerStyle = UIButtonConfigurationCornerStyleCapsule;
+ config.baseBackgroundColor = prominent ? SGGreen() : nil;
+ config.baseForegroundColor = prominent ? UIColor.blackColor : UIColor.whiteColor;
+ config.contentInsets = prominent ? NSDirectionalEdgeInsetsMake(15, 20, 15, 20) : NSDirectionalEdgeInsetsMake(9, 16, 9, 16);
+ UIFont *font = [UIFont systemFontOfSize:prominent ? 17 : 15 weight:UIFontWeightSemibold];
+ config.attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName: font}];
+ UIButton *button = [UIButton buttonWithConfiguration:config primaryAction:nil];
+ button.translatesAutoresizingMaskIntoConstraints = NO;
+ return button;
+}
+
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ self.view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.85];
+
+ _pager = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll
+ navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
+ options:nil];
+ _pager.dataSource = self;
+ _pager.delegate = self;
+ [self buildPages];
+ NSMutableDictionary *before = [NSMutableDictionary dictionary];
+ for (SGTourRow *row in self.switches) before[row.key] = @(SGFlag(row.key, row.defaultOn));
+ _before = before;
+ [_pager setViewControllers:@[_pages.firstObject] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
+ [self addChildViewController:_pager];
+ _pager.view.translatesAutoresizingMaskIntoConstraints = NO;
+ [self.view addSubview:_pager.view];
+ [_pager didMoveToParentViewController:self];
+
+ UIButton *skip = glassButton(@"Skip", NO);
+ [skip addTarget:self action:@selector(finish) forControlEvents:UIControlEventTouchUpInside];
+ _dots = [UIPageControl new];
+ _dots.numberOfPages = (NSInteger)_pages.count;
+ _dots.currentPageIndicatorTintColor = UIColor.whiteColor;
+ _dots.pageIndicatorTintColor = [UIColor colorWithWhite:1 alpha:0.3];
+ _dots.userInteractionEnabled = NO;
+ _dots.translatesAutoresizingMaskIntoConstraints = NO;
+ _primary = glassButton(@"Continue", YES);
+ [_primary addTarget:self action:@selector(advance) forControlEvents:UIControlEventTouchUpInside];
+ for (UIView *v in @[skip, _dots, _primary]) [self.view addSubview:v];
+
+ UILayoutGuide *safe = self.view.safeAreaLayoutGuide;
+ [NSLayoutConstraint activateConstraints:@[
+ [_pager.view.topAnchor constraintEqualToAnchor:safe.topAnchor constant:52],
+ [_pager.view.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],
+ [_pager.view.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],
+ [_pager.view.bottomAnchor constraintEqualToAnchor:_dots.topAnchor constant:-4],
+ [skip.topAnchor constraintEqualToAnchor:safe.topAnchor constant:8],
+ [skip.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-kMargin],
+ [_dots.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],
+ [_dots.bottomAnchor constraintEqualToAnchor:_primary.topAnchor constant:-8],
+ [_primary.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:kMargin],
+ [_primary.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-kMargin],
+ [_primary.bottomAnchor constraintEqualToAnchor:safe.bottomAnchor constant:-16],
+ ]];
+}
+
+- (NSArray<SGTourRow *> *)switches {
+ NSMutableArray *rows = [NSMutableArray array];
+ for (SGTourPage *page in _pages) {
+ for (SGTourRow *row in page.rows) if (row.kind == SGTourRowSwitch) [rows addObject:row];
+ }
+ return rows;
+}
+
+- (NSInteger)current {
+ return ((SGTourPage *)_pager.viewControllers.firstObject).index;
+}
+
+// The hooks read every switch here at launch, so a changed one ends the tour in a restart.
+- (BOOL)changed {
+ for (SGTourRow *row in self.switches) {
+ if (SGFlag(row.key, row.defaultOn) != _before[row.key].boolValue) return YES;
+ }
+ return NO;
+}
+
+- (void)refresh {
+ NSInteger index = self.current;
+ _dots.currentPage = index;
+ BOOL last = index == (NSInteger)_pages.count - 1;
+ NSString *title = !last ? @"Continue" : self.changed ? @"Restart Spotify" : @"Start listening";
+ UIButtonConfiguration *config = _primary.configuration;
+ config.attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold]}];
+ _primary.configuration = config;
+}
+
+- (void)advance {
+ NSInteger next = self.current + 1;
+ if (next >= (NSInteger)_pages.count) {
+ [self finish];
+ return;
+ }
+ __weak typeof(self) weakSelf = self;
+ [_pager setViewControllers:@[_pages[(NSUInteger)next]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL done) {
+ [weakSelf refresh];
+ }];
+ [self refresh];
+}
+
+// A switch the hooks read at launch only shows after one: the tour saves and quits, and the next
+// tap on the icon comes up the chosen way.
+- (void)finish {
+ SGSetEnabled(SGKeyOnboardingSeen, YES);
+ BOOL restart = self.changed;
+ [NSUserDefaults.standardUserDefaults synchronize];
+ if (restart) {
+ exit(0);
+ }
+ [self dismissViewControllerAnimated:YES completion:^{ SGShowSigningFixIfPending(); }];
+}
+
+- (void)share {
+ UIActivityViewController *sheet = [[UIActivityViewController alloc] initWithActivityItems:@[@"Spotify, in glass.", [NSURL URLWithString:SGSiteURL]] applicationActivities:nil];
+ sheet.popoverPresentationController.sourceView = self.view;
+ [self presentViewController:sheet animated:YES completion:nil];
+}
+
+#pragma mark paging
+
+- (UIViewController *)pageViewController:(UIPageViewController *)pager viewControllerBeforeViewController:(SGTourPage *)page {
+ return page.index > 0 ? _pages[(NSUInteger)page.index - 1] : nil;
+}
+
+- (UIViewController *)pageViewController:(UIPageViewController *)pager viewControllerAfterViewController:(SGTourPage *)page {
+ return page.index + 1 < (NSInteger)_pages.count ? _pages[(NSUInteger)page.index + 1] : nil;
+}
+
+- (void)pageViewController:(UIPageViewController *)pager didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previous transitionCompleted:(BOOL)completed {
+ [self refresh];
+}
+
+@end
+
+#pragma mark - entry
+
+static __weak SGOnboardingController *sg_tour;
+
+BOOL SGOnboardingShowing(void) {
+ return sg_tour != nil;
+}
+
+void SGShowOnboarding(void) {
+ if (sg_tour) return;
+ UIViewController *top = SGTopController();
+ // Presenting from an alert lands nowhere; the tour waits for it to go.
+ if (!top || [top isKindOfClass:UIAlertController.class]) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ SGShowOnboarding(); });
+ return;
+ }
+ SGOnboardingController *tour = [SGOnboardingController new];
+ sg_tour = tour;
+ [top presentViewController:tour animated:YES completion:nil];
+}
diff --git a/tweak/Sources/Settings/SGPageStyle.h b/tweak/Sources/Settings/SGPageStyle.h
index f8254c2d..d0169af3 100644
--- a/tweak/Sources/Settings/SGPageStyle.h
+++ b/tweak/Sources/Settings/SGPageStyle.h
@@ -24,3 +24,5 @@ UIView *SGSectionHeader(UITableView *table, NSString *title);
UITableViewCell *SGDequeueCell(UITableView *table, NSString *identifier);
void SGOpenURL(NSString *url);
+// The controller on top of the key window, through whatever is presented over it.
+UIViewController *SGTopController(void);
diff --git a/tweak/Sources/Settings/SGPageStyle.m b/tweak/Sources/Settings/SGPageStyle.m
index 91d56dbf..749e7754 100644
--- a/tweak/Sources/Settings/SGPageStyle.m
+++ b/tweak/Sources/Settings/SGPageStyle.m
@@ -131,6 +131,19 @@ void SGAdoptFonts(UIView *list, UIView *row) {
});
}
+UIViewController *SGTopController(void) {
+ UIViewController *top = nil;
+ for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
+ if (![scene isKindOfClass:UIWindowScene.class]) continue;
+ for (UIWindow *window in ((UIWindowScene *)scene).windows) {
+ if (window.hidden) continue;
+ if (!top || window.isKeyWindow) top = window.rootViewController;
+ }
+ }
+ while (top.presentedViewController) top = top.presentedViewController;
+ return top;
+}
+
void SGOpenURL(NSString *url) {
NSURL *target = url ? [NSURL URLWithString:url] : nil;
if (!target) return;