Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: support the project on Ko-fi
Vojtěch Škopekb796643a5220
diff --git a/harness/donate/README.md b/harness/donate/README.mdnew file mode 100644index 00000000..5e6d1fdd--- /dev/null+++ b/harness/donate/README.md@@ -0,0 +1,8 @@+# Donate harness++The donate sheet and the Ko-fi button over a stand-in Home, on the simulator. Only `Donate.m`, the+page style and Core's glass are compiled.++ ./build.sh+ xcrun simctl install booted build/DonateHarness.app+ xcrun simctl launch booted com.vojta.donateharness sheet # or: tourdiff --git a/harness/donate/build.sh b/harness/donate/build.shnew file mode 100755index 00000000..d3757e0c--- /dev/null+++ b/harness/donate/build.sh@@ -0,0 +1,35 @@+#!/bin/sh+# Builds the donate harness for the simulator: Donate.m and the page style, nothing of Spotify's.+set -e+SRC=$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)+OUT=$(dirname "$0")/build+VERSION=${1:-0.18.0}+rm -rf "$OUT"; mkdir -p "$OUT/DonateHarness.app"++SDK=$(xcrun --sdk iphonesimulator --show-sdk-path)+xcrun -sdk iphonesimulator clang -target arm64-apple-ios26.0-simulator -fobjc-arc -g -O0 \+ -I"$SRC" -isysroot "$SDK" -Wno-deprecated-declarations -DSG_VERSION='"0.20.0"' \+ "$(dirname "$0")/main.m" "$SRC"/App/Donate/Donate.m \+ "$SRC"/Settings/*.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 -framework Symbols \+ -o "$OUT/DonateHarness.app/DonateHarness"++cat > "$OUT/DonateHarness.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>DonateHarness</string>+<key>CFBundleIdentifier</key><string>com.vojta.donateharness</string>+<key>CFBundleName</key><string>DonateHarness</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/DonateHarness.app"diff --git a/harness/donate/main.m b/harness/donate/main.mnew file mode 100644index 00000000..72b8ba88--- /dev/null+++ b/harness/donate/main.m@@ -0,0 +1,57 @@+// The donate sheet and the Ko-fi button over a stand-in Home: `sheet` brings the sheet up a second in,+// `tour` shows the button alone, as the welcome tour has it.+#import <UIKit/UIKit.h>+#import "App/Donate/Donate.h"++BOOL SGOnboardingShowing(void) { return NO; }+BOOL SGUpdateNoticeShown(void) { return NO; }++@interface Delegate : UIResponder <UIApplicationDelegate>+@property (nonatomic, strong) UIWindow *window;+@end++@implementation Delegate++static UIViewController *home(void) {+ UIViewController *screen = [UIViewController new];+ screen.view.backgroundColor = UIColor.blackColor;+ NSArray *colors = @[UIColor.systemPinkColor, UIColor.systemTealColor, UIColor.systemOrangeColor, UIColor.systemIndigoColor, UIColor.systemGreenColor, UIColor.systemPurpleColor];+ CGFloat side = (402 - 16 * 3) / 2.0;+ for (NSInteger i = 0; i < 8; i++) {+ UIView *tile = [[UIView alloc] initWithFrame:CGRectMake(16 + (i % 2) * (side + 16), 90 + (i / 2) * (side + 16), side, side)];+ tile.backgroundColor = colors[i % colors.count];+ tile.layer.cornerRadius = 10;+ [screen.view addSubview:tile];+ }+ if ([NSProcessInfo.processInfo.arguments containsObject:@"tour"]) {+ UIView *dim = [[UIView alloc] initWithFrame:UIScreen.mainScreen.bounds];+ dim.backgroundColor = [UIColor colorWithWhite:0 alpha:0.85];+ [screen.view addSubview:dim];+ SGKofiButton *button = [[SGKofiButton alloc] initWithTitle:@"Buy a student a coffee" prominent:NO];+ button.translatesAutoresizingMaskIntoConstraints = NO;+ [screen.view addSubview:button];+ [NSLayoutConstraint activateConstraints:@[+ [button.centerXAnchor constraintEqualToAnchor:screen.view.centerXAnchor],+ [button.centerYAnchor constraintEqualToAnchor:screen.view.centerYAnchor],+ ]];+ }+ return screen;+}++- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)options {+ self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];+ self.window.rootViewController = home();+ self.window.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ [self.window makeKeyAndVisible];+ if ([NSProcessInfo.processInfo.arguments containsObject:@"sheet"])+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ SGShowDonateSheet(); });+ 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 92db3ddf..20796092 100644--- a/tweak/Sources/App/About/About.h+++ b/tweak/Sources/App/About/About.h@@ -45,6 +45,7 @@ void SGUsageNoteAsked(void);// page and takes effect at once.#define SGKeyUpdateNotice @"spotifyglass.update.notice"void SGWatchForUpdates(void);+BOOL SGUpdateNoticeShown(void); // this run, so the donate sheet stays out of its way// 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/UpdateNotice.m b/tweak/Sources/App/About/UpdateNotice.mindex 90a560dc..ed502d09 100644--- a/tweak/Sources/App/About/UpdateNotice.m+++ b/tweak/Sources/App/About/UpdateNotice.m@@ -15,6 +15,10 @@ static const NSInteger kTries = 15; // a minute of waiting for the screenstatic BOOL sg_offered; // once a run, whatever else happens+BOOL SGUpdateNoticeShown(void) {+ return sg_offered;+}+// Everything that has changed since this build, newest release first, which is what the sheet counts// and reads the first lines of.static NSArray<SGUpdateChange *> *changesSinceThisBuild(void) {diff --git a/tweak/Sources/App/Donate/Donate.h b/tweak/Sources/App/Donate/Donate.hnew file mode 100644index 00000000..734a58fa--- /dev/null+++ b/tweak/Sources/App/Donate/Donate.h@@ -0,0 +1,16 @@+// Donate: Ko-fi, asked for from the Mod Settings row, a button on the welcome tour and a sheet that+// comes up on its own two days after the first launch and then every fourteen.+#import <UIKit/UIKit.h>+#import "Settings/SGModPage.h"++extern NSString *const SGKofiURL;+UIColor *SGKofiColor(void);++// A glass capsule with a Ko-fi rim circling it and a breathing glow. Prominent tints the glass itself.+@interface SGKofiButton : UIControl+- (instancetype)initWithTitle:(NSString *)title prominent:(BOOL)prominent;+@end++void SGShowDonateSheet(void);+SGModRow *SGDonateRow(void);+void SGWatchForDonate(void);diff --git a/tweak/Sources/App/Donate/Donate.m b/tweak/Sources/App/Donate/Donate.mnew file mode 100644index 00000000..37c9d985--- /dev/null+++ b/tweak/Sources/App/Donate/Donate.m@@ -0,0 +1,503 @@+#import "Core/SGCore.h"+#import "Settings/SGPageStyle.h"+#import "App/About/About.h"+#import "App/Onboarding/Onboarding.h"+#import "Donate.h"++NSString *const SGKofiURL = @"https://ko-fi.com/darkksh";++// Outside the "spotifyglass." prefix, so Reset all settings does not bring the sheet back early.+static NSString *const kNextKey = @"spotipw.donate.next";+static const NSTimeInterval kDay = 86400;+static const NSTimeInterval kFirstAsk = 2 * kDay, kEvery = 14 * kDay, kAfterDonating = 90 * kDay;+static const NSTimeInterval kSettle = 20, kRetry = 5;+static const NSInteger kTries = 24;++static UIColor *rgb(uint32_t v, CGFloat alpha) {+ return [UIColor colorWithRed:((v >> 16) & 0xFF) / 255.0 green:((v >> 8) & 0xFF) / 255.0 blue:(v & 0xFF) / 255.0 alpha:alpha];+}++UIColor *SGKofiColor(void) { return rgb(0xFF5E5B, 1); }++#pragma mark - button++static const CGFloat kRimWidth = 1.5, kGlowWidth = 6, kGlowRadius = 9, kGlowBleed = 22;+static const CFTimeInterval kTurn = 3.2, kBreath = 1.8;++@interface CAFilter : NSObject++ (instancetype)filterWithType:(NSString *)type;+@end++// Ko-fi red most of the way round, with one bright streak that runs along the rim as the colours turn.+static CAGradientLayer *newRimColors(void) {+ CAGradientLayer *gradient = [CAGradientLayer layer];+ gradient.type = kCAGradientLayerConic;+ gradient.startPoint = CGPointMake(0.5, 0.5);+ gradient.endPoint = CGPointMake(0.5, 0);+ gradient.colors = @[(id)rgb(0xFF5E5B, 0.55).CGColor, (id)rgb(0xFF5E5B, 1).CGColor, (id)rgb(0xFFB4A2, 1).CGColor,+ (id)UIColor.whiteColor.CGColor, (id)rgb(0xFFB4A2, 1).CGColor, (id)rgb(0xFF5E5B, 1).CGColor,+ (id)rgb(0xFF5E5B, 0.55).CGColor];+ gradient.locations = @[@0, @0.5, @0.64, @0.72, @0.8, @0.9, @1];+ return gradient;+}++static CAShapeLayer *newStroke(CGFloat width) {+ CAShapeLayer *stroke = [CAShapeLayer layer];+ stroke.fillColor = UIColor.clearColor.CGColor;+ stroke.strokeColor = UIColor.blackColor.CGColor;+ stroke.lineWidth = width;+ return stroke;+}++@implementation SGKofiButton {+ BOOL _prominent;+ UIVisualEffectView *_glass;+ CAGradientLayer *_fill;+ CALayer *_rim, *_glow, *_glowShape;+ CAShapeLayer *_rimMask, *_glowMask;+ CAGradientLayer *_rimColors, *_glowColors;+ UIImpactFeedbackGenerator *_haptic;+}++- (instancetype)initWithTitle:(NSString *)title prominent:(BOOL)prominent {+ if (!(self = [super initWithFrame:CGRectZero])) return nil;+ _prominent = prominent;+ self.isAccessibilityElement = YES;+ self.accessibilityTraits = UIAccessibilityTraitButton;+ self.accessibilityLabel = title;++ _glow = [CALayer layer];+ _glowShape = [CALayer layer];+ _glowMask = newStroke(kGlowWidth);+ _glowShape.mask = _glowMask;+ _glowColors = newRimColors();+ [_glowShape addSublayer:_glowColors];+ [_glow addSublayer:_glowShape];+ Class filter = NSClassFromString(@"CAFilter");+ CAFilter *blur = [filter respondsToSelector:@selector(filterWithType:)] ? [filter filterWithType:@"gaussianBlur"] : nil;+ if (blur) {+ [blur setValue:@(kGlowRadius) forKey:@"inputRadius"];+ _glow.filters = @[blur];+ }+ [self.layer addSublayer:_glow];++ UIVisualEffect *effect = SGGlassEffect();+ BOOL glass = NSClassFromString(@"UIGlassEffect") && [effect respondsToSelector:@selector(setTintColor:)];+ if (glass && prominent) {+ effect = [NSClassFromString(@"UIGlassEffect") effectWithStyle:0];+ [(id)effect setTintColor:rgb(0xFF5E5B, 0.85)];+ }+ _glass = [[UIVisualEffectView alloc] initWithEffect:effect];+ _glass.userInteractionEnabled = NO;+ _glass.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ [self addSubview:_glass];+ if (prominent && !glass) {+ _fill = [CAGradientLayer layer];+ _fill.colors = @[(id)rgb(0xFF7A73, 1).CGColor, (id)rgb(0xE8434B, 1).CGColor];+ _fill.startPoint = CGPointMake(0, 0);+ _fill.endPoint = CGPointMake(1, 1);+ [self.layer addSublayer:_fill];+ }++ _rim = [CALayer layer];+ _rimMask = newStroke(kRimWidth);+ _rim.mask = _rimMask;+ _rimColors = newRimColors();+ [_rim addSublayer:_rimColors];+ [self.layer addSublayer:_rim];++ UIImageView *cup = SGSymbolView(@"cup.and.saucer.fill", 17, UIImageSymbolWeightSemibold, 24);+ cup.tintColor = prominent ? UIColor.whiteColor : SGKofiColor();+ UILabel *label = [UILabel new];+ label.text = title;+ label.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];+ label.textColor = UIColor.whiteColor;+ label.adjustsFontSizeToFitWidth = YES;+ label.minimumScaleFactor = 0.8;+ UIStackView *content = [[UIStackView alloc] initWithArrangedSubviews:@[cup, label]];+ content.alignment = UIStackViewAlignmentCenter;+ content.spacing = 8;+ content.userInteractionEnabled = NO;+ content.translatesAutoresizingMaskIntoConstraints = NO;+ [self addSubview:content];+ [NSLayoutConstraint activateConstraints:@[+ [content.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],+ [content.leadingAnchor constraintGreaterThanOrEqualToAnchor:self.leadingAnchor constant:22],+ [content.topAnchor constraintEqualToAnchor:self.topAnchor constant:prominent ? 16 : 13],+ [content.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:prominent ? -16 : -13],+ ]];+ // Hugs its content unless its host stretches it.+ NSLayoutConstraint *hug = [content.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:22];+ hug.priority = UILayoutPriorityDefaultLow;+ hug.active = YES;++ _haptic = [[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium];+ [self addTarget:self action:@selector(tapped) forControlEvents:UIControlEventTouchUpInside];+ return self;+}++- (void)tapped {+ [_haptic impactOccurred];+}++- (void)layoutSubviews {+ [super layoutSubviews];+ CGRect bounds = self.bounds;+ CGFloat radius = bounds.size.height / 2;+ _glass.frame = bounds;+ SGShapeGlass(_glass, radius, YES);+ UIBezierPath *capsule = [UIBezierPath bezierPathWithRoundedRect:CGRectInset(bounds, kRimWidth / 2, kRimWidth / 2) cornerRadius:radius];+ CGFloat side = ceil(hypot(bounds.size.width, bounds.size.height)) + 2;+ CGRect square = CGRectMake(CGRectGetMidX(bounds) - side / 2, CGRectGetMidY(bounds) - side / 2, side, side);++ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ _fill.frame = bounds;+ _fill.cornerRadius = radius;+ _rim.frame = bounds;+ _rimMask.frame = bounds;+ _rimMask.path = capsule.CGPath;+ _rimColors.frame = square;+ _glow.frame = CGRectInset(bounds, -kGlowBleed, -kGlowBleed);+ _glowShape.frame = _glow.bounds;+ _glowMask.frame = _glow.bounds;+ UIBezierPath *glowPath = [capsule copy];+ [glowPath applyTransform:CGAffineTransformMakeTranslation(kGlowBleed, kGlowBleed)];+ _glowMask.path = glowPath.CGPath;+ _glowColors.frame = CGRectOffset(square, kGlowBleed, kGlowBleed);+ [CATransaction commit];+}++- (void)setHighlighted:(BOOL)highlighted {+ BOOL changed = highlighted != self.highlighted;+ [super setHighlighted:highlighted];+ if (!changed) return;+ [UIView animateWithDuration:highlighted ? 0.18 : 0.45 delay:0 usingSpringWithDamping:highlighted ? 1 : 0.55+ initialSpringVelocity:0 options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState animations:^{+ self.transform = highlighted ? CGAffineTransformMakeScale(0.95, 0.95) : CGAffineTransformIdentity;+ } completion:nil];+}++- (void)updateMotion {+ _glow.hidden = UIAccessibilityIsReduceTransparencyEnabled();+ BOOL moving = self.window && !UIAccessibilityIsReduceMotionEnabled();+ for (CAGradientLayer *colors in @[_rimColors, _glowColors]) {+ if (!moving) {+ [colors removeAllAnimations];+ continue;+ }+ if ([colors animationForKey:@"turn"]) continue;+ CABasicAnimation *turn = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];+ turn.fromValue = @0;+ turn.toValue = @(M_PI * 2);+ turn.duration = kTurn;+ turn.repeatCount = HUGE_VALF;+ [colors addAnimation:turn forKey:@"turn"];+ }+ if (!moving) {+ [_glow removeAllAnimations];+ _glow.opacity = _prominent ? 0.8 : 0.6;+ return;+ }+ if ([_glow animationForKey:@"breathe"]) return;+ CABasicAnimation *breathe = [CABasicAnimation animationWithKeyPath:@"opacity"];+ breathe.fromValue = @(_prominent ? 0.55 : 0.35);+ breathe.toValue = @1;+ breathe.duration = kBreath;+ breathe.autoreverses = YES;+ breathe.repeatCount = HUGE_VALF;+ breathe.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];+ [_glow addAnimation:breathe forKey:@"breathe"];+}++// Backgrounding drops layer animations; they start again on the way back.+- (void)didMoveToWindow {+ [super didMoveToWindow];+ [NSNotificationCenter.defaultCenter removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];+ if (self.window) [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateMotion) name:UIApplicationWillEnterForegroundNotification object:nil];+ [self updateMotion];+}++@end++#pragma mark - schedule++static NSTimeInterval now(void) {+ return NSDate.date.timeIntervalSince1970;+}++static NSTimeInterval nextAsk(void) {+ NSUserDefaults *store = NSUserDefaults.standardUserDefaults;+ double next = [store doubleForKey:kNextKey];+ if (next <= 0) {+ next = now() + kFirstAsk;+ [store setDouble:next forKey:kNextKey];+ }+ return next;+}++static void askAgainIn(NSTimeInterval wait) {+ [NSUserDefaults.standardUserDefaults setDouble:now() + wait forKey:kNextKey];+}++#pragma mark - sheet++static const CGFloat kCardMargin = 10, kCardPadding = 26;++@interface SGDonateController : UIViewController+@end++@implementation SGDonateController {+ UIView *_backdrop, *_card;+ CAGradientLayer *_warmth;+ UIImageView *_cup, *_heart;+ BOOL _leaving;+}++static char kCardGlassKey;++- (instancetype)init {+ if (!(self = [super initWithNibName:nil bundle:nil])) return nil;+ self.modalPresentationStyle = UIModalPresentationOverFullScreen;+ self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;+ return self;+}++- (CGFloat)cardRadius {+ if (@available(iOS 26.0, *)) return 44;+ return 28;+}++- (UILabel *)label:(NSString *)text font:(UIFont *)font color:(UIColor *)color {+ UILabel *label = [UILabel new];+ label.text = text;+ label.font = font;+ label.textColor = color;+ label.numberOfLines = 0;+ label.textAlignment = NSTextAlignmentCenter;+ return label;+}++// The cup on a warm Ko-fi disc that glows into the card, with a heart badge on its shoulder.+- (UIView *)hero {+ UIView *disc = [UIView new];+ disc.translatesAutoresizingMaskIntoConstraints = NO;+ CAGradientLayer *fill = [CAGradientLayer layer];+ fill.frame = CGRectMake(0, 0, 80, 80);+ fill.cornerRadius = 40;+ fill.colors = @[(id)rgb(0xFF8A7A, 1).CGColor, (id)rgb(0xE8434B, 1).CGColor];+ fill.startPoint = CGPointMake(0.2, 0);+ fill.endPoint = CGPointMake(0.8, 1);+ [disc.layer addSublayer:fill];+ disc.layer.shadowColor = SGKofiColor().CGColor;+ disc.layer.shadowOpacity = UIAccessibilityIsReduceTransparencyEnabled() ? 0 : 0.75;+ disc.layer.shadowRadius = 24;+ disc.layer.shadowOffset = CGSizeZero;+ disc.layer.shadowPath = [UIBezierPath bezierPathWithOvalInRect:fill.frame].CGPath;++ _cup = SGSymbolView(@"cup.and.saucer.fill", 32, UIImageSymbolWeightSemibold, 80);+ _cup.tintColor = UIColor.whiteColor;+ _cup.translatesAutoresizingMaskIntoConstraints = NO;+ [disc addSubview:_cup];++ _heart = SGSymbolView(@"heart.fill", 13, UIImageSymbolWeightBold, 28);+ _heart.tintColor = SGKofiColor();+ _heart.backgroundColor = UIColor.whiteColor;+ _heart.layer.cornerRadius = 14;+ _heart.translatesAutoresizingMaskIntoConstraints = NO;+ [disc addSubview:_heart];++ [NSLayoutConstraint activateConstraints:@[+ [disc.widthAnchor constraintEqualToConstant:80],+ [disc.heightAnchor constraintEqualToConstant:80],+ [_cup.centerXAnchor constraintEqualToAnchor:disc.centerXAnchor],+ [_cup.centerYAnchor constraintEqualToAnchor:disc.centerYAnchor],+ [_heart.widthAnchor constraintEqualToConstant:28],+ [_heart.heightAnchor constraintEqualToConstant:28],+ [_heart.trailingAnchor constraintEqualToAnchor:disc.trailingAnchor constant:4],+ [_heart.bottomAnchor constraintEqualToAnchor:disc.bottomAnchor constant:2],+ ]];+ return disc;+}++- (void)viewDidLoad {+ [super viewDidLoad];+ self.view.backgroundColor = UIColor.clearColor;++ _backdrop = [UIView new];+ _backdrop.backgroundColor = [UIColor colorWithWhite:0 alpha:0.55];+ _backdrop.alpha = 0;+ _backdrop.translatesAutoresizingMaskIntoConstraints = NO;+ [_backdrop addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(later)]];+ [self.view addSubview:_backdrop];++ _card = [UIView new];+ _card.clipsToBounds = YES;+ _card.layer.cornerRadius = self.cardRadius;+ _card.layer.cornerCurve = kCACornerCurveContinuous;+ _card.translatesAutoresizingMaskIntoConstraints = NO;+ if (!NSClassFromString(@"UIGlassEffect")) _card.backgroundColor = [UIColor colorWithWhite:0.08 alpha:0.6];+ _warmth = [CAGradientLayer layer];+ _warmth.type = kCAGradientLayerRadial;+ _warmth.colors = @[(id)rgb(0xFF5E5B, 0.32).CGColor, (id)rgb(0xFF5E5B, 0).CGColor];+ _warmth.startPoint = CGPointMake(0.5, 0);+ _warmth.endPoint = CGPointMake(1.15, 0.75);+ [_card.layer addSublayer:_warmth];+ [self.view addSubview:_card];++ UIView *hero = [self hero];+ UILabel *eyebrow = [self label:@"A STUDENT PROJECT" font:[UIFont systemFontOfSize:12 weight:UIFontWeightBold] color:SGKofiColor()];+ eyebrow.attributedText = [[NSAttributedString alloc] initWithString:eyebrow.text attributes:@{NSKernAttributeName: @1.4}];+ UILabel *title = [self label:@"Enjoying spoti.pw?" font:[UIFont systemFontOfSize:26 weight:UIFontWeightBold] color:UIColor.whiteColor];+ UILabel *body = [self label:@"I'm a student and I build it for free, in my spare time. If it made your music better, a coffee helps me keep going."+ font:[UIFont systemFontOfSize:15] color:[UIColor colorWithWhite:1 alpha:0.72]];++ SGKofiButton *donate = [[SGKofiButton alloc] initWithTitle:@"Buy me a coffee" prominent:YES];+ [donate addTarget:self action:@selector(donate) forControlEvents:UIControlEventTouchUpInside];++ UIButtonConfiguration *config = [UIButtonConfiguration plainButtonConfiguration];+ config.baseForegroundColor = [UIColor colorWithWhite:1 alpha:0.6];+ config.attributedTitle = [[NSAttributedString alloc] initWithString:@"Maybe later" attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:15 weight:UIFontWeightMedium]}];+ UIButton *later = [UIButton buttonWithConfiguration:config primaryAction:nil];+ [later addTarget:self action:@selector(later) forControlEvents:UIControlEventTouchUpInside];++ UILabel *thanks = [self label:@"Also built on Spicy Lyrics, JamesDSP and EeveeSpotify. Thank you to everyone behind them."+ font:[UIFont systemFontOfSize:11] color:[UIColor colorWithWhite:1 alpha:0.38]];++ UIStackView *column = [[UIStackView alloc] initWithArrangedSubviews:@[hero, eyebrow, title, body, donate, later, thanks]];+ column.axis = UILayoutConstraintAxisVertical;+ column.alignment = UIStackViewAlignmentCenter;+ column.spacing = 8;+ [column setCustomSpacing:22 afterView:hero];+ [column setCustomSpacing:4 afterView:eyebrow];+ [column setCustomSpacing:26 afterView:body];+ [column setCustomSpacing:6 afterView:donate];+ [column setCustomSpacing:10 afterView:later];+ column.translatesAutoresizingMaskIntoConstraints = NO;+ [_card addSubview:column];++ UILayoutGuide *safe = self.view.safeAreaLayoutGuide;+ [NSLayoutConstraint activateConstraints:@[+ [_backdrop.topAnchor constraintEqualToAnchor:self.view.topAnchor],+ [_backdrop.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor],+ [_backdrop.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor],+ [_backdrop.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor],+ [_card.leadingAnchor constraintEqualToAnchor:safe.leadingAnchor constant:kCardMargin],+ [_card.trailingAnchor constraintEqualToAnchor:safe.trailingAnchor constant:-kCardMargin],+ [_card.widthAnchor constraintLessThanOrEqualToConstant:460],+ [_card.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor],+ [_card.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor constant:-kCardMargin],+ [_card.topAnchor constraintGreaterThanOrEqualToAnchor:safe.topAnchor constant:kCardMargin],+ [column.topAnchor constraintEqualToAnchor:_card.topAnchor constant:36],+ [column.leadingAnchor constraintEqualToAnchor:_card.leadingAnchor constant:kCardPadding],+ [column.trailingAnchor constraintEqualToAnchor:_card.trailingAnchor constant:-kCardPadding],+ [column.bottomAnchor constraintLessThanOrEqualToAnchor:_card.bottomAnchor constant:-kCardPadding],+ [donate.widthAnchor constraintEqualToAnchor:column.widthAnchor],+ [body.widthAnchor constraintLessThanOrEqualToAnchor:column.widthAnchor],+ [thanks.widthAnchor constraintLessThanOrEqualToAnchor:column.widthAnchor constant:-24],+ ]];+ // Clear of the home indicator; without one the card's own padding wins.+ NSLayoutConstraint *indicator = [column.bottomAnchor constraintEqualToAnchor:safe.bottomAnchor constant:-8];+ indicator.priority = UILayoutPriorityDefaultHigh;+ indicator.active = YES;+ _card.transform = CGAffineTransformMakeTranslation(0, 700);+}++- (void)viewDidLayoutSubviews {+ [super viewDidLayoutSubviews];+ UIVisualEffectView *pane = SGGlassFor(_card, &kCardGlassKey);+ pane.frame = _card.bounds;+ SGShapeGlass(pane, self.cardRadius, NO);+ [CATransaction begin];+ [CATransaction setDisableActions:YES];+ _warmth.frame = _card.bounds;+ [CATransaction commit];+}++- (void)viewDidAppear:(BOOL)animated {+ [super viewDidAppear:animated];+ [UIView animateWithDuration:0.3 animations:^{ self->_backdrop.alpha = 1; }];+ [UIView animateWithDuration:0.62 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:0+ options:UIViewAnimationOptionAllowUserInteraction animations:^{+ self->_card.transform = CGAffineTransformIdentity;+ } completion:nil];+ if (@available(iOS 17.0, *)) {+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ [self->_cup addSymbolEffect:[NSClassFromString(@"NSSymbolBounceEffect") effect]];+ });+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{+ [self->_heart addSymbolEffect:[NSClassFromString(@"NSSymbolBounceEffect") effect]];+ });+ }+}++- (void)leaveThen:(void (^)(void))then {+ if (_leaving) return;+ _leaving = YES;+ [UIView animateWithDuration:0.28 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{+ self->_backdrop.alpha = 0;+ self->_card.transform = CGAffineTransformMakeTranslation(0, self->_card.bounds.size.height + 40);+ } completion:^(BOOL finished) {+ [self dismissViewControllerAnimated:NO completion:then];+ }];+}++- (void)donate {+ askAgainIn(kAfterDonating);+ SGLog(@"donate: opened Ko-fi");+ [self leaveThen:^{ SGOpenURL(SGKofiURL); }];+}++- (void)later {+ [self leaveThen:nil];+}++@end++#pragma mark - entry++static __weak SGDonateController *sg_sheet;+static BOOL sg_offered;++void SGShowDonateSheet(void) {+ UIViewController *top = SGTopController();+ if (sg_sheet || !top || [top isKindOfClass:UIAlertController.class]) return;+ SGDonateController *sheet = [SGDonateController new];+ sg_sheet = sheet;+ [top presentViewController:sheet animated:NO completion:nil];+}++SGModRow *SGDonateRow(void) {+ SGModRow *row = SGWithSymbol(SGActionRow(@"Support spoti.pw", @"Buy the student behind it a coffee", ^{ SGShowDonateSheet(); }), @"cup.and.saucer.fill");+ row.color = SGKofiColor();+ return row;+}++// Never over the tour, an alert or the update sheet, and never twice in one run: a busy screen+// waits a couple of minutes, then the sheet is left for the next launch.+static void offerWhenClear(NSInteger tries) {+ if (sg_offered || now() < nextAsk() || SGUpdateNoticeShown()) return;+ UIViewController *top = SGTopController();+ BOOL busy = !top || SGOnboardingShowing() || [top isKindOfClass:UIAlertController.class]+ || UIApplication.sharedApplication.applicationState != UIApplicationStateActive;+ if (busy) {+ if (tries > 0)+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kRetry * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ offerWhenClear(tries - 1); });+ return;+ }+ sg_offered = YES;+ askAgainIn(kEvery);+ SGShowDonateSheet();+ SGLog(@"donate: asked over %@", NSStringFromClass(top.class));+}++void SGWatchForDonate(void) {+ nextAsk();+ __block id observer = [NSNotificationCenter.defaultCenter addObserverForName:UIApplicationDidBecomeActiveNotification+ object:nil+ queue:NSOperationQueue.mainQueue+ usingBlock:^(NSNotification *note) {+ [NSNotificationCenter.defaultCenter removeObserver:observer];+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(kSettle * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ offerWhenClear(kTries); });+ }];+}diff --git a/tweak/Sources/App/ModSettings.x b/tweak/Sources/App/ModSettings.xindex e2e09cb8..46cc5574 100644--- a/tweak/Sources/App/ModSettings.x+++ b/tweak/Sources/App/ModSettings.x@@ -22,6 +22,7 @@#import "Shared/JamesDSP/JamesDSPPage.h"#import "Shared/LiveActivity/LiveActivity.h"#import "App/About/About.h"+#import "App/Donate/Donate.h"#import "Pages.h"static const CGFloat kRowHeight = 56;@@ -39,6 +40,7 @@ static UIViewController *modSettingsPage(void) {// that no switch can put right, and it is worth reading before anything else.SGModRow *signing = SGSigningWarningRow();if (signing) [sections addObject:SGSection(nil, @[signing])];+ [sections addObject:SGSection(nil, @[SGDonateRow()])];SGModRow *mod = pageRow(@"Mod", @"info.circle", ^UIViewController *{ return SGAboutPage(); });mod.value = ^NSString *{ return @(SG_VERSION); };// JamesDSP works on the sound, so both looks have it, with what it is doing beside the chevron.@@ -247,4 +249,5 @@ static BOOL isSettingsRoot(UIViewController *list) {SGRegisterPages();SGCheckSigningOnce();SGWatchForUpdates();+ SGWatchForDonate();}diff --git a/tweak/Sources/App/Onboarding/Tour.m b/tweak/Sources/App/Onboarding/Tour.mindex 0acd178d..60980590 100644--- a/tweak/Sources/App/Onboarding/Tour.m+++ b/tweak/Sources/App/Onboarding/Tour.m@@ -3,6 +3,7 @@#import "Onboarding.h"#import "App/About/About.h"#import "App/Pages.h"+#import "App/Donate/Donate.h"static const CGFloat kMargin = 24;static const CGFloat kCardRadius = 22;@@ -227,11 +228,18 @@ static UIButton *glassButton(NSString *title) {_beta = [self betaNote];_beta.hidden = !redesign;- UIStackView *column = [[UIStackView alloc] initWithArrangedSubviews:@[strip, heading, _redesigned, _legacy, _beta]];+ SGKofiButton *kofi = [[SGKofiButton alloc] initWithTitle:@"Buy a student a coffee" prominent:NO];+ kofi.translatesAutoresizingMaskIntoConstraints = NO;+ [kofi addAction:[UIAction actionWithHandler:^(UIAction *action) { SGOpenURL(SGKofiURL); }] forControlEvents:UIControlEventTouchUpInside];+ UIView *kofiStrip = [UIView new];+ [kofiStrip addSubview:kofi];++ UIStackView *column = [[UIStackView alloc] initWithArrangedSubviews:@[strip, heading, _redesigned, _legacy, _beta, kofiStrip]];column.axis = UILayoutConstraintAxisVertical;column.spacing = 12;[column setCustomSpacing:28 afterView:strip];[column setCustomSpacing:24 afterView:heading];+ [column setCustomSpacing:36 afterView:_beta];column.translatesAutoresizingMaskIntoConstraints = NO;UIScrollView *scroll = [UIScrollView new];@@ -271,6 +279,10 @@ static UIButton *glassButton(NSString *title) {[halo.heightAnchor constraintEqualToConstant:88],[_hero.centerXAnchor constraintEqualToAnchor:halo.centerXAnchor],[_hero.centerYAnchor constraintEqualToAnchor:halo.centerYAnchor],+ [kofi.centerXAnchor constraintEqualToAnchor:kofiStrip.centerXAnchor],+ [kofi.topAnchor constraintEqualToAnchor:kofiStrip.topAnchor],+ [kofi.bottomAnchor constraintEqualToAnchor:kofiStrip.bottomAnchor],+ [kofi.leadingAnchor constraintGreaterThanOrEqualToAnchor:kofiStrip.leadingAnchor],[_primary.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor constant:kMargin],[_primary.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor constant:-kMargin],[_primary.bottomAnchor constraintEqualToAnchor:footer.topAnchor constant:-12],