forked from BandarHL/BHTwitter
-
Notifications
You must be signed in to change notification settings - Fork 218
Expand file tree
/
Copy pathTweak.x
More file actions
4704 lines (3948 loc) · 187 KB
/
Tweak.x
File metadata and controls
4704 lines (3948 loc) · 187 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// Tweak.x
// BHTwitter/NeoFreeBird
//
// Created by BandarHelal
// Modified by nyaathea
//
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h> // For objc_msgSend and objc_msgSend_stret
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
#import <WebKit/WebKit.h>
#import <dlfcn.h>
#import "SAMKeychain/AuthViewController.h"
#import "Colours/Colours.h"
#import "BHTManager.h"
#import "BHDimPalette.h"
#import <math.h>
#import "BHTBundle/BHTBundle.h"
#import "TWHeaders.h"
#import "SAMKeychain/SAMKeychain.h"
#import "CustomTabBar/BHCustomTabBarUtility.h"
#import <Preferences/PSListController.h>
#import <Preferences/PSSpecifier.h>
#import "ModernSettingsViewController.h"
@class T1SettingsViewController;
// Forward declarations
static void BHT_UpdateAllTabBarIcons(void);
static void BHT_applyThemeToWindow(UIWindow *window);
static void BHT_ensureTheming(void);
static void BHT_forceRefreshAllWindowAppearances(void);
static void BHT_ensureThemingEngineSynchronized(BOOL forceSynchronize);
static UIViewController* getViewControllerForView(UIView *view);
static char kBHTSourceTapAddedKey;
// Theme state tracking
static BOOL BHT_themeManagerInitialized = NO;
static BOOL BHT_isInThemeChangeOperation = NO;
// Map to store timestamp labels for each player instance
static NSMapTable<T1ImmersiveFullScreenViewController *, UILabel *> *playerToTimestampMap = nil;
// Performance optimization: Cache for label searches to avoid repeated expensive traversals
static NSMapTable<T1ImmersiveFullScreenViewController *, NSNumber *> *labelSearchCache = nil;
static NSTimeInterval lastCacheInvalidation = 0;
static const NSTimeInterval CACHE_INVALIDATION_INTERVAL = 10.0; // 10 seconds
// Static helper function for recursive view traversal - OPTIMIZED VERSION
static void BH_EnumerateSubviewsRecursively(UIView *view, void (^block)(UIView *currentView)) {
if (!view || !block) return;
// Performance optimization: Skip hidden views and their subviews
if (view.hidden || view.alpha <= 0.01) return;
block(view);
// Performance optimization: Limit recursion depth to prevent excessive traversal
static NSInteger recursionDepth = 0;
if (recursionDepth > 15) return; // Reasonable depth limit
recursionDepth++;
for (UIView *subview in view.subviews) {
BH_EnumerateSubviewsRecursively(subview, block);
}
recursionDepth--;
}
// MARK: imports to hook into Twitters TAE color system
UIColor *BHTCurrentAccentColor(void) {
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
if (!TAEColorSettingsCls) {
return [UIColor systemBlueColor];
}
id settings = [TAEColorSettingsCls sharedSettings];
id current = [settings currentColorPalette];
id palette = [current colorPalette];
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
if ([defs objectForKey:@"bh_color_theme_selectedColor"]) {
NSInteger opt = [defs integerForKey:@"bh_color_theme_selectedColor"];
return [palette primaryColorForOption:opt] ?: [UIColor systemBlueColor];
}
if ([defs objectForKey:@"T1ColorSettingsPrimaryColorOptionKey"]) {
NSInteger opt = [defs integerForKey:@"T1ColorSettingsPrimaryColorOptionKey"];
return [palette primaryColorForOption:opt] ?: [UIColor systemBlueColor];
}
return [UIColor systemBlueColor];
}
// Helper function to get Twitter's current dark mode state
static BOOL BHT_isTwitterDarkThemeActive() {
Class TAEColorSettingsCls = objc_getClass("TAEColorSettings");
if (!TAEColorSettingsCls) {
if (@available(iOS 13.0, *)) {
return UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
}
return NO; // Default to light mode if essential classes are missing
}
id settings = [TAEColorSettingsCls sharedSettings];
if (!settings || ![settings respondsToSelector:@selector(currentColorPalette)]) {
if (@available(iOS 13.0, *)) {
return UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
}
return NO;
}
id currentPaletteContainer = [settings currentColorPalette]; // This is TAEThemeColorPalette
// TAETwitterColorPaletteSettingInfo is returned by [TAEThemeColorPalette colorPalette]
if (!currentPaletteContainer || ![currentPaletteContainer respondsToSelector:@selector(colorPalette)]) {
if (@available(iOS 13.0, *)) {
return UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
}
return NO;
}
id actualPaletteInfo = [currentPaletteContainer colorPalette];
if (actualPaletteInfo && [actualPaletteInfo respondsToSelector:@selector(isDark)]) {
// Use objc_msgSend to call the isDark method
return ((BOOL (*)(id, SEL))objc_msgSend)(actualPaletteInfo, @selector(isDark));
}
// Fallback to system trait if Twitter's internal state is inaccessible
if (@available(iOS 13.0, *)) {
return UITraitCollection.currentTraitCollection.userInterfaceStyle == UIUserInterfaceStyleDark;
}
return NO;
}
// ===== Padlock helpers (new) =====
static const NSInteger BHTPadlockOverlayTag = 909;
static NSArray<UIWindow *> *BHT_allActiveWindows(void) {
NSMutableArray<UIWindow *> *result = [NSMutableArray array];
if (@available(iOS 13.0, *)) {
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
if (scene.activationState == UISceneActivationStateForegroundActive &&
[scene isKindOfClass:[UIWindowScene class]]) {
UIWindowScene *ws = (UIWindowScene *)scene;
for (UIWindow *w in ws.windows) {
if (!w.hidden) [result addObject:w];
}
}
}
}
if (result.count == 0) {
for (UIWindow *w in UIApplication.sharedApplication.windows) {
if (!w.hidden) [result addObject:w];
}
}
return result;
}
static UIWindow *BHT_activeKeyWindow(void) {
if (@available(iOS 13.0, *)) {
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
if (scene.activationState == UISceneActivationStateForegroundActive &&
[scene isKindOfClass:[UIWindowScene class]]) {
UIWindowScene *ws = (UIWindowScene *)scene;
for (UIWindow *w in ws.windows) {
if (w.isKeyWindow) return w;
}
for (UIWindow *w in ws.windows) {
if (!w.hidden) return w;
}
}
}
}
for (UIWindow *w in UIApplication.sharedApplication.windows) {
if (w.isKeyWindow) return w;
}
for (UIWindow *w in UIApplication.sharedApplication.windows) {
if (!w.hidden) return w;
}
return nil;
}
static UIViewController *BHT_topViewController(UIViewController *root) {
if (!root) return nil;
UIViewController *vc = root;
while (vc.presentedViewController) {
vc = vc.presentedViewController;
}
if ([vc isKindOfClass:[UINavigationController class]]) {
vc = ((UINavigationController *)vc).visibleViewController ?: vc;
}
if ([vc isKindOfClass:[UITabBarController class]]) {
UIViewController *sel = ((UITabBarController *)vc).selectedViewController;
if (sel) vc = sel;
}
return vc;
}
static void BHT_showPadlockOverlay(void) {
UIWindow *window = BHT_activeKeyWindow();
if (!window) return;
for (UIWindow *w in BHT_allActiveWindows()) {
for (UIView *v in w.subviews) {
if (v.tag == BHTPadlockOverlayTag) [v removeFromSuperview];
}
}
UIView *overlay = [[UIView alloc] initWithFrame:window.bounds];
overlay.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
overlay.backgroundColor = UIColor.systemBackgroundColor;
overlay.userInteractionEnabled = YES;
overlay.tag = BHTPadlockOverlayTag;
UIImageView *icon = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:@"lock.fill"]];
icon.translatesAutoresizingMaskIntoConstraints = NO;
icon.tintColor = UIColor.labelColor;
UILabel *label = [[UILabel alloc] init];
label.translatesAutoresizingMaskIntoConstraints = NO;
label.text = @"Locked";
label.textColor = UIColor.labelColor;
label.font = [UIFont systemFontOfSize:22 weight:UIFontWeightSemibold];
label.textAlignment = NSTextAlignmentCenter;
[overlay addSubview:icon];
[overlay addSubview:label];
[NSLayoutConstraint activateConstraints:@[
[icon.centerXAnchor constraintEqualToAnchor:overlay.centerXAnchor],
[icon.centerYAnchor constraintEqualToAnchor:overlay.centerYAnchor constant:-20],
[label.centerXAnchor constraintEqualToAnchor:overlay.centerXAnchor],
[label.topAnchor constraintEqualToAnchor:icon.bottomAnchor constant:8]
]];
[window addSubview:overlay];
}
static void BHT_removePadlockOverlay(void) {
for (UIWindow *w in BHT_allActiveWindows()) {
NSMutableArray<UIView *> *toRemove = [NSMutableArray array];
for (UIView *v in w.subviews) {
if (v.tag == BHTPadlockOverlayTag) [toRemove addObject:v];
}
for (UIView *v in toRemove) [v removeFromSuperview];
}
}
static BOOL BHT_isAuthenticated(void) {
NSDictionary *keychainData = [[keychain shared] getData];
if (!keychainData) return NO;
id val = keychainData[@"isAuthenticated"];
return [val respondsToSelector:@selector(boolValue)] ? [val boolValue] : NO;
}
static void BHT_setAuthenticated(BOOL yes) {
[[keychain shared] saveDictionary:@{@"isAuthenticated": @(yes)}];
}
static void BHT_presentAuthIfNeeded(void) {
if (BHT_isAuthenticated()) {
BHT_removePadlockOverlay();
return;
}
UIWindow *window = BHT_activeKeyWindow();
if (!window) {
BHT_showPadlockOverlay();
return;
}
UIViewController *root = window.rootViewController;
if (!root) {
window.rootViewController = [UIViewController new];
root = window.rootViewController;
}
UIViewController *host = BHT_topViewController(root);
AuthViewController *auth = [[AuthViewController alloc] init];
auth.modalPresentationStyle = UIModalPresentationFullScreen;
if ([auth respondsToSelector:@selector(setModalInPresentation:)]) {
auth.modalInPresentation = YES;
}
if (host.presentedViewController == nil) {
[host presentViewController:auth animated:NO completion:nil];
} else {
[host dismissViewControllerAnimated:NO completion:^{
UIViewController *newTop = BHT_topViewController(root);
[newTop presentViewController:auth animated:NO completion:nil];
}];
}
}
static UIFont * _Nullable TAEStandardFontGroupReplacement(UIFont *self, SEL _cmd, CGFloat arg1, CGFloat arg2) {
BH_BaseImp orig = originalFontsIMP[NSStringFromSelector(_cmd)].pointerValue;
NSUInteger nArgs = [[self class] instanceMethodSignatureForSelector:_cmd].numberOfArguments;
UIFont *origFont;
switch (nArgs) {
case 2:
origFont = orig(self, _cmd);
break;
case 3:
origFont = orig(self, _cmd, arg1);
break;
case 4:
origFont = orig(self, _cmd, arg1, arg2);
break;
default:
// Should not be reachable, as it was verified before swizzling
origFont = orig(self, _cmd);
break;
};
UIFont *newFont = BH_getDefaultFont(origFont);
return newFont != nil ? newFont : origFont;
}
static void batchSwizzlingOnClass(Class cls, NSArray<NSString*>*origSelectors, IMP newIMP){
for (NSString *sel in origSelectors) {
SEL origSel = NSSelectorFromString(sel);
Method origMethod = class_getInstanceMethod(cls, origSel);
if (origMethod != NULL) {
IMP oldImp = class_replaceMethod(cls, origSel, newIMP, method_getTypeEncoding(origMethod));
[originalFontsIMP setObject:[NSValue valueWithPointer:oldImp] forKey:sel];
} else {
NSLog(@"[BHTwitter] Can't find method (%@) in Class (%@)", sel, NSStringFromClass(cls));
}
}
}
// MARK: - Core TAE Color hooks
%hook TAEColorSettings
- (instancetype)init {
id instance = %orig;
if (instance && !BHT_themeManagerInitialized) {
// Register for system theme and appearance related notifications
[[NSNotificationCenter defaultCenter] addObserverForName:@"UITraitCollectionDidChangeNotification"
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification * _Nonnull note) {
if ([NSUserDefaults.standardUserDefaults objectForKey:@"bh_color_theme_selectedColor"]) {
dispatch_async(dispatch_get_main_queue(), ^{
BHT_ensureThemingEngineSynchronized(NO);
});
}
}];
// Also listen for app entering foreground
[[NSNotificationCenter defaultCenter] addObserverForName:@"UIApplicationWillEnterForegroundNotification"
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification * _Nonnull note) {
if ([NSUserDefaults.standardUserDefaults objectForKey:@"bh_color_theme_selectedColor"]) {
dispatch_async(dispatch_get_main_queue(), ^{
BHT_ensureThemingEngineSynchronized(YES);
});
}
}];
BHT_themeManagerInitialized = YES;
}
return instance;
}
- (void)setPrimaryColorOption:(NSInteger)colorOption {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// If we have a BHTwitter theme selected, ensure it takes precedence
if ([defaults objectForKey:@"bh_color_theme_selectedColor"]) {
NSInteger ourSelectedOption = [defaults integerForKey:@"bh_color_theme_selectedColor"];
// Only allow changes that match our selection (avoids fighting with Twitter's system)
if (colorOption == ourSelectedOption || BHT_isInThemeChangeOperation) {
%orig(colorOption);
} else {
// If not from our theme operation, apply our own theme instead
%orig(ourSelectedOption);
// Also ensure Twitter's defaults match our setting for consistency
[defaults setObject:@(ourSelectedOption) forKey:@"T1ColorSettingsPrimaryColorOptionKey"];
}
} else {
// No BHTwitter theme active, let Twitter handle it normally
%orig(colorOption);
}
}
- (void)applyCurrentColorPalette {
%orig;
// Signal UI to refresh after Twitter applies its palette
if ([NSUserDefaults.standardUserDefaults objectForKey:@"bh_color_theme_selectedColor"] &&
!BHT_isInThemeChangeOperation &&
[BHTManager classicTabBarEnabled]) {
// This call happens after Twitter has applied its color changes,
// so we need to refresh our tab bar theming
dispatch_async(dispatch_get_main_queue(), ^{
BHT_UpdateAllTabBarIcons();
});
}
}
%end
%hook T1ColorSettings
+ (void)_t1_applyPrimaryColorOption {
// Execute original implementation to let Twitter update its internal state
%orig;
// If we have an active theme, ensure it's properly applied
if ([NSUserDefaults.standardUserDefaults objectForKey:@"bh_color_theme_selectedColor"]) {
// Synchronize our theme if needed (without forcing)
BHT_ensureThemingEngineSynchronized(NO);
}
}
+ (void)_t1_updateOverrideUserInterfaceStyle {
// Let Twitter update its UI style
%orig;
// Ensure our theme isn't lost during dark/light mode changes
if ([NSUserDefaults.standardUserDefaults objectForKey:@"bh_color_theme_selectedColor"] &&
[BHTManager classicTabBarEnabled]) {
dispatch_async(dispatch_get_main_queue(), ^{
BHT_UpdateAllTabBarIcons();
});
}
}
%end
%hook NSUserDefaults
- (void)setObject:(id)value forKey:(NSString *)defaultName {
// Protect our custom theme from being overwritten by Twitter
if ([defaultName isEqualToString:@"T1ColorSettingsPrimaryColorOptionKey"]) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
id selectedColor = [defaults objectForKey:@"bh_color_theme_selectedColor"];
if (selectedColor != nil && !BHT_isInThemeChangeOperation) {
// If our theme is active and this change isn't part of our operation,
// only allow the change if it matches our selection
if (![value isEqual:selectedColor]) {
// Silently reject the change, our theme has priority
return;
}
}
}
%orig;
}
%end
// MARK: App Delegate hooks
%hook T1AppDelegate
- (_Bool)application:(UIApplication *)application didFinishLaunchingWithOptions:(id)arg2 {
_Bool orig = %orig;
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"FirstRun_4.3"]) {
[[NSUserDefaults standardUserDefaults] setValue:@"1strun" forKey:@"FirstRun_4.3"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"dw_v"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"hide_promoted"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"voice"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"undo_tweet"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"TrustedFriends"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"disableSensitiveTweetWarnings"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"disable_immersive_player"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"custom_voice_upload"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"hide_premium_offer"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"disableMediaTab"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"disableArticles"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"disableHighlights"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"hide_view_count"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"hide_grok_analyze"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"restore_reply_context"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"disable_xchat"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"hide_topics"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"hide_topics_to_follow"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"hide_who_to_follow"];
[[NSUserDefaults standardUserDefaults] setBool:true forKey:@"no_tab_bar_hiding"];
}
[BHTManager cleanCache];
if ([BHTManager FLEX]) {
[[%c(FLEXManager) sharedManager] showExplorer];
}
// Apply theme immediately after launch - simplified version using our new system
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"bh_color_theme_selectedColor"]) {
dispatch_async(dispatch_get_main_queue(), ^{
// Force synchronize our theme with Twitter's internal theme system
BHT_ensureThemingEngineSynchronized(YES);
});
}
// Start the cookie initialization process with retry mechanism
if ([BHTManager RestoreTweetLabels]) {
dispatch_async(dispatch_get_main_queue(), ^{
[TweetSourceHelper initializeCookiesWithRetry];
});
}
return orig;
}
- (void)applicationDidBecomeActive:(id)arg1 {
%orig;
// Re-apply theming and other existing logic …
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"bh_color_theme_selectedColor"]) {
BHT_ensureThemingEngineSynchronized(YES);
}
if ([BHTManager RestoreTweetLabels]) {
dispatch_async(dispatch_get_main_queue(), ^{
[TweetSourceHelper initializeCookiesWithRetry];
});
}
if ([BHTManager Padlock]) {
if (BHT_isAuthenticated()) {
BHT_removePadlockOverlay();
} else {
BHT_showPadlockOverlay();
dispatch_async(dispatch_get_main_queue(), ^{
BHT_presentAuthIfNeeded();
});
}
// Safety recheck in case Face ID completes very quickly
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
if (BHT_isAuthenticated()) {
BHT_removePadlockOverlay();
}
});
} else {
BHT_removePadlockOverlay();
}
}
- (void)applicationWillResignActive:(id)arg1 {
%orig;
if ([BHTManager RestoreTweetLabels]) {
[TweetSourceHelper cleanupTimersForBackground];
}
if ([BHTManager Padlock]) {
// Cover UI immediately
BHT_showPadlockOverlay();
// Mark unauthenticated so a reopen from background will prompt again
BHT_setAuthenticated(NO);
}
if ([BHTManager FLEX]) {
[[%c(FLEXManager) sharedManager] showExplorer];
}
}
- (void)applicationDidEnterBackground:(id)arg1 {
%orig;
if ([BHTManager Padlock]) {
// Redundant, ensures state is locked while backgrounded
BHT_setAuthenticated(NO);
BHT_showPadlockOverlay();
}
}
- (void)applicationWillEnterForeground:(id)arg1 {
%orig;
if ([BHTManager Padlock]) {
// Keep UI covered during transition
BHT_showPadlockOverlay();
}
}
- (void)applicationWillTerminate:(id)arg1 {
%orig;
if ([BHTManager Padlock]) {
BHT_setAuthenticated(NO);
BHT_removePadlockOverlay();
}
}
%end
%hook AuthViewController
- (void)viewDidDisappear:(BOOL)animated {
%orig;
if (BHT_isAuthenticated()) {
BHT_removePadlockOverlay();
}
}
%end
// MARK: prevent tab bar fade
%hook T1TabBarViewController
- (void)setTabBarScrolling:(BOOL)scrolling {
if ([BHTManager stopHidingTabBar]) {
%orig(NO); // Force scrolling to NO if fading is prevented
} else {
%orig(scrolling);
}
}
- (void)loadView {
%orig;
NSArray <NSString *> *hiddenBars = [BHCustomTabBarUtility getHiddenTabBars];
for (T1TabView *tabView in self.tabViews) {
if ([hiddenBars containsObject:tabView.scribePage]) {
[tabView setHidden:true];
}
}
}
%end
%hook T1DirectMessageConversationEntriesViewController
- (void)viewDidLoad {
%orig;
if ([BHTManager changeBackground]) {
if ([BHTManager backgroundImage]) { // set the backgeound as image
NSFileManager *manager = [NSFileManager defaultManager];
NSString *DocPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true).firstObject;
NSURL *imagePath = [[NSURL fileURLWithPath:DocPath] URLByAppendingPathComponent:@"msg_background.png"];
if ([manager fileExistsAtPath:imagePath.path]) {
UIImageView *backgroundImage = [[UIImageView alloc] initWithFrame:UIScreen.mainScreen.bounds];
backgroundImage.image = [UIImage imageNamed:imagePath.path];
[backgroundImage setContentMode:UIViewContentModeScaleAspectFill];
[self.view insertSubview:backgroundImage atIndex:0];
}
}
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"background_color"]) { // set the backgeound as color
NSString *hexCode = [[NSUserDefaults standardUserDefaults] objectForKey:@"background_color"];
UIColor *selectedColor = [UIColor colorFromHexString:hexCode];
self.view.backgroundColor = selectedColor;
}
}
}
%end
// Declare Twitter's vector loader.
@interface UIImage (TwitterVectors)
+ (UIImage *)tfn_vectorImageNamed:(NSString *)name
fitsSize:(CGSize)size
fillColor:(UIColor *)fillColor;
@end
static inline UIImage *BHTVectorIcon(NSString *name, CGFloat size) {
if (!name.length) return nil;
return [UIImage tfn_vectorImageNamed:name
fitsSize:CGSizeMake(size, size)
fillColor:UIColor.labelColor];
}
static inline NSString *BHTIconNameForKey(NSString *key) {
if ([key isEqualToString:@"button"]) return @"copy_stroke";
if ([key isEqualToString:@"bio"]) return @"news_stroke";
if ([key isEqualToString:@"username"]) return @"at";
if ([key isEqualToString:@"fullname"]) return @"account";
if ([key isEqualToString:@"url"]) return @"link";
if ([key isEqualToString:@"location"]) return @"location_stroke";
return @"copy_stroke";
}
#pragma mark - Theme detection and style helpers
typedef NS_ENUM(NSInteger, BHTTwitterThemeVariant) {
BHTTwitterThemeVariantLight = 0,
BHTTwitterThemeVariantDim = 1,
BHTTwitterThemeVariantBlack = 2, // Lights out / pure black
};
// Decide between Light / Dim / Lights out using BHDimPalette for dim.
static BHTTwitterThemeVariant BHTCurrentTwitterThemeVariant(T1ProfileHeaderView *headerView) {
UIUserInterfaceStyle style = UIUserInterfaceStyleLight;
if (headerView && @available(iOS 13.0, *)) {
style = headerView.traitCollection.userInterfaceStyle;
}
// System / Twitter light theme
if (style == UIUserInterfaceStyleLight) {
return BHTTwitterThemeVariantLight;
}
// Dark family: use BHDimPalette to distinguish Dim from Lights out.
if ([BHDimPalette isDimMode]) {
return BHTTwitterThemeVariantDim;
}
// Dark but not dim -> Lights out (black).
return BHTTwitterThemeVariantBlack;
}
// Style using the logged RGBA values for each theme.
static void BHTApplyCopyButtonStyle(UIButton *copyButton, T1ProfileHeaderView *headerView) {
if (!copyButton) return;
BHTTwitterThemeVariant variant = BHTCurrentTwitterThemeVariant(headerView);
copyButton.layer.cornerRadius = 16.0;
copyButton.layer.masksToBounds = YES;
copyButton.layer.borderWidth = 1.0;
copyButton.backgroundColor = nil;
switch (variant) {
case BHTTwitterThemeVariantLight: {
// Light mode logs:
// tint: 0.000 0.533 1.000
// border: 0.812 0.851 0.871
copyButton.tintColor = [UIColor colorWithRed:0.000f
green:0.533f
blue:1.000f
alpha:1.0f];
copyButton.layer.borderColor = [UIColor colorWithRed:0.812f
green:0.851f
blue:0.871f
alpha:1.0f].CGColor;
break;
}
case BHTTwitterThemeVariantDim: {
// Dim mode logs:
// tint: 0.000 0.569 1.000
// border: 0.259 0.325 0.392
copyButton.tintColor = [UIColor colorWithRed:0.000f
green:0.569f
blue:1.000f
alpha:1.0f];
copyButton.layer.borderColor = [UIColor colorWithRed:0.259f
green:0.325f
blue:0.392f
alpha:1.0f].CGColor;
break;
}
case BHTTwitterThemeVariantBlack: {
// Lights out logs:
// tint: 0.000 0.569 1.000
// border: 0.200 0.212 0.224
copyButton.tintColor = [UIColor colorWithRed:0.000f
green:0.569f
blue:1.000f
alpha:1.0f];
copyButton.layer.borderColor = [UIColor colorWithRed:0.200f
green:0.212f
blue:0.224f
alpha:1.0f].CGColor;
break;
}
}
}
#pragma mark - Hook
%hook T1ProfileHeaderViewController
- (void)viewDidAppear:(_Bool)arg1 {
%orig(arg1);
if (![BHTManager CopyProfileInfo]) {
return;
}
T1ProfileHeaderView *headerView = [self valueForKey:@"_headerView"];
if (!headerView || ![headerView respondsToSelector:@selector(actionButtonsView)]) {
return;
}
UIView *actionButtonsView = headerView.actionButtonsView;
UIView *innerContentView = [actionButtonsView valueForKey:@"_innerContentView"];
if (!innerContentView) innerContentView = actionButtonsView;
// Reuse if it already exists.
UIButton *copyButton = (UIButton *)[actionButtonsView viewWithTag:9001];
if (!copyButton) {
copyButton = [UIButton buttonWithType:UIButtonTypeCustom];
[copyButton setImage:BHTVectorIcon(BHTIconNameForKey(@"button"), 18.0)
forState:UIControlStateNormal];
copyButton.tag = 9001;
if (@available(iOS 14.0, *)) {
[copyButton setShowsMenuAsPrimaryAction:true];
UIAction *fullname = [UIAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_3"]
image:BHTVectorIcon(BHTIconNameForKey(@"fullname"), 16.0)
identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {
if (self.viewModel.fullName != nil) UIPasteboard.generalPasteboard.string = self.viewModel.fullName;
}];
UIAction *username = [UIAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_2"]
image:BHTVectorIcon(BHTIconNameForKey(@"username"), 16.0)
identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {
if (self.viewModel.username != nil) UIPasteboard.generalPasteboard.string = self.viewModel.username;
}];
UIAction *bio = [UIAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_1"]
image:BHTVectorIcon(BHTIconNameForKey(@"bio"), 16.0)
identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {
if (self.viewModel.bio != nil) UIPasteboard.generalPasteboard.string = self.viewModel.bio;
}];
UIAction *location = [UIAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_5"]
image:BHTVectorIcon(BHTIconNameForKey(@"location"), 16.0)
identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {
if (self.viewModel.location != nil) UIPasteboard.generalPasteboard.string = self.viewModel.location;
}];
UIAction *url = [UIAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_4"]
image:BHTVectorIcon(BHTIconNameForKey(@"url"), 16.0)
identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {
if (self.viewModel.url != nil) UIPasteboard.generalPasteboard.string = self.viewModel.url;
}];
[copyButton setMenu:[UIMenu menuWithTitle:@"" children:@[fullname, username, bio, location, url]]];
} else {
[copyButton addTarget:self
action:@selector(copyButtonHandler:)
forControlEvents:UIControlEventTouchUpInside];
}
copyButton.translatesAutoresizingMaskIntoConstraints = NO;
[actionButtonsView addSubview:copyButton];
[NSLayoutConstraint activateConstraints:@[
[copyButton.centerYAnchor constraintEqualToAnchor:actionButtonsView.centerYAnchor],
[copyButton.widthAnchor constraintEqualToConstant:32.0],
[copyButton.heightAnchor constraintEqualToConstant:32.0],
]];
if (isDeviceLanguageRTL()) {
[NSLayoutConstraint activateConstraints:@[
[copyButton.leadingAnchor constraintEqualToAnchor:innerContentView.trailingAnchor constant:7.0],
]];
} else {
[NSLayoutConstraint activateConstraints:@[
[copyButton.trailingAnchor constraintEqualToAnchor:innerContentView.leadingAnchor constant:-7.0],
]];
}
} else {
[copyButton setImage:BHTVectorIcon(BHTIconNameForKey(@"button"), 18.0)
forState:UIControlStateNormal];
}
// Style for current theme.
BHTApplyCopyButtonStyle(copyButton, headerView);
}
%new - (void)copyButtonHandler:(UIButton *)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"hi"
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
if (is_iPad()) {
alert.popoverPresentationController.sourceView = self.view;
alert.popoverPresentationController.sourceRect = sender.frame;
}
UIAlertAction *fullname = [UIAlertAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_3"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
if (self.viewModel.fullName != nil) UIPasteboard.generalPasteboard.string = self.viewModel.fullName;
}];
UIAlertAction *username = [UIAlertAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_2"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
if (self.viewModel.username != nil) UIPasteboard.generalPasteboard.string = self.viewModel.username;
}];
UIAlertAction *bio = [UIAlertAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_1"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
if (self.viewModel.bio != nil) UIPasteboard.generalPasteboard.string = self.viewModel.bio;
}];
UIAlertAction *location = [UIAlertAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_5"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
if (self.viewModel.location != nil) UIPasteboard.generalPasteboard.string = self.viewModel.location;
}];
UIAlertAction *url = [UIAlertAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_4"]
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * _Nonnull action) {
if (self.viewModel.url != nil) UIPasteboard.generalPasteboard.string = self.viewModel.url;
}];
if (@available(iOS 13.0, *)) {
[bio setValue:BHTVectorIcon(BHTIconNameForKey(@"bio"), 16.0) forKey:@"image"];
[username setValue:BHTVectorIcon(BHTIconNameForKey(@"username"), 16.0) forKey:@"image"];
[fullname setValue:BHTVectorIcon(BHTIconNameForKey(@"fullname"), 16.0) forKey:@"image"];
[url setValue:BHTVectorIcon(BHTIconNameForKey(@"url"), 16.0) forKey:@"image"];
[location setValue:BHTVectorIcon(BHTIconNameForKey(@"location"), 16.0) forKey:@"image"];
}
[alert addAction:fullname];
[alert addAction:username];
[alert addAction:bio];
[alert addAction:location];
[alert addAction:url];
[alert addAction:[UIAlertAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"CANCEL_BUTTON_TITLE"]
style:UIAlertActionStyleCancel
handler:nil]];
[self presentViewController:alert animated:true completion:nil];
}
- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection {
%orig(previousTraitCollection);
if (![BHTManager CopyProfileInfo]) {
return;
}
T1ProfileHeaderView *headerView = [self valueForKey:@"_headerView"];
if (!headerView || ![headerView respondsToSelector:@selector(actionButtonsView)]) {
return;
}
UIButton *copyButton = (UIButton *)[headerView.actionButtonsView viewWithTag:9001];
if (!copyButton) {
return;
}
[copyButton setImage:BHTVectorIcon(BHTIconNameForKey(@"button"), 18.0)
forState:UIControlStateNormal];
if (@available(iOS 14.0, *)) {
UIAction *fullname = [UIAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_3"]
image:BHTVectorIcon(BHTIconNameForKey(@"fullname"), 16.0)
identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {
if (self.viewModel.fullName != nil) UIPasteboard.generalPasteboard.string = self.viewModel.fullName;
}];
UIAction *username = [UIAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_2"]
image:BHTVectorIcon(BHTIconNameForKey(@"username"), 16.0)
identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {
if (self.viewModel.username != nil) UIPasteboard.generalPasteboard.string = self.viewModel.username;
}];
UIAction *bio = [UIAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_1"]
image:BHTVectorIcon(BHTIconNameForKey(@"bio"), 16.0)
identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {
if (self.viewModel.bio != nil) UIPasteboard.generalPasteboard.string = self.viewModel.bio;
}];
UIAction *location = [UIAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_5"]
image:BHTVectorIcon(BHTIconNameForKey(@"location"), 16.0)
identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {
if (self.viewModel.location != nil) UIPasteboard.generalPasteboard.string = self.viewModel.location;
}];
UIAction *url = [UIAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_MENU_OPTION_4"]
image:BHTVectorIcon(BHTIconNameForKey(@"url"), 16.0)
identifier:nil
handler:^(__kindof UIAction * _Nonnull action) {
if (self.viewModel.url != nil) UIPasteboard.generalPasteboard.string = self.viewModel.url;
}];
[copyButton setMenu:[UIMenu menuWithTitle:@"" children:@[fullname, username, bio, location, url]]];
}
// Reapply style so border/tint match the updated theme.
BHTApplyCopyButtonStyle(copyButton, headerView);
}
%end
%hook T1ProfileSummaryView
- (BOOL)shouldShowGetVerifiedButton {
return [BHTManager hidePremiumOffer] ? false : %orig;
}
%end
// MARK: Show unrounded follower/following counts
%hook T1ProfileFriendsFollowingViewModel
- (id)_t1_followCountTextWithLabel:(id)label singularLabel:(id)singularLabel count:(id)count highlighted:(_Bool)highlighted {
// First get the original result to understand the expected return type
id originalResult = %orig;
// Only proceed if we have a valid count that's an NSNumber