From 815d03d03df3e7f033021f5c0c7de8410c040683 Mon Sep 17 00:00:00 2001 From: Jack Matthews Date: Sat, 13 May 2023 04:05:05 -0400 Subject: [PATCH] [Themes] Hook native colors earlier --- Sources/VendettaTweak/Tweak.x.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sources/VendettaTweak/Tweak.x.swift b/Sources/VendettaTweak/Tweak.x.swift index 253045c..59c935d 100644 --- a/Sources/VendettaTweak/Tweak.x.swift +++ b/Sources/VendettaTweak/Tweak.x.swift @@ -89,10 +89,6 @@ class LoadHook: ClassHook { { orig.executeApplicationScript( "globalThis.__vendetta_theme=\(themeString)".data(using: .utf8)!, url: source, async: false) - let theme = try? JSONDecoder().decode(Theme.self, from: themeString.data(using: .utf8)!) - if let semanticColors = theme?.data.semanticColors { swizzleDCDThemeColor(semanticColors) } - if let rawColors = theme?.data.rawColors { swizzleUIColor(rawColors) } - } if vendetta != nil { @@ -103,3 +99,14 @@ class LoadHook: ClassHook { } } } + +struct VendettaTweak: Tweak { + func tweakDidActivate() { + if let themeData = try? Data( + contentsOf: documentDirectory.appendingPathComponent("vendetta_theme.json")) { + let theme = try? JSONDecoder().decode(Theme.self, from: themeData) + if let semanticColors = theme?.data.semanticColors { swizzleDCDThemeColor(semanticColors) } + if let rawColors = theme?.data.rawColors { swizzleUIColor(rawColors) } + } + } +}