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: offer the donate sheet after the first tour

Vojtěch Škopekcb7bf69db0d3
diff --git a/tweak/Sources/App/Donate/Donate.h b/tweak/Sources/App/Donate/Donate.h
index 734a58fa..47ab750e 100644
--- a/tweak/Sources/App/Donate/Donate.h
+++ b/tweak/Sources/App/Donate/Donate.h
@@ -1,5 +1,5 @@
-// 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.
+// Donate: Ko-fi, asked for from the Mod Settings row, a sheet after the first welcome tour (after its
+// restart when the look changed), then two days on and every fourteen after that.
#import <UIKit/UIKit.h>
#import "Settings/SGModPage.h"
@@ -14,3 +14,7 @@ UIColor *SGKofiColor(void);
void SGShowDonateSheet(void);
SGModRow *SGDonateRow(void);
void SGWatchForDonate(void);
+// The first tour is done: the sheet follows it, or follows Home after the restart.
+void SGDonateAfterTour(BOOL restarting);
+BOOL SGDonateAfterTourPending(void);
+void SGOfferDonate(void);
diff --git a/tweak/Sources/App/Donate/Donate.m b/tweak/Sources/App/Donate/Donate.m
index 37c9d985..e32e1258 100644
--- a/tweak/Sources/App/Donate/Donate.m
+++ b/tweak/Sources/App/Donate/Donate.m
@@ -8,6 +8,7 @@ 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 NSString *const kAfterTourKey = @"spotipw.donate.aftertour";
static const NSTimeInterval kDay = 86400;
static const NSTimeInterval kFirstAsk = 2 * kDay, kEvery = 14 * kDay, kAfterDonating = 90 * kDay;
static const NSTimeInterval kSettle = 20, kRetry = 5;
@@ -240,6 +241,10 @@ static void askAgainIn(NSTimeInterval wait) {
[NSUserDefaults.standardUserDefaults setDouble:now() + wait forKey:kNextKey];
}
+BOOL SGDonateAfterTourPending(void) {
+ return [NSUserDefaults.standardUserDefaults boolForKey:kAfterTourKey];
+}
+
#pragma mark - sheet
static const CGFloat kCardMargin = 10, kCardPadding = 26;
@@ -476,7 +481,8 @@ SGModRow *SGDonateRow(void) {
// 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;
+ BOOL afterTour = SGDonateAfterTourPending();
+ if (sg_offered || (!afterTour && now() < nextAsk()) || SGUpdateNoticeShown()) return;
UIViewController *top = SGTopController();
BOOL busy = !top || SGOnboardingShowing() || [top isKindOfClass:UIAlertController.class]
|| UIApplication.sharedApplication.applicationState != UIApplicationStateActive;
@@ -487,8 +493,18 @@ static void offerWhenClear(NSInteger tries) {
}
sg_offered = YES;
askAgainIn(kEvery);
+ [NSUserDefaults.standardUserDefaults removeObjectForKey:kAfterTourKey];
SGShowDonateSheet();
- SGLog(@"donate: asked over %@", NSStringFromClass(top.class));
+ SGLog(@"donate: asked over %@%@", NSStringFromClass(top.class), afterTour ? @", after the tour" : @"");
+}
+
+void SGDonateAfterTour(BOOL restarting) {
+ [NSUserDefaults.standardUserDefaults setBool:YES forKey:kAfterTourKey];
+ if (!restarting) SGOfferDonate();
+}
+
+void SGOfferDonate(void) {
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ offerWhenClear(kTries); });
}
void SGWatchForDonate(void) {
diff --git a/tweak/Sources/App/Onboarding/Onboarding.x b/tweak/Sources/App/Onboarding/Onboarding.x
index 00c40b75..0d6bef99 100644
--- a/tweak/Sources/App/Onboarding/Onboarding.x
+++ b/tweak/Sources/App/Onboarding/Onboarding.x
@@ -1,7 +1,9 @@
// 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.
+// A tour that ended in a restart leaves the donate sheet for this Home instead.
#import "Core/SGCore.h"
#import "Onboarding.h"
+#import "App/Donate/Donate.h"
%hook _TtC19Home_FunkisPageImpl20FunkisViewController
- (void)viewDidAppear:(BOOL)animated {
@@ -9,14 +11,15 @@
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();
+ if (SGFlag(SGKeyOnboardingSeen, NO)) SGOfferDonate();
+ else SGShowOnboarding();
});
});
}
%end
%ctor {
- if (SGFlag(SGKeyOnboardingSeen, NO)) return;
+ if (SGFlag(SGKeyOnboardingSeen, NO) && !SGDonateAfterTourPending()) return;
%init;
SGRequireClasses(@[@"_TtC19Home_FunkisPageImpl20FunkisViewController"]);
}
diff --git a/tweak/Sources/App/Onboarding/Tour.m b/tweak/Sources/App/Onboarding/Tour.m
index 60980590..fc40fbcb 100644
--- a/tweak/Sources/App/Onboarding/Tour.m
+++ b/tweak/Sources/App/Onboarding/Tour.m
@@ -228,18 +228,11 @@ static UIButton *glassButton(NSString *title) {
_beta = [self betaNote];
_beta.hidden = !redesign;
- 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]];
+ UIStackView *column = [[UIStackView alloc] initWithArrangedSubviews:@[strip, heading, _redesigned, _legacy, _beta]];
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];
@@ -279,10 +272,6 @@ 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],
@@ -326,6 +315,7 @@ static UIButton *glassButton(NSString *title) {
}
- (void)finish {
+ if (!SGFlag(SGKeyOnboardingSeen, NO)) SGDonateAfterTour(self.needsRestart);
SGSetEnabled(SGKeyOnboardingSeen, YES);
SGSetRedesignedUI(_redesigned.selected);
if (self.needsRestart) {