-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKBDock.xm
187 lines (166 loc) · 9.32 KB
/
KBDock.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
#import "KBDock.h"
#import "KBDockCollectionView.h"
#import "Manager/DLicenseManager.h"
#import "KBDockMacro.h"
#import "KBDockClipBoardViewController.h"
#import <objc/runtime.h>
#import "UIView+Extend.h"
#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height
#define kTopWindow [[UIApplication sharedApplication]keyWindow]
static NSString *KBDockSettingsPlist = @"/var/mobile/Library/Preferences/com.nactro.kbdocksettings.plist";
static NSString *bundleName = @"com.nactro.kbdock";
static NSString *trialerLicensePath = @"/var/mobile/Library/nactro/trial/com.nactro.kbdock.dat";
static NSString *licensePath = @"/var/mobile/Library/nactro/com.nactro.kbdock.dat";
static NSString *bundlePath = @"/Library/PreferenceBundles/KBDockSettings.bundle";
static NSString *publicKey = @"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAptsM8G+m3huFQMYqFkV6Ky5TiGqCjE6G3oL9/XSTAkCyQcVQFry17sN5u2s/7YZq0hZZmDpwXE16y2+feUMz4UI9BuS1zr9IiSqoDRKln3amekA7VLfuwuY6ptEJDqRfl114iLvkfXmArThPS7L1G43fFX5HhsblXF6SrQNHr4HHUMlSaGFBW0s5MYK1hLynV/lkn7heE87BEW13D3XwhVhHTNboZ9tABpStMbTHRUxB1Mjb79TjB0qFUvC7VP57Rd5DzO++GQwdAniKYTisJ5ZPoN9yY7dGoSWhYBz3Te7dlcCNzzSVXDrAvjvXNdkuZvf2iA8FS85QTl3IKIoHLQIDAQAB";
static BOOL enabledClipBoradSwitch = NO;
static BOOL enabledGlobalSwitch = NO;
static BOOL licenseStatus = NO;
static void loadPrefs() {
NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:KBDockSettingsPlist];
if (prefs) {
enabledGlobalSwitch = ([[prefs objectForKey:@"enabledGlobalSwitch"] boolValue] ? [[prefs objectForKey:@"enabledGlobalSwitch"] boolValue] : enabledGlobalSwitch);
enabledClipBoradSwitch = ([[prefs objectForKey:@"enabledClipBoradSwitch"] boolValue] ? [[prefs objectForKey:@"enabledClipBoradSwitch"] boolValue] : enabledClipBoradSwitch);
}
[prefs release];
}
static void verifySignature(){
NSFileManager *fileManager = [NSFileManager defaultManager];
// 首先判断有没有试用文件
if([fileManager fileExistsAtPath:licensePath] && [fileManager fileExistsAtPath:trialerLicensePath]){ // 同时存在有先判断正式激活文件
// 如果存在,就验证文件
BOOL result = [DLicenseManager verifyLicenseFromPath:licensePath publicKey:publicKey bundleName:bundleName];
if (result) {
licenseStatus = YES;
}else{
licenseStatus = NO;
}
}else if([fileManager fileExistsAtPath:licensePath]){ //判断正式激活文件是否存在
// 存在则验证
BOOL result = [DLicenseManager verifyLicenseFromPath:licensePath publicKey:publicKey bundleName:bundleName];
if (result) {
licenseStatus = YES;
}else{
licenseStatus = NO;
}
}else if([fileManager fileExistsAtPath:trialerLicensePath]){
BOOL trial = [DLicenseManager verifyTrailerLicenseFromPath:trialerLicensePath publicKey:publicKey bundleName:bundleName];
if (trial) {
licenseStatus = YES;
}else{
licenseStatus = NO;
}
}else{
licenseStatus = NO;
}
}
/* =========================== Hook Dock 栏,添加 App 图标 ===================== */
%hook UIKeyboardDockView
%property (retain, nonatomic) KBDockCollectionView *appDock;
%property (retain, nonatomic) UIButton *clipBoardBtn;
- (instancetype)initWithFrame:(CGRect)frame {
//licenseStatus = YES;
UIKeyboardDockView *dockView = %orig;
//licenseStatus &&
if (enabledGlobalSwitch) {
if (dockView) {
self.appDock = [[KBDockCollectionView alloc]init];
self.appDock.translatesAutoresizingMaskIntoConstraints = NO;
[dockView addSubview:self.appDock];
[dockView addConstraint:[NSLayoutConstraint constraintWithItem:self.appDock attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:dockView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:73]]; // 60
[dockView addConstraint:[NSLayoutConstraint constraintWithItem:self.appDock attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:dockView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-58]];
[dockView addConstraint:[NSLayoutConstraint constraintWithItem:self.appDock attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:40]];
[dockView addConstraint:[NSLayoutConstraint constraintWithItem:self.appDock attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:dockView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-22]];
if (enabledClipBoradSwitch){
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kbDidGetNotifOfStandardGlyphColor:) name:@"kbDidChangeStandardGlyphColor" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(kbDidGetNotifOfDarkGlyphColor:) name:@"kbDidChangeDarkStyleGlyphColor" object:nil];
self.clipBoardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.clipBoardBtn.translatesAutoresizingMaskIntoConstraints = NO;
[self.clipBoardBtn addTarget:self action:@selector(clipBoardBtnButtonClick:) forControlEvents:UIControlEventTouchUpInside];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(clipBoardButtonLongPress:)];
[self.clipBoardBtn addGestureRecognizer:longPress];
[dockView addSubview:self.clipBoardBtn];
[dockView addConstraint:[NSLayoutConstraint constraintWithItem:self.clipBoardBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:dockView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-15]];
[dockView addConstraint:[NSLayoutConstraint constraintWithItem:self.clipBoardBtn attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:35]];
[dockView addConstraint:[NSLayoutConstraint constraintWithItem:self.clipBoardBtn attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:35]];
[dockView addConstraint:[NSLayoutConstraint constraintWithItem:self.clipBoardBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:dockView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-27]];
}
return dockView;
}else{
return %orig;
}
}else{
return %orig;
}
}
/* =========================== Hook Dock 栏听写键,去除听写键 ===================== */
- (void)setRightDockItem:(UIKeyboardDockItem *)arg1{
if (enabledClipBoradSwitch) {
%orig(nil);
}else{
%orig;
}
}
/* =========================== 移除通知 ===================== */
- (void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
%orig;
}
/* =========================== 黏贴文本方法 ===================== */
%new
- (void)clipBoardBtnButtonClick:(id)sender{
UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
[[NSClassFromString(@"UIKeyboardImpl") activeInstance] insertText:pasteBoard.string];
}
%new
- (void)clipBoardButtonLongPress:(UIGestureRecognizer *)recognizer{
if (recognizer.state == UIGestureRecognizerStateBegan) {
KBDockClipBoardViewController *vc = [[KBDockClipBoardViewController alloc]initWithViewFrame:CGRectMake(10,0,375 - 10 *2 ,300)];
vc.view.alpha = 0.0;
UIViewController *inputVC = [self viewController];
NSLog(@"dockView所在的控制器------>%@ ------>%f -------->%f",inputVC,inputVC.view.frame.size.height,inputVC.view.frame.size.width);
[inputVC.view addSubview:vc.view];
[vc animateForPresentation];
}else {
NSLog(@"long pressTap state :end");
}
}
/* =========================== 通知响应方法 ===================== */
%new
- (void)kbDidGetNotifOfStandardGlyphColor:(NSNotification *)notif{
NSString *imagePath = notif.userInfo[@"image"];
[self.clipBoardBtn setBackgroundImage:[UIImage imageWithContentsOfFile:imagePath] forState:UIControlStateNormal];
}
%new
- (void)kbDidGetNotifOfDarkGlyphColor:(NSNotification *)notif{
NSString *imagePath = notif.userInfo[@"image"];
[self.clipBoardBtn setBackgroundImage:[UIImage imageWithContentsOfFile:imagePath] forState:UIControlStateNormal];
}
%end
/*
* 注意,Apple 所定义的 standard 指的是 UIDock 的颜色,即「白灰色」,因此,图片需要变为 dark
* 同理
*/
%hook UIKeyboardDockItem
+ (id)_standardGlyphColor{
[[NSNotificationCenter defaultCenter] postNotificationName:@"kbDidChangeStandardGlyphColor" object:nil userInfo:@{@"image":[bundlePath stringByAppendingPathComponent:@"pasteDark.png"]}];
return %orig;
}
+ (id)_darkStyleGlyphColor{
[[NSNotificationCenter defaultCenter] postNotificationName:@"kbDidChangeDarkStyleGlyphColor" object:nil userInfo:@{@"image":[bundlePath stringByAppendingPathComponent:@"pasteStandard.png"]}];
return %orig;
}
%end
/* =========================== UIPasteboard ===================== */
%hook UIPasteboard
- (void)setString:(NSString *)arg1{
[[NSNotificationCenter defaultCenter] postNotificationName:@"kbDidSetString" object:nil userInfo:@{@"string":arg1}];
%orig;
}
%end
%ctor {
//verifySignature();
loadPrefs();
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)loadPrefs, CFSTR("com.nactro.kbdocksettings/changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
}