Skip to content

Commit e1ce1f4

Browse files
committed
feat: improve effectiveness of padlock feature
1 parent 598f209 commit e1ce1f4

5 files changed

Lines changed: 45 additions & 23 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#import <UIKit/UIKit.h>
22
#import <LocalAuthentication/LocalAuthentication.h>
33

4+
#import "../InstagramHeaders.h"
5+
#import "../Tweak.h"
6+
#import "../../modules/JGProgressHUD/JGProgressHUD.h"
7+
48
@interface SCISecurityViewController : UIViewController
59
@end

‎src/Controllers/SecurityViewController.m‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1-
#import "../../modules/JGProgressHUD/JGProgressHUD.h"
2-
#import "../InstagramHeaders.h"
31
#import "SecurityViewController.h"
42

53
@implementation SCISecurityViewController
64

7-
- (void)viewDidLoad {
8-
[super viewDidLoad];
9-
5+
- (id)init {
6+
self = [super init];
7+
if (!self) return nil;
8+
9+
[[NSNotificationCenter defaultCenter] addObserver:self
10+
selector:@selector(authenticate)
11+
name:UIApplicationWillEnterForegroundNotification
12+
object:[UIApplication sharedApplication]
13+
];
14+
15+
return self;
16+
}
17+
- (void)dealloc {
18+
[[NSNotificationCenter defaultCenter] removeObserver:self];
19+
}
20+
21+
- (void)viewDidLoad {
1022
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleDark];
1123
UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
1224
blurView.frame = self.view.bounds;
@@ -15,16 +27,12 @@ - (void)viewDidLoad {
1527
UIButton *authenticateButton = [[UIButton alloc] initWithFrame:CGRectMake(20, 20, 200, 60)];
1628
[authenticateButton setTitle:@"Click to unlock app" forState:UIControlStateNormal];
1729
authenticateButton.center = self.view.center;
18-
[authenticateButton addTarget:self action:@selector(authenticateButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
30+
[authenticateButton addTarget:self action:@selector(authenticate) forControlEvents:UIControlEventTouchUpInside];
1931
[self.view addSubview:authenticateButton];
2032

2133
[self authenticate];
2234
}
2335

24-
- (void)authenticateButtonTapped:(id)sender {
25-
[self authenticate];
26-
}
27-
2836
- (void)authenticate {
2937
LAContext *context = [[LAContext alloc] init];
3038
NSError *error = nil;
@@ -39,6 +47,8 @@ - (void)authenticate {
3947
if (success) {
4048
[self dismissViewControllerAnimated:YES completion:nil];
4149

50+
isAuthenticationBeingShown = NO;
51+
4252
NSLog(@"[SCInsta] Padlock authentication: Unlock success");
4353
}
4454
else {

‎src/InstagramHeaders.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
@end
265265

266266
@interface IGInstagramAppDelegate : NSObject <UIApplicationDelegate>
267+
- (void)authPrompt; // new
267268
@end
268269

269270
@interface IGDirectInboxSearchAIAgentsPillsContainerCell : UIView

‎src/Tweak.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ extern NSString *SCIVersionString;
55

66
// Variables that work across features
77
extern BOOL seenButtonEnabled; // Whether dm message seen button is enabled
8-
extern BOOL dmVisualMsgsViewedButtonEnabled; // Whether story dm unlimited views button is enabled
8+
extern BOOL dmVisualMsgsViewedButtonEnabled; // Whether story dm unlimited views button is enabled
9+
10+
// Biometric/passcode authentication
11+
extern BOOL isAuthenticationBeingShown;

‎src/Tweak.x‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,38 @@ BOOL dmVisualMsgsViewedButtonEnabled = false;
7575
NSLog(@"[SCInsta] Cleaning cache...");
7676
[SCIManager cleanCache];
7777

78+
[self authPrompt];
79+
7880
return true;
7981
}
8082

8183
// Biometric/passcode authentication
82-
static BOOL isAuthenticationShowed = FALSE;
84+
BOOL isAuthenticationBeingShown = NO;
85+
86+
- (void)applicationDidEnterBackground:(id)arg1 {
87+
%orig;
8388

84-
- (void)applicationDidBecomeActive:(id)arg1 {
89+
[self authPrompt];
90+
}
91+
- (void)applicationWillEnterForeground:(id)arg1 {
8592
%orig;
8693

94+
[self authPrompt];
95+
}
96+
97+
%new - (void)authPrompt {
8798
// Padlock (biometric auth)
88-
if ([SCIManager getPref:@"padlock"] && !isAuthenticationShowed) {
99+
if ([SCIManager getPref:@"padlock"] && !isAuthenticationBeingShown) {
89100
UIViewController *rootController = [[self window] rootViewController];
90101
SCISecurityViewController *securityViewController = [SCISecurityViewController new];
91102
securityViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
92-
[rootController presentViewController:securityViewController animated:YES completion:nil];
103+
[rootController presentViewController:securityViewController animated:NO completion:nil];
93104

94-
isAuthenticationShowed = TRUE;
105+
isAuthenticationBeingShown = YES;
95106

96107
NSLog(@"[SCInsta] Padlock authentication: App enabled");
97108
}
98109
}
99-
100-
- (void)applicationWillEnterForeground:(id)arg1 {
101-
%orig;
102-
103-
// Reset padlock status
104-
isAuthenticationShowed = FALSE;
105-
}
106110
%end
107111

108112

0 commit comments

Comments
 (0)