Skip to content

Commit

Permalink
update 4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
BandarHL committed Feb 10, 2024
1 parent 6c73a7f commit d8ca00c
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 68 deletions.
3 changes: 1 addition & 2 deletions BHTManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
+ (BOOL)FLEX;
+ (BOOL)autoHighestLoad;
+ (BOOL)disableSensitiveTweetWarnings;
+ (BOOL)TwitterCircle;
+ (BOOL)showScrollIndicator;
+ (BOOL)CopyProfileInfo;
+ (BOOL)tweetToImage;
Expand All @@ -52,9 +51,9 @@
+ (BOOL)stripTrackingParams;
+ (BOOL)alwaysFollowingPage;
+ (BOOL)stopHidingTabBar;
+ (BOOL)advancedSearch;
+ (BOOL)changeBackground;
+ (bool)backgroundImage;
+ (BOOL)hideBookmarkButton;
+ (BOOL)customVoice;
@end

9 changes: 3 additions & 6 deletions BHTManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@ + (BOOL)autoHighestLoad {
+ (BOOL)disableSensitiveTweetWarnings {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"disableSensitiveTweetWarnings"];
}
+ (BOOL)TwitterCircle {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"TrustedFriends"];
}
+ (BOOL)showScrollIndicator {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"showScollIndicator"];
}
Expand Down Expand Up @@ -241,9 +238,6 @@ + (BOOL)alwaysFollowingPage {
+ (BOOL)stopHidingTabBar {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"no_tab_bar_hiding"];
}
+ (BOOL)advancedSearch {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"advanced_search"];
}
+ (BOOL)changeBackground {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"change_msg_background"];
}
Expand All @@ -253,6 +247,9 @@ + (bool)backgroundImage {
+ (BOOL)hideBookmarkButton {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"hide_bookmark_button"];
}
+ (BOOL)customVoice {
return [[NSUserDefaults standardUserDefaults] boolForKey:@"custom_voice_upload"];
}
+ (UIViewController *)BHTSettingsWithAccount:(TFNTwitterAccount *)twAccount {
SettingsViewController *pref = [[SettingsViewController alloc] initWithTwitterAccount:twAccount];
[pref.navigationItem setTitleView:[objc_getClass("TFNTitleView") titleViewWithTitle:@"BHTwitter" subtitle:twAccount.displayUsername]];
Expand Down
59 changes: 52 additions & 7 deletions SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ - (NSArray *)specifiers {

PSSpecifier *hideAds = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"HIDE_ADS_OPTION_TITLE"] detailTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"HIDE_ADS_OPTION_DETAIL_TITLE"] key:@"hide_promoted" defaultValue:true changeAction:nil];

PSSpecifier *customVoice = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"UPLOAD_CUSTOM_VOICE_OPTION_TITLE"] detailTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"UPLOAD_CUSTOM_VOICE_OPTION_DETAIL_TITLE"] key:@"custom_voice_upload" defaultValue:true changeAction:nil];

PSSpecifier *hideTopics = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"HIDE_TOPICS_OPTION_TITLE"] detailTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"HIDE_TOPICS_OPTION_DETAIL_TITLE"] key:@"hide_topics" defaultValue:false changeAction:nil];

PSSpecifier *hideWhoToFollow = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"HIDE_WHO_FOLLOW_OPTION"] detailTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"HIDE_WHO_FOLLOW_OPTION_DETAIL_TITLE"] key:@"hide_who_to_follow" defaultValue:false changeAction:nil];
Expand All @@ -168,9 +170,7 @@ - (NSArray *)specifiers {
PSSpecifier *autoHighestLoad = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"AUTO_HIGHEST_LOAD_OPTION_TITLE"] detailTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"AUTO_HIGHEST_LOAD_OPTION_DETAIL_TITLE"] key:@"autoHighestLoad" defaultValue:true changeAction:nil];

PSSpecifier *disableSensitiveTweetWarnings = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"DISABLE_SENSITIVE_TWEET_WARNINGS_OPTION_TITLE"] detailTitle:nil key:@"disableSensitiveTweetWarnings" defaultValue:true changeAction:nil];

PSSpecifier *trustedFriends = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"TRUSTED_FRIENSS_OPTION_TITLE"] detailTitle:nil key:@"TrustedFriends" defaultValue:true changeAction:nil];


PSSpecifier *copyProfileInfo = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_OPTION_TITLE"] detailTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"COPY_PROFILE_INFO_OPTION_DETAIL_TITLE"] key:@"CopyProfileInfo" defaultValue:false changeAction:nil];

PSSpecifier *tweetToImage = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"TWEET_TO_IMAGE_OPTION_TITLE"] detailTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"TWEET_TO_IMAGE_OPTION_DETAIL_TITLE"] key:@"TweetToImage" defaultValue:false changeAction:nil];
Expand All @@ -182,8 +182,8 @@ - (NSArray *)specifiers {
PSSpecifier *alwaysOpenSafari = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"ALWAYS_OPEN_SAFARI_OPTION_TITLE"] detailTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"ALWAYS_OPEN_SAFARI_OPTION_DETAIL_TITLE"] key:@"openInBrowser" defaultValue:false changeAction:nil];

PSSpecifier *stripTrackingParams = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"STRIP_URL_TRACKING_PARAMETERS_TITLE"] detailTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"STRIP_URL_TRACKING_PARAMETERS_DETAIL_TITLE"] key:@"strip_tracking_params" defaultValue:false changeAction:nil];
PSSpecifier *advancedSearch = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"ADVANCED_SEARCH_TITLE"] detailTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"ADVANCED_SEARCH_DETAIL_TITLE"] key:@"advanced_search" defaultValue:false changeAction:nil];

PSSpecifier *urlHost = [self newButtonCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"SELECT_URL_HOST_AFTER_COPY_OPTION_TITLE"] detailTitle:[[NSUserDefaults standardUserDefaults] objectForKey:@"tweet_url_host"] dynamicRule:@"strip_tracking_params, ==, 0" action:@selector(showURLHostSelectionViewController:)];

// Twitter bule section
PSSpecifier *undoTweet = [self newSwitchCellWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"UNDO_TWEET_OPTION_TITLE"] detailTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"UNDO_TWEET_OPTION_DETAIL_TITLE"] key:@"undo_tweet" defaultValue:false changeAction:nil];
Expand Down Expand Up @@ -232,6 +232,7 @@ - (NSArray *)specifiers {
mainSection, // 0
download,
hideAds,
customVoice,
hideTopics,
hideWhoToFollow,
hideTopicsToFollow,
Expand All @@ -251,8 +252,7 @@ - (NSArray *)specifiers {
disableRTL,
alwaysOpenSafari,
stripTrackingParams,
trustedFriends,
advancedSearch,
urlHost,

twitterBlueSection, // 1
undoTweet,
Expand Down Expand Up @@ -493,6 +493,51 @@ - (void)showBHAppIconViewController:(PSSpecifier *)specifier {
}
[self.navigationController pushViewController:appIconVC animated:true];
}
- (void)showURLHostSelectionViewController:(PSSpecifier *)specifier {
UITableViewCell *specifierCell = [specifier propertyForKey:PSTableCellKey];
PSSpecifier *selectionSpecifier = [self specifierForID:@"Select URL host"];

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"BHTwitter" message:@"plaese select what host you prefre" preferredStyle:UIAlertControllerStyleActionSheet];

if (alert.popoverPresentationController != nil) {
CGFloat midX = CGRectGetMidX(specifierCell.frame);
CGFloat midY = CGRectGetMidY(specifierCell.frame);

alert.popoverPresentationController.sourceRect = CGRectMake(midX, midY, 0, 0);
alert.popoverPresentationController.sourceView = specifierCell;
}

UIAlertAction *xHostAction = [UIAlertAction actionWithTitle:@"x.com" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[NSUserDefaults standardUserDefaults] setObject:@"x.com" forKey:@"tweet_url_host"];
[selectionSpecifier setProperty:@"x.com" forKey:@"subtitle"];
[self reloadSpecifiers];
}];
UIAlertAction *twitterHostAction = [UIAlertAction actionWithTitle:@"twitter.com" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[NSUserDefaults standardUserDefaults] setObject:@"twitter.com" forKey:@"tweet_url_host"];
[selectionSpecifier setProperty:@"twitter.com" forKey:@"subtitle"];
[self reloadSpecifiers];
}];
UIAlertAction *fxHostAction = [UIAlertAction actionWithTitle:@"fxtwitter.com" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[NSUserDefaults standardUserDefaults] setObject:@"fxtwitter.com" forKey:@"tweet_url_host"];
[selectionSpecifier setProperty:@"fxtwitter.com" forKey:@"subtitle"];
[self reloadSpecifiers];
}];
UIAlertAction *vxHostAction = [UIAlertAction actionWithTitle:@"vxtwitter.com" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[NSUserDefaults standardUserDefaults] setObject:@"vxtwitter.com" forKey:@"tweet_url_host"];
[selectionSpecifier setProperty:@"vxtwitter.com" forKey:@"subtitle"];
[self reloadSpecifiers];
}];

UIAlertAction *cancel = [UIAlertAction actionWithTitle:[[BHTBundle sharedBundle] localizedStringForKey:@"CANCEL_BUTTON_TITLE"] style:UIAlertActionStyleCancel handler:nil];

[alert addAction:xHostAction];
[alert addAction:twitterHostAction];
[alert addAction:fxHostAction];
[alert addAction:vxHostAction];
[alert addAction:cancel];

[self presentViewController:alert animated:true completion:nil];
}
- (void)showCustomBackgroundViewViewController:(PSSpecifier *)specifier {
UITableViewCell *specifierCell = [specifier propertyForKey:PSTableCellKey];

Expand Down
33 changes: 33 additions & 0 deletions TWHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#import <objc/runtime.h>
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <AVKit/AVKit.h>
#import <Photos/Photos.h>
#import <SafariServices/SafariServices.h>
#import "BHDownload/BHDownload.h"
Expand All @@ -34,6 +36,37 @@ static NSString *_lastCopiedURL;
@property(retain, nonatomic) UIWindow *window;
@end


@interface TTMAssetVideoFile: NSObject
@property (nonatomic, copy, readonly) NSString *filePath;
@property (nonatomic, assign, readonly) CGFloat duration;

@end

@interface TTMAssetVoiceRecording: TTMAssetVideoFile
@property (nonatomic, strong, readwrite) NSNumber *totalDurationMillis;
@end

@interface T1MediaAttachmentsViewCell: UICollectionViewCell
@property (nonatomic, strong, readwrite) id attachment;
@property (nonatomic, strong) UIButton *uploadButton;
@end

@interface T1MediaAttachmentsViewCell () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@end

@interface TCRVoiceRecordingViewController: UIViewController
@property (nonatomic, assign, readwrite) CGFloat clipDuration;
- (void)_tcr_pauseRecording;
- (void)_tcr_endRecording;
@end

@interface TCRVoiceRecordingView: UIView
@property (nonatomic, strong) NSTimer *recordingTimer;
@property (nonatomic, assign) CGFloat desiredRecordingDuration;
@property (nonatomic, weak, readwrite) id delegate;
@end

@interface NSParagraphStyle ()
+ (NSWritingDirection)_defaultWritingDirection;
@end
Expand Down
96 changes: 80 additions & 16 deletions Tweak.x
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ static void batchSwizzlingOnClass(Class cls, NSArray<NSString*>*origSelectors, I
%hook T1AppDelegate
- (_Bool)application:(UIApplication *)application didFinishLaunchingWithOptions:(id)arg2 {
%orig;
if (![[NSUserDefaults standardUserDefaults] objectForKey:@"FirstRun"]) {
[[NSUserDefaults standardUserDefaults] setValue:@"1strun" forKey:@"FirstRun"];
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"];
}
[BHTManager cleanCache];
if ([BHTManager FLEX]) {
Expand Down Expand Up @@ -490,6 +491,77 @@ static void batchSwizzlingOnClass(Class cls, NSArray<NSString*>*origSelectors, I
}
%end

// upload custom voice
%hook T1MediaAttachmentsViewCell
%property (nonatomic, strong) UIButton *uploadButton;
- (void)updateCellElements {
%orig;

if ([BHTManager customVoice]) {
TFNButton *removeButton = [self valueForKey:@"_removeButton"];

if ([self.attachment isKindOfClass:%c(TTMAssetVoiceRecording)]) {
if (self.uploadButton == nil) {
self.uploadButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImageSymbolConfiguration *smallConfig = [UIImageSymbolConfiguration configurationWithScale:UIImageSymbolScaleSmall];
UIImage *arrowUpImage = [UIImage systemImageNamed:@"arrow.up" withConfiguration:smallConfig];
[self.uploadButton setImage:arrowUpImage forState:UIControlStateNormal];
[self.uploadButton addTarget:self action:@selector(handleUploadButton:) forControlEvents:UIControlEventTouchUpInside];
[self.uploadButton setTintColor:UIColor.labelColor];
[self.uploadButton setBackgroundColor:[UIColor blackColor]];
[self.uploadButton.layer setCornerRadius:29/2];
[self.uploadButton setTranslatesAutoresizingMaskIntoConstraints:false];

if (self.uploadButton.superview == nil) {
[self addSubview:self.uploadButton];
[NSLayoutConstraint activateConstraints:@[
[self.uploadButton.trailingAnchor constraintEqualToAnchor:removeButton.leadingAnchor constant:-10],
[self.uploadButton.topAnchor constraintEqualToAnchor:removeButton.topAnchor],
[self.uploadButton.widthAnchor constraintEqualToConstant:29],
[self.uploadButton.heightAnchor constraintEqualToConstant:29],
]];
}
}
}
}
}
%new - (void)handleUploadButton:(UIButton *)sender {
UIImagePickerController *videoPicker = [[UIImagePickerController alloc] init];
videoPicker.mediaTypes = @[(NSString*)kUTTypeMovie];
videoPicker.delegate = self;

[topMostController() presentViewController:videoPicker animated:YES completion:nil];
}
%new - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
NSURL *videoURL = info[UIImagePickerControllerMediaURL];
TTMAssetVoiceRecording *attachment = self.attachment;
NSURL *recorder_url = [NSURL fileURLWithPath:attachment.filePath];

if (recorder_url != nil) {
NSFileManager *fileManager = [NSFileManager defaultManager];

NSError *error = nil;
if ([fileManager fileExistsAtPath:[recorder_url path]]) {
[fileManager removeItemAtURL:recorder_url error:&error];
if (error) {
NSLog(@"[BHTwitter] Error removing existing file: %@", error);
}
}

[fileManager copyItemAtURL:videoURL toURL:recorder_url error:&error];
if (error) {
NSLog(@"[BHTwitter] Error copying file: %@", error);
}
}

[picker dismissViewControllerAnimated:true completion:nil];
}
%new - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:true completion:nil];
}
%end


// MARK: Color theme
%hook TFNPagingViewController
- (void)viewDidAppear:(_Bool)animated {
Expand Down Expand Up @@ -737,7 +809,7 @@ static void batchSwizzlingOnClass(Class cls, NSArray<NSString*>*origSelectors, I
}
%end

// MARK: Voice, TwitterCircle, SensitiveTweetWarnings, autoHighestLoad, VideoZoom, VODCaptions, disableSpacesBar feature
// MARK: Voice, SensitiveTweetWarnings, autoHighestLoad, VideoZoom, VODCaptions, disableSpacesBar feature
%hook TPSTwitterFeatureSwitches
// Twitter save all the features and keys in side JSON file in bundle of application fs_embedded_defaults_production.json, and use it in TFNTwitterAccount class but with DM voice maybe developers forget to add boolean variable in the class, so i had to change it from the file.
// also, you can find every key for every feature i used in this tweak, i can remove all the codes below and find every key for it but I'm lazy to do that, :)
Expand All @@ -750,10 +822,6 @@ static void batchSwizzlingOnClass(Class cls, NSArray<NSString*>*origSelectors, I
return true;
}

if ([BHTManager advancedSearch] && [key isEqualToString:@"search_features_advanced_search_enabled"]) {
return true;
}

return %orig;
}
%end
Expand Down Expand Up @@ -825,22 +893,13 @@ static void batchSwizzlingOnClass(Class cls, NSArray<NSString*>*origSelectors, I
}
%end

%hook T1TrustedFriendsFeatureSwitches
+ (_Bool)isTrustedFriendsTweetCreationEnabled:(id)arg1 {
return [BHTManager TwitterCircle] ? true : %orig;
}
%end

%hook TFNTwitterAccount
- (_Bool)isEditProfileUsernameEnabled {
return true;
}
- (_Bool)isEditTweetConsumptionEnabled {
return true;
}
- (_Bool)isTrustedFriendsAPIEnabled {
return [BHTManager TwitterCircle] ? true : %orig;
}
- (_Bool)isSensitiveTweetWarningsComposeEnabled {
return [BHTManager disableSensitiveTweetWarnings] ? false : %orig;
}
Expand Down Expand Up @@ -1230,6 +1289,11 @@ static void batchSwizzlingOnClass(Class cls, NSArray<NSString*>*origSelectors, I
}
}
cleanedURL.queryItems = safeParams;

if ([[NSUserDefaults standardUserDefaults] objectForKey:@"tweet_url_host"]) {
NSString *selectedHost = [[NSUserDefaults standardUserDefaults] objectForKey:@"tweet_url_host"];
cleanedURL.host = selectedHost;
}
UIPasteboard.generalPasteboard.URL = cleanedURL.URL;
}
}
Expand Down
14 changes: 14 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ do
rm -rf .theos
make SIDELOADED=1

if [ $? -eq 0 ]; then
echo -e '\033[1m\033[32mMake command succeeded.\033[0m'
else
echo -e '\033[1m\033[31mMake command failed.\033[0m'
exit 1
fi

if [ -e ./packages/com.atebits.Tweetie2.ipa ]; then

echo -e '\033[1m\033[32mDownloading libcephei SDK.\033[0m'
Expand Down Expand Up @@ -51,6 +58,13 @@ do
rm -rf .theos
make

if [ $? -eq 0 ]; then
echo -e '\033[1m\033[32mMake command succeeded.\033[0m'
else
echo -e '\033[1m\033[31mMake command failed.\033[0m'
exit 1
fi

if [ -e ./packages/com.atebits.Tweetie2.ipa ]; then

echo -e '\033[1m\033[32mDownloading libcephei SDK.\033[0m'
Expand Down
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: com.bandarhl.bhtwitter
Name: BHTwitter
Version: 4.2
Version: 4.3
Architecture: iphoneos-arm
Description: Awesome tweak for Twitter
Maintainer: Bandar Alruwaili
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,8 @@
"APP_ICON_HEADER_TITLE" = "إختر الأيقونة التي تُريدها وبإمكانك تغييرها في أي وقت";

"FFMPEG_DOWNLOAD_OPTION_TITLE" = "التحميل بإستخدام FFmpeg";

"SELECT_URL_HOST_AFTER_COPY_OPTION_TITLE" = "أختر رابط الموقع للتغريدة بعد النسخ";

"UPLOAD_CUSTOM_VOICE_OPTION_TITLE" = "رفع صوت مخصص";
"UPLOAD_CUSTOM_VOICE_OPTION_DETAIL_TITLE" = "رفع فيديو مخصص بعد تسجيل المقطع الصوتي بالتغريدة";
Loading

0 comments on commit d8ca00c

Please sign in to comment.