Skip to content

Commit

Permalink
feat: open settings by holding icon
Browse files Browse the repository at this point in the history
  • Loading branch information
asdfzxcvbn committed Mar 25, 2024
1 parent fbb9adc commit a7eb880
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 37 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
TARGET := iphone:clang:14.5
INSTALL_TARGET_PROCESSES = SpringBoard
INSTALL_TARGET_PROCESSES = Instagram
ARCHS = arm64

include $(THEOS)/makefiles/common.mk

Expand Down
93 changes: 57 additions & 36 deletions src/Features/General/BHSettingsMenuEntry.x
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,74 @@
#import "../../Controllers/SettingsViewController.h"

// Workaround to show BHInsta settings by clicking on Instagram logo
%hook IGMainAppHeaderView
- (void)_logoButtonTapped {
NSLog(@"[BHInsta] Displaying BHInsta settings modal");
// %hook IGMainAppHeaderView
// - (void)_logoButtonTapped {
// NSLog(@"[BHInsta] Displaying BHInsta settings modal");

UIViewController *rootController = [[UIApplication sharedApplication] delegate].window.rootViewController;
SettingsViewController *settingsViewController = [SettingsViewController new];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:settingsViewController];
// UIViewController *rootController = [[UIApplication sharedApplication] delegate].window.rootViewController;
// SettingsViewController *settingsViewController = [SettingsViewController new];
// UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:settingsViewController];

[rootController presentViewController:navigationController animated:YES completion:nil];

return;
}
%end

// Legacy (as of March 13th 2023)
%hook IGProfileMenuSheetViewController
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 9;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0 && indexPath.row == 8) {
IGProfileSheetTableViewCell *bhinstacell = [[%c(IGProfileSheetTableViewCell) alloc] initWithReuseIdentifier:@"bhinsta_settings"];
// [rootController presentViewController:navigationController animated:YES completion:nil];

UIImageSymbolConfiguration *configuration = [UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightBold];
UIImage *gear = [UIImage systemImageNamed:@"gearshape.fill" withConfiguration:configuration];
// return;
// }
// %end

[bhinstacell.imageView setImage:gear];
[bhinstacell.imageView setTintColor:[UIColor labelColor]];
[bhinstacell.textLabel setText:@" BHInsta Settings"];
// show settings by holding on the settings icon for ~1 second
%hook IGBadgedNavigationButton
- (instancetype)initWithIcon:(UIImage *)icon target:(id)target action:(SEL)action buttonType:(NSUInteger)type {
self = %orig;

return bhinstacell;
if ([[icon ig_imageName] isEqualToString:@"ig_icon_menu_pano_outline_24"]) {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress)];
[self addGestureRecognizer:longPress];
}

return %orig;
return self;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0 && indexPath.row == 8) {
UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:[[SettingsViewController alloc] init]];
[self _superPresentViewController:navVC animated:true completion:nil];
[tableView deselectRowAtIndexPath:indexPath animated:true];
} else {
return %orig;
}

%new - (void)handleLongPress {
UIViewController *rootController = [[UIApplication sharedApplication] delegate].window.rootViewController;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[SettingsViewController new]];

[rootController presentViewController:navigationController animated:YES completion:nil];
}
%end

// Legacy (as of March 13th 2023)
// %hook IGProfileMenuSheetViewController
// - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// return 9;
// }

// - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// if (indexPath.section == 0 && indexPath.row == 8) {
// IGProfileSheetTableViewCell *bhinstacell = [[%c(IGProfileSheetTableViewCell) alloc] initWithReuseIdentifier:@"bhinsta_settings"];

// UIImageSymbolConfiguration *configuration = [UIImageSymbolConfiguration configurationWithWeight:UIImageSymbolWeightBold];
// UIImage *gear = [UIImage systemImageNamed:@"gearshape.fill" withConfiguration:configuration];

// [bhinstacell.imageView setImage:gear];
// [bhinstacell.imageView setTintColor:[UIColor labelColor]];
// [bhinstacell.textLabel setText:@" BHInsta Settings"];

// return bhinstacell;
// }

// return %orig;
// }
// - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// if (indexPath.section == 0 && indexPath.row == 8) {
// UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:[[SettingsViewController alloc] init]];
// [self _superPresentViewController:navVC animated:true completion:nil];
// [tableView deselectRowAtIndexPath:indexPath animated:true];
// } else {
// return %orig;
// }
// }
// %end

// TODO: Add BHInsta settings button to profile header navbar icons
/* %hook IGStackLayout
// Display Settings Modal
Expand Down
8 changes: 8 additions & 0 deletions src/InstagramHeaders.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
- (void)_superPresentViewController:(UIViewController *)viewController animated:(BOOL)animated completion:(id)completion; // new
@end

@interface IGBadgedNavigationButton: UIView
- (void)handleLongPress; // new
@end

@interface UIImage ()
- (NSString *)ig_imageName;
@end

@interface IGProfileMenuSheetViewController: IGViewController
@end

Expand Down

0 comments on commit a7eb880

Please sign in to comment.