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: one font applies throughout the app under either look

My-Name-Is-Jeffb006850848d4
diff --git a/docs/tweaks.md b/docs/tweaks.md
index a8c11cb3..ba6ec332 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -239,7 +239,7 @@ setting by the part of Spotify it changes, so a part's glass, its hide switches
one page, the mod's own rows first and Spotify's flags below them or on a sub page named after what
they change. It opens on the Appearance card: Redesigned UI, then the stored look's accent colour, and in the native
look AMOLED (the redesign is always black); Spotify's green is offered from the colour row once a colour
-is set. Redesigned UI is the one switch between the two looks (see Layers): it glows
+is set. Last comes the Font, under either look and on any iOS, below 26 too. Redesigned UI is the one switch between the two looks (see Layers): it glows
(Settings/SGGlowSwitch), its ⓘ says what it changes, and flipping it offers to restart Spotify.
The pages show only what the stored look has: a page opened after flipping the switch already shows
what the restart will bring. Then a card of parts. Navbar: the tab editor of the stored look, each with
diff --git a/harness/album/build.sh b/harness/album/build.sh
index 33778744..45693ce6 100755
--- a/harness/album/build.sh
+++ b/harness/album/build.sh
@@ -4,7 +4,7 @@ SRC=$(cd "$(dirname "$0")/../../tweak/Sources" && pwd)
OUT=$(dirname "$0")/build
rm -rf "$OUT"; mkdir -p "$OUT/gen" "$OUT/AlbumHarness.app"
-for f in Redesigned/Album/AlbumField.x Redesigned/Album/AlbumHeader.x Redesigned/Album/AlbumRows.x Redesigned/Album/AlbumSections.x; do
+for f in Shared/Fonts/Fonts.x Redesigned/Album/AlbumField.x Redesigned/Album/AlbumHeader.x Redesigned/Album/AlbumRows.x Redesigned/Album/AlbumSections.x; do
name=$(basename "$f" .x)
"$THEOS/bin/logos.pl" -c generator=internal "$SRC/$f" > "$OUT/gen/$name.m"
done
diff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.m
index b8579c2f..16bd2ec0 100644
--- a/tweak/Sources/App/Pages.m
+++ b/tweak/Sources/App/Pages.m
@@ -1,4 +1,5 @@
#import "Core/SGCore.h"
+#import "Shared/Fonts/Fonts.h"
#import "Shared/LyricsTranslation/LyricsTranslation.h"
#import "Redesigned/Player/Player.h"
#import "Settings/SGModPage.h"
@@ -51,9 +52,12 @@ static SGModRow *unavailableRow(void) {
}
SGModSection *SGAppearanceSection(void) {
+ // Fonts.x works under either look on any iOS, so the row is on the card either way.
+ SGModRow *font = SGWithSymbol(SGChoiceRow(@"Font", nil, SGKeyAppFont, SGAppFontNames(), SGAppFontSpotify), @"textformat");
if (!SGRedesignAvailable()) {
NSMutableArray<SGModRow *> *rows = [NSMutableArray arrayWithObject:unavailableRow()];
[rows addObjectsFromArray:SGNativeAppearanceRows()];
+ [rows addObject:font];
return SGNotedSection(@"Appearance", rows, @"Changes apply after you restart Spotify.");
}
SGModRow *redesign = SGOptionRow(@"Redesigned UI", nil, SGKeyRedesign);
@@ -65,6 +69,7 @@ SGModSection *SGAppearanceSection(void) {
};
NSMutableArray<SGModRow *> *rows = [NSMutableArray arrayWithObject:SGWithSymbol(redesign, @"sparkles")];
[rows addObjectsFromArray:SGRedesignedUIStored() ? SGRAppearanceRows() : SGNativeAppearanceRows()];
+ [rows addObject:font];
return SGNotedSection(@"Appearance", rows, @"Changes apply after you restart Spotify.");
}
diff --git a/tweak/Sources/Shared/Fonts/Fonts.h b/tweak/Sources/Shared/Fonts/Fonts.h
new file mode 100644
index 00000000..29f6ff22
--- /dev/null
+++ b/tweak/Sources/Shared/Fonts/Fonts.h
@@ -0,0 +1,15 @@
+// One font for the whole app (Fonts.x), chosen on the Appearance card under either look.
+#import <UIKit/UIKit.h>
+
+#define SGKeyAppFont @"spotifyglass.font"
+
+typedef NS_ENUM(NSInteger, SGAppFont) {
+ SGAppFontSpotify, // Spotify's own, untouched
+ SGAppFontSystem, // San Francisco
+ SGAppFontRounded, // SF Rounded
+ SGAppFontSerif, // New York
+ SGAppFontMono, // SF Mono
+};
+
+SGAppFont SGAppFontChosen(void);
+NSArray<NSString *> *SGAppFontNames(void);
diff --git a/tweak/Sources/Shared/Fonts/Fonts.x b/tweak/Sources/Shared/Fonts/Fonts.x
new file mode 100644
index 00000000..9e5fdaad
--- /dev/null
+++ b/tweak/Sources/Shared/Fonts/Fonts.x
@@ -0,0 +1,91 @@
+// One font for the whole app, under either look: Spotify's own (Circular and Spotify Mix, a file per
+// script in SpotifyShared's Fonts.bundle), or the system's in one of its designs. Spotify asks for its
+// fonts by name, so a name from its two families comes back as the system font at the same size, with
+// the weight its name ends in. The rounded, serif and monospaced designs reach the system font too, so
+// the mod's own text follows. Read at launch.
+#import "Core/SGCore.h"
+#import "Shared/Fonts/Fonts.h"
+
+static SGAppFont sg_font;
+
+static BOOL spotifys(NSString *name) {
+ return [name hasPrefix:@"CircularSp"] || [name hasPrefix:@"SpotifyMix"] || [name hasPrefix:@"Circular"];
+}
+
+// "CircularSp-Bold", "SpotifyMixUITitle-Arab-Extrabold": the weight is the last word.
+static UIFontWeight weightOf(NSString *name) {
+ NSString *last = [[name componentsSeparatedByString:@"-"].lastObject lowercaseString];
+ if ([last containsString:@"black"] || [last containsString:@"extrabold"] || [last containsString:@"heavy"]) return UIFontWeightHeavy;
+ if ([last containsString:@"bold"]) return UIFontWeightBold;
+ if ([last containsString:@"medium"]) return UIFontWeightMedium;
+ if ([last containsString:@"light"]) return UIFontWeightLight;
+ return UIFontWeightRegular;
+}
+
+static UIFontDescriptorSystemDesign designOf(SGAppFont font) {
+ switch (font) {
+ case SGAppFontRounded: return UIFontDescriptorSystemDesignRounded;
+ case SGAppFontSerif: return UIFontDescriptorSystemDesignSerif;
+ case SGAppFontMono: return UIFontDescriptorSystemDesignMonospaced;
+ default: return UIFontDescriptorSystemDesignDefault;
+ }
+}
+
+static UIFont *designed(UIFont *font) {
+ if (sg_font < SGAppFontRounded || !font) return font;
+ UIFontDescriptor *descriptor = [font.fontDescriptor fontDescriptorWithDesign:designOf(sg_font)];
+ return descriptor ? [UIFont fontWithDescriptor:descriptor size:font.pointSize] : font;
+}
+
+static UIFont *systemFor(NSString *name, CGFloat size) {
+ return designed([UIFont systemFontOfSize:size weight:weightOf(name)]);
+}
+
+%hook UIFont
++ (UIFont *)fontWithName:(NSString *)name size:(CGFloat)size {
+ if (spotifys(name)) return systemFor(name, size);
+ return %orig;
+}
+
++ (UIFont *)fontWithDescriptor:(UIFontDescriptor *)descriptor size:(CGFloat)size {
+ NSString *name = descriptor.fontAttributes[UIFontDescriptorNameAttribute] ?: descriptor.fontAttributes[UIFontDescriptorFamilyAttribute];
+ if (spotifys(name)) return systemFor(name, size > 0 ? size : descriptor.pointSize);
+ return %orig;
+}
+%end
+
+%group Designs
+%hook UIFont
++ (UIFont *)systemFontOfSize:(CGFloat)size weight:(UIFontWeight)weight {
+ UIFont *font = %orig;
+ return designed(font);
+}
+
++ (UIFont *)systemFontOfSize:(CGFloat)size {
+ UIFont *font = %orig;
+ return designed(font);
+}
+
++ (UIFont *)boldSystemFontOfSize:(CGFloat)size {
+ UIFont *font = %orig;
+ return designed(font);
+}
+%end
+%end
+
+SGAppFont SGAppFontChosen(void) {
+ NSInteger font = SGInt(SGKeyAppFont, SGAppFontSpotify);
+ return font >= SGAppFontSpotify && font <= SGAppFontMono ? font : SGAppFontSpotify;
+}
+
+NSArray<NSString *> *SGAppFontNames(void) {
+ return @[@"Spotify", @"System", @"Rounded", @"Serif", @"Mono"];
+}
+
+%ctor {
+ sg_font = SGAppFontChosen();
+ if (sg_font == SGAppFontSpotify) return;
+ %init;
+ if (sg_font >= SGAppFontRounded) %init(Designs);
+ SGLog(@"fonts: %@ in place of Spotify's", SGAppFontNames()[sg_font]);
+}