This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathMobileCoreServices.x
61 lines (45 loc) · 1.7 KB
/
MobileCoreServices.x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#import "HBLOHandlerController.h"
#import "HBLOOpenOperation.h"
#import <MobileCoreServices/LSApplicationWorkspace.h>
#import <version.h>
#include <dlfcn.h>
static BOOL isOverriding = NO;
// TODO: SBSOpenSensitiveURLAndUnlock() late loads MobileCoreServices. not sure if it's worth
// supporting such situations… use case: sbopenurl
@interface LSApplicationWorkspace ()
- (NSURL *)_opener_URLOverrideForURL:(NSURL *)url;
@end
%hook LSApplicationWorkspace
%new - (NSURL *)_opener_URLOverrideForURL:(NSURL *)url {
NSArray <HBLOOpenOperation *> *result = [[HBLOHandlerController sharedInstance] getReplacementsForOpenOperation:[HBLOOpenOperation openOperationWithURL:url sender:[NSBundle mainBundle].bundleIdentifier]];
// none? fair enough, just return the original url
if (!result) {
return nil;
}
// well, looks like we're getting newURL[0]! how, uh, boring
return result[0].URL;
}
- (NSURL *)URLOverrideForURL:(NSURL *)url {
// if we're currently trying to find replacements, we don't want to replace the replacements
if (isOverriding) {
return %orig;
}
// consult with HBLOHandlerController to see if there's any possible URL replacements
isOverriding = YES;
NSURL *newURL = [self _opener_URLOverrideForURL:url];
isOverriding = NO;
// if we got a url, return that. if not, well, we tried… call the original function
return newURL ?: %orig;
}
- (BOOL)openURL:(NSURL *)url withOptions:(NSDictionary *)options {
// need to make sure all openURL: requests go through URLOverrideForURL:
return %orig([self _opener_URLOverrideForURL:url] ?: url, options);
}
%end
#pragma mark - Constructor
%ctor {
// only use these hooks if we aren’t using app links
if (!IS_IOS_OR_NEWER(iOS_9_0)) {
%init;
}
}