This repository has been archived by the owner on May 5, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
UIKit.xm
263 lines (228 loc) · 8.91 KB
/
UIKit.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#import <UIKit/UIKit.h>
#import <substrate.h>
#import <SpringBoard/SBApplication.h>
#import "headers.h"
#import "RAWidgetSectionManager.h"
#import "RASettings.h"
#import "RAMessagingClient.h"
#import "RAFakePhoneMode.h"
UIInterfaceOrientation prevousOrientation;
BOOL setPreviousOrientation = NO;
NSInteger wasStatusBarHidden = -1;
NSMutableDictionary *oldFrames = [NSMutableDictionary new];
static Class $memorized$UITextEffectsWindow$class;
%hook UIWindow
-(void) setFrame:(CGRect)frame
{
if ([self.class isEqual:$memorized$UITextEffectsWindow$class] == NO && [RAMessagingClient.sharedInstance shouldResize])
{
if ([oldFrames objectForKey:@(self.hash)] == nil)
[oldFrames setObject:[NSValue valueWithCGRect:frame] forKey:@(self.hash)];
frame.origin.x = RAMessagingClient.sharedInstance.currentData.wantedClientOriginX == -1 ? 0 : RAMessagingClient.sharedInstance.currentData.wantedClientOriginX;
frame.origin.y = RAMessagingClient.sharedInstance.currentData.wantedClientOriginY == -1 ? 0 : RAMessagingClient.sharedInstance.currentData.wantedClientOriginY;
CGFloat overrideWidth = [RAMessagingClient.sharedInstance resizeSize].width;
CGFloat overrideHeight = [RAMessagingClient.sharedInstance resizeSize].height;
if (overrideWidth != -1 && overrideWidth != 0)
frame.size.width = overrideWidth;
if (overrideHeight != -1 && overrideHeight != 0)
frame.size.height = overrideHeight;
if (self.subviews.count > 0)
{
((UIView*)self.subviews[0]).frame = frame;
}
}
%orig(frame);
}
- (void)_rotateWindowToOrientation:(UIInterfaceOrientation)arg1 updateStatusBar:(BOOL)arg2 duration:(double)arg3 skipCallbacks:(BOOL)arg4
{
if ([RAMessagingClient.sharedInstance shouldForceOrientation] && arg1 != [RAMessagingClient.sharedInstance forcedOrientation] && [UIApplication.sharedApplication _isSupportedOrientation:arg1])
return;
%orig;
}
- (BOOL)_shouldAutorotateToInterfaceOrientation:(int)arg1 checkForDismissal:(BOOL)arg2 isRotationDisabled:(BOOL*)arg3
{
if ([RAMessagingClient.sharedInstance shouldForceOrientation] && arg1 != [RAMessagingClient.sharedInstance forcedOrientation] && [UIApplication.sharedApplication _isSupportedOrientation:arg1])
return NO;
return %orig;
}
- (void)_setWindowInterfaceOrientation:(int)arg1
{
if ([RAMessagingClient.sharedInstance shouldForceOrientation] && arg1 != [RAMessagingClient.sharedInstance forcedOrientation] && [UIApplication.sharedApplication _isSupportedOrientation:arg1])
return;
%orig([RAMessagingClient.sharedInstance shouldForceOrientation] && [UIApplication.sharedApplication _isSupportedOrientation:[RAMessagingClient.sharedInstance forcedOrientation]] ? [RAMessagingClient.sharedInstance forcedOrientation] : arg1);
}
- (void)_sendTouchesForEvent:(unsafe_id)arg1
{
%orig;
dispatch_async(dispatch_get_main_queue(), ^{
[RAMessagingClient.sharedInstance notifySpringBoardOfFrontAppChangeToSelf];
});
}
%end
%hook UIApplication
-(void) applicationDidResume
{
%orig;
[RAMessagingClient.sharedInstance requestUpdateFromServer];
//[RAFakePhoneMode updateAppSizing];
}
/*
+(void) _startWindowServerIfNecessary
{
%orig;
//[RAMessagingClient.sharedInstance requestUpdateFromServer];
[RAFakePhoneMode updateAppSizing];
}
*/
-(void) _setStatusBarHidden:(BOOL)arg1 animationParameters:(unsafe_id)arg2 changeApplicationFlag:(BOOL)arg3
{
//if ([RASettings.sharedInstance unifyStatusBar])
if ([RAMessagingClient.sharedInstance shouldHideStatusBar])
{
arg1 = YES;
arg3 = YES;
}
else if ([RAMessagingClient.sharedInstance shouldShowStatusBar])
{
arg1 = NO;
arg3 = YES;
}
//arg1 = ((forcingRotation&&NO) || overrideDisplay) ? (isTopApp ? NO : YES) : arg1;
%orig(arg1, arg2, arg3);
}
/*
- (void)_notifySpringBoardOfStatusBarOrientationChangeAndFenceWithAnimationDuration:(double)arg1
{
if (overrideViewControllerDismissal)
return;
%orig;
}
*/
%new -(void) RA_forceRotationToInterfaceOrientation:(UIInterfaceOrientation)orientation isReverting:(BOOL)reverting
{
if (!reverting)
{
if (setPreviousOrientation == NO)
{
setPreviousOrientation = YES;
prevousOrientation = UIApplication.sharedApplication.statusBarOrientation;
if (wasStatusBarHidden == -1)
wasStatusBarHidden = UIApplication.sharedApplication.statusBarHidden;
}
}
else if (setPreviousOrientation)
{
orientation = prevousOrientation;
setPreviousOrientation = NO;
}
if (![UIApplication.sharedApplication _isSupportedOrientation:orientation])
{
return;
}
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
[window _setRotatableViewOrientation:orientation updateStatusBar:YES duration:0.25 force:YES];
}
}
%new -(void) RA_forceStatusBarVisibility:(BOOL)visible orRevert:(BOOL)revert
{
if (revert)
{
if (wasStatusBarHidden != -1)
{
[UIApplication.sharedApplication _setStatusBarHidden:wasStatusBarHidden animationParameters:nil changeApplicationFlag:YES];
}
}
else
{
if (wasStatusBarHidden == -1)
wasStatusBarHidden = UIApplication.sharedApplication.statusBarHidden;
[UIApplication.sharedApplication _setStatusBarHidden:visible animationParameters:nil changeApplicationFlag:YES];
}
}
%new -(void) RA_updateWindowsForSizeChange:(CGSize)size isReverting:(BOOL)revert
{
if (revert)
{
for (UIWindow *window in [[UIApplication sharedApplication] windows])
{
CGRect frame = window.frame;
if ([oldFrames objectForKey:@(window.hash)] != nil)
{
frame = [[oldFrames objectForKey:@(window.hash)] CGRectValue];
[oldFrames removeObjectForKey:@(window.hash)];
}
[UIView animateWithDuration:0.4 animations:^{
[window setFrame:frame];
}];
}
if ([oldFrames objectForKey:@"statusBar"] != nil)
UIApplication.sharedApplication.statusBar.frame = [oldFrames[@"statusBar"] CGRectValue];
return;
}
if (size.width != -1)
{
if ([oldFrames objectForKey:@"statusBar"] == nil)
[oldFrames setObject:[NSValue valueWithCGRect:UIApplication.sharedApplication.statusBar.frame] forKey:@"statusBar"];
UIApplication.sharedApplication.statusBar.frame = CGRectMake(0, 0, size.width, UIApplication.sharedApplication.statusBar.frame.size.height);
}
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
if ([oldFrames objectForKey:@(window.hash)] == nil)
[oldFrames setObject:[NSValue valueWithCGRect:window.frame] forKey:@(window.hash)];
[UIView animateWithDuration:0.3 animations:^{
[window setFrame:window.frame]; // updates with client message app data in the setFrame: hook
}];
}
}
-(BOOL) isNetworkActivityIndicatorVisible
{
if ([RAMessagingClient.sharedInstance isBeingHosted])
return [objc_getAssociatedObject(self, @selector(RA_networkActivity)) boolValue];
else
return %orig;
}
-(void) setNetworkActivityIndicatorVisible:(BOOL)arg1
{
%orig(arg1);
if ([RAMessagingClient.sharedInstance isBeingHosted])
{
objc_setAssociatedObject(self, @selector(RA_networkActivity), @(arg1), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
StatusBarData *data = [UIStatusBarServer getStatusBarData];
data->itemIsEnabled[24] = arg1; // 24 = activity indicator
[UIApplication.sharedApplication.statusBar forceUpdateToData:data animated:YES];
}
}
-(BOOL) openURL:(__unsafe_unretained NSURL*)url
{
if ([RAMessagingClient.sharedInstance isBeingHosted])// || [RASettings.sharedInstance openLinksInWindows])
{
return [RAMessagingClient.sharedInstance notifyServerToOpenURL:url openInWindow:[RASettings.sharedInstance openLinksInWindows]];
}
return %orig;
}
%end
%hook UIStatusBar
-(void) statusBarServer:(unsafe_id)arg1 didReceiveStatusBarData:(StatusBarData*)arg2 withActions:(int)arg3
{
if ([RAMessagingClient.sharedInstance isBeingHosted])
arg2->itemIsEnabled[24] = [UIApplication.sharedApplication isNetworkActivityIndicatorVisible];
%orig;
}
%end
void reloadSettings(CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
[RASettings.sharedInstance reloadSettings];
}
%ctor
{
IF_NOT_SPRINGBOARD {
%init;
$memorized$UITextEffectsWindow$class = objc_getClass("UITextEffectsWindow");
}
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, &reloadSettings, CFSTR("com.efrederickson.reachapp.settings/reloadSettings"), NULL, 0);
[RASettings sharedInstance];
}