-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path12.xm
156 lines (117 loc) · 3.25 KB
/
12.xm
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
@class BrowserController, TabController, TabDocument, Application;
@class TabOverview, TiltedTabView;
@class UIView;
@protocol TabCollectionView;
@interface BrowserController
// Brings up the keyboard, use of arg1 us unknown
- (void)navigationBarURLWasTapped:(id)arg1;
//Determins of the tab view is currently showing
- (BOOL)isShowingTabView;
// Returns the current TabController
- (TabController *)tabController;
// Called on iPad?
- (void)addTabFromButtonBar;
@end
@interface TabDocument
// Returns if the document is blank or not
- (BOOL)isBlankDocument;
@end
@interface TabController: NSObject
// Called when the + button in the TiltedTabView on iPhone is pressed
- (void)_addNewActiveTiltedTabViewTab;
// Returns the currently displayed TabDocument
- (TabDocument *)activeTabDocument;
// nil when tab collection not presented
@property (retain) UIView<TabCollectionView> *tabCollectionView;
// iPhone portrait
@property (retain) TiltedTabView *tiltedTabView;
// iPhone landscape or iPad
@property (retain) TabOverview *tabOverview;
@end
@interface Application
- (BrowserController *)_focusedBrowserController;
@end
// iPhone tab view in portrait
@interface TiltedTabView: UIView
// 2: showing
// 1: unknown
// 0: not showing
@property NSUInteger presentationState;
@end
// iPhone tab view in landscape, maybe iPad too?
@interface TabOverview
@end
%group 12
bool tabViewShowing()
{
BrowserController *bc = [(Application *)[UIApplication sharedApplication] _focusedBrowserController];
TabController *tc = [bc tabController];
if (tc == nil)
{
return NO;
}
return [tc tabCollectionView] != nil;
}
void typeTab()
{
BrowserController *bc = [(Application *)[UIApplication sharedApplication] _focusedBrowserController];
TabController *tc = [bc tabController];
TabDocument *activeTabDocument = [tc activeTabDocument];
NSLog(@"TypeTab called");
if (tc != nil && [activeTabDocument isBlankDocument])
{
NSLog(@"Tapping bar!");
[bc navigationBarURLWasTapped:nil];
}
}
%hook Application
// Show keyboard on launch if the current tab is blank
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
BOOL orig = %orig;
if (!tabViewShowing())
{
typeTab();
}
return orig;
}
// Show keyboard on resume if the current tab is blank
- (void)applicationDidBecomeActive:(UIApplication *)application {
%orig;
if (!tabViewShowing())
{
typeTab();
}
}
// 3D Touch shortcut support
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler {
%orig;
if ([shortcutItem.type isEqualToString:@"com.apple.mobilesafari.shortcut.openNewTab"] || [shortcutItem.type isEqualToString:@"com.apple.mobilesafari.shortcut.openNewPrivateTab"]) {
typeTab();
}
}
%end
// Called on iPad
%hook BrowserController
- (void)addTabFromButtonBar {
%orig;
typeTab();
}
%end
// Called on iPhone
%hook TabController
- (void)_newTabFromTabViewButton {
%orig;
typeTab();
}
- (void)newTab
{
%orig;
typeTab();
}
%end
%end
%ctor {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 12.0 && [[[UIDevice currentDevice] systemVersion] floatValue] < 13.0) {
%init(12);
}
}