diff --git a/.gitignore b/.gitignore index abd3ced..8d0f987 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ Theos/packages/ .theos .cache/ -compile_commands.json \ No newline at end of file +compile_commands.json +.DS_Store diff --git a/Theos/Tweak.x b/Theos/Tweak.x index 3aed7dc..d73a0a6 100644 --- a/Theos/Tweak.x +++ b/Theos/Tweak.x @@ -3,24 +3,46 @@ //Add Settings button @interface MainFeedViewController : UIViewController +@property (nonatomic, strong) UIBarButtonItem *settingsButton; +- (void)addSettingsButton; @end %hook MainFeedViewController +%property (nonatomic, strong) UIBarButtonItem *settingsButton; + - (void)viewDidLoad{ %orig; - @try{ - JELog(@"Adding setting button"); - MainFeedViewController *usableSelf = self; - UIBarButtonItem *statsButton = [[UIBarButtonItem alloc] initWithTitle:[[JDESettingsManager sharedInstance] localizedStringForKey:@"emproved"] - style:UIBarButtonItemStyleDone target:self - action:@selector(presentJDEViewController:)]; - - usableSelf.navigationItem.leftBarButtonItem = statsButton; - } - @catch(NSException *exception){ - JELog(@"Failed to add settings button: %@", exception); + [self addSettingsButton]; + [self addObserver:self forKeyPath:@"navigationItem" options:NSKeyValueObservingOptionNew context:nil]; +} + +- (void)dealloc { + // Remove observer to avoid memory leaks + [self removeObserver:self forKeyPath:@"navigationItem"]; + %orig; +} + +%new +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + // Check if the observed keyPath is "navigationItem" + if ([keyPath isEqualToString:@"navigationItem"]) { + // Re-add the button whenever the navigationItem changes + [self addSettingsButton]; } } +%new +- (void)addSettingsButton { + // Create the button + MainFeedViewController *usableSelf = self; + usableSelf.settingsButton = [[UIBarButtonItem alloc] initWithTitle:[[JDESettingsManager sharedInstance] localizedStringForKey:@"emproved"] + style:UIBarButtonItemStyleDone + target:self + action:@selector(presentJDEViewController:)]; + + // Add the button to the navigation item + + usableSelf.navigationItem.leftBarButtonItem = usableSelf.settingsButton; +} %new -(void)presentJDEViewController:(id)sender{ diff --git a/Theos/layout/DEBIAN/control b/Theos/layout/DEBIAN/control index 098cb65..323da9f 100644 --- a/Theos/layout/DEBIAN/control +++ b/Theos/layout/DEBIAN/control @@ -1,11 +1,11 @@ Package: dev.extbh.jodelemproved Name: Jodel EMPROVED -Version: 1.1.7-3 +Version: 1.1.8 Architecture: iphoneos-arm Description: Customizing the Jodel app Depiction: https://repo.depiction.extbh.dev/dev.extbh.jodelemproved/ Homepage: https://extbh.dev -Maintainer: ExTBH -Author: ExTBH +Maintainer: ExTBH +Author: ExTBH Section: Tweaks Depends: mobilesubstrate (>= 0.9.5000), firmware (>= 14.0)