-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweak.xm
More file actions
91 lines (76 loc) · 2.96 KB
/
Tweak.xm
File metadata and controls
91 lines (76 loc) · 2.96 KB
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
//
// Tweak.xm
// Pastie
//
// Created by Tanner Bennett on 2021-05-07
// Copyright © 2021 Tanner Bennett. All rights reserved.
//
#import "Interfaces.h"
static UIWindow *_pastieWindow = nil;
/// Present the Pastie controller at half height
%hook _UISheetPresentationController
- (id)initWithPresentedViewController:(id)present presentingViewController:(id)presenter {
self = %orig;
if ([present isKindOfClass:PastieController.self]) {
self._presentsAtStandardHalfHeight = YES;
}
return self;
}
%end
/// Prevent this window from being hidden while Pastie is presented
%hook SBBannerWindow
- (void)setHidden:(BOOL)hidden {
if (hidden && PastieController.isPresented) return;
%orig;
}
%end
void ServerMain(CFMachPortRef port, LMMessage *message, CFIndex size, void *info) {
// Get the reply port
mach_port_t replyPort = message->head.msgh_remote_port;
// Check validity of message
if (!LMDataWithSizeIsValidMessage(message, size)) {
LMSendReply(replyPort, NULL, 0);
LMResponseBufferFree((LMResponseBuffer *)message);
return;
}
// Get message data
// const char *data = (const char *)LMMessageGetData(message);
// size_t length = LMMessageGetDataLength(message);
// Show pastie
if (!PastieController.isPresented) {
// Show it from the banner window; the banner window is usually hidden,
// so show it first. Pastie will hide it when it dismisses.
SpringBoard *springboard = (id)UIApplication.sharedApplication;
UIWindow *window = _pastieWindow; window.hidden = NO;
// window.rootViewController = [PastieController new];
// UIWindow *window = springboard.bannerManager.bannerWindow; window.hidden = NO;
UIViewController *root = window.rootViewController;
[root presentViewController:[PastieController new] animated:YES completion:nil];
}
// If we ever need to send data back
LMSendReply(replyPort, nil, 0);
// Cleanup
LMResponseBufferFree((LMResponseBuffer *)message);
}
%ctor {
%init;
dispatch_async(dispatch_get_main_queue(), ^{
// Start LightMessaging server
LMStartService(_kPackageName, CFRunLoopGetCurrent(), (CFMachPortCallBack)ServerMain);
// Create pastie window
_pastieWindow = [[PastieWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
_pastieWindow.rootViewController = [UIViewController new];
_pastieWindow.rootViewController.view.userInteractionEnabled = NO;
});
// Observe pasteboard notifications
static int token = 0;
dispatch_queue_t global = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
notify_register_dispatch("com.apple.pasteboard.notify.changed", &token, global, ^(int _){
UIPasteboard *pb = UIPasteboard.generalPasteboard;
if (pb.hasImages) {
// [PDBManager.sharedManager addImages:pb.images];
} else {
[PDBManager.sharedManager addStrings:pb.strings];
}
});
}