Skip to content
This repository was archived by the owner on Jan 4, 2024. It is now read-only.

Commit acf05f6

Browse files
committed
Fix a stupid crash
1 parent 67bfc2f commit acf05f6

File tree

3 files changed

+38
-15
lines changed

3 files changed

+38
-15
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Theos/packages/
22
.theos
33
.cache/
4-
compile_commands.json
4+
compile_commands.json
5+
.DS_Store

Theos/Tweak.x

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,46 @@
33

44
//Add Settings button
55
@interface MainFeedViewController : UIViewController
6+
@property (nonatomic, strong) UIBarButtonItem *settingsButton;
7+
- (void)addSettingsButton;
68
@end
79

810
%hook MainFeedViewController
11+
%property (nonatomic, strong) UIBarButtonItem *settingsButton;
12+
913
- (void)viewDidLoad{
1014
%orig;
11-
@try{
12-
JELog(@"Adding setting button");
13-
MainFeedViewController *usableSelf = self;
14-
UIBarButtonItem *statsButton = [[UIBarButtonItem alloc] initWithTitle:[[JDESettingsManager sharedInstance] localizedStringForKey:@"emproved"]
15-
style:UIBarButtonItemStyleDone target:self
16-
action:@selector(presentJDEViewController:)];
17-
18-
usableSelf.navigationItem.leftBarButtonItem = statsButton;
19-
}
20-
@catch(NSException *exception){
21-
JELog(@"Failed to add settings button: %@", exception);
15+
[self addSettingsButton];
16+
[self addObserver:self forKeyPath:@"navigationItem" options:NSKeyValueObservingOptionNew context:nil];
17+
}
18+
19+
- (void)dealloc {
20+
// Remove observer to avoid memory leaks
21+
[self removeObserver:self forKeyPath:@"navigationItem"];
22+
%orig;
23+
}
24+
25+
%new
26+
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
27+
// Check if the observed keyPath is "navigationItem"
28+
if ([keyPath isEqualToString:@"navigationItem"]) {
29+
// Re-add the button whenever the navigationItem changes
30+
[self addSettingsButton];
2231
}
2332
}
33+
%new
34+
- (void)addSettingsButton {
35+
// Create the button
36+
MainFeedViewController *usableSelf = self;
37+
usableSelf.settingsButton = [[UIBarButtonItem alloc] initWithTitle:[[JDESettingsManager sharedInstance] localizedStringForKey:@"emproved"]
38+
style:UIBarButtonItemStyleDone
39+
target:self
40+
action:@selector(presentJDEViewController:)];
41+
42+
// Add the button to the navigation item
43+
44+
usableSelf.navigationItem.leftBarButtonItem = usableSelf.settingsButton;
45+
}
2446

2547
%new
2648
-(void)presentJDEViewController:(id)sender{

Theos/layout/DEBIAN/control

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Package: dev.extbh.jodelemproved
22
Name: Jodel EMPROVED
3-
Version: 1.1.7-3
3+
Version: 1.1.8
44
Architecture: iphoneos-arm
55
Description: Customizing the Jodel app
66
Depiction: https://repo.depiction.extbh.dev/dev.extbh.jodelemproved/
77
Homepage: https://extbh.dev
8-
Maintainer: ExTBH <natheer@extbh.dev>
9-
Author: ExTBH <natheer@extbh.dev>
8+
Maintainer: ExTBH
9+
Author: ExTBH
1010
Section: Tweaks
1111
Depends: mobilesubstrate (>= 0.9.5000), firmware (>= 14.0)

0 commit comments

Comments
 (0)