109 lines
2.6 KiB
Plaintext
109 lines
2.6 KiB
Plaintext
#import <SpringBoard/SpringBoard.h>
|
||
#import <SpringBoard/SBAlertItemsController.h>
|
||
#import <SpringBoard/SBUserNotificationAlert.h>
|
||
#import <SpringBoard/SBApplication.h>
|
||
#import <SpringBoard/SBWorkspace.h>
|
||
#import <SpringBoard/SBApplicationController.h>
|
||
|
||
|
||
#import <UIKit/UIKit.h>
|
||
#import <objc/runtime.h>
|
||
|
||
#import "server/MySimpleServer.h"
|
||
#import "server/FloatingWindow.h"
|
||
|
||
@interface UIWindow (FloatingWindow)
|
||
@end
|
||
|
||
@implementation UIWindow (FloatingWindow)
|
||
|
||
- (void)addFloatingWindow {
|
||
// Check if already exists
|
||
if (objc_getAssociatedObject(self, @selector(addFloatingWindow))) {
|
||
return;
|
||
}
|
||
|
||
// Create floating window
|
||
UIWindow *floatingWindow = [[FloatingWindow alloc] initWithFrame];
|
||
floatingWindow.windowLevel = UIWindowLevelAlert + 1;
|
||
floatingWindow.layer.masksToBounds = YES;
|
||
|
||
// Show window
|
||
floatingWindow.hidden = NO;
|
||
|
||
// Associate object to prevent multiple windows
|
||
objc_setAssociatedObject(self, @selector(addFloatingWindow), floatingWindow, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||
}
|
||
|
||
|
||
|
||
@end
|
||
|
||
%group all
|
||
|
||
%hook SpringBoard
|
||
|
||
- (void)applicationDidFinishLaunching:(id)arg1
|
||
{
|
||
%orig;
|
||
|
||
// 延迟启动服务器,让系统UI完全加载
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
|
||
dispatch_get_main_queue(), ^{
|
||
startSimpleServer();
|
||
});
|
||
|
||
@autoreleasepool {
|
||
// 延迟添加悬浮窗,给系统UI足够的启动时间
|
||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)),
|
||
dispatch_get_main_queue(), ^{
|
||
// 添加保护机制
|
||
@try {
|
||
for (UIWindowScene *windowScene in [UIApplication sharedApplication].connectedScenes) {
|
||
if ([windowScene isKindOfClass:[UIWindowScene class]]) {
|
||
UIWindow *window = windowScene.windows.firstObject;
|
||
if (window) {
|
||
[window addFloatingWindow];
|
||
}
|
||
}
|
||
}
|
||
} @catch (NSException *exception) {
|
||
NSLog(@"Add floating window error: %@", exception);
|
||
}
|
||
});
|
||
}
|
||
}
|
||
|
||
// 添加生命周期方法以便清理
|
||
- (void)applicationWillTerminate:(id)arg1 {
|
||
%orig;
|
||
// 清理服务器资源
|
||
// 清理悬浮窗
|
||
}
|
||
|
||
|
||
%end
|
||
|
||
/*
|
||
// 注入网络权限
|
||
%hook NSBundle
|
||
|
||
- (NSDictionary *)infoDictionary {
|
||
NSMutableDictionary *dict = [[%orig mutableCopy] copy];
|
||
[dict setObject:@YES forKey:@"NSLocalNetworkUsageDescription"];
|
||
[dict setObject:@YES forKey:@"NSAllowsLocalNetworking"];
|
||
return dict;
|
||
}
|
||
|
||
|
||
%end
|
||
*/
|
||
|
||
|
||
%end
|
||
|
||
|
||
%ctor{
|
||
NSLog(@"start app server");
|
||
%init(all);
|
||
} |