2022-10-07 07:25:20 +08:00
|
|
|
#import <Foundation/Foundation.h>
|
2022-10-12 04:57:08 +08:00
|
|
|
#import "TSHAppDelegateNoScene.h"
|
|
|
|
#import "TSHAppDelegateWithScene.h"
|
|
|
|
#import "TSHSceneDelegate.h"
|
|
|
|
#import <TSUtil.h>
|
2022-10-07 07:25:20 +08:00
|
|
|
#import <objc/runtime.h>
|
|
|
|
|
2022-10-08 00:34:06 +08:00
|
|
|
BOOL sceneDelegateFix(void)
|
2022-10-07 07:25:20 +08:00
|
|
|
{
|
2022-10-08 00:34:06 +08:00
|
|
|
NSString* sceneDelegateClassName = nil;
|
|
|
|
|
|
|
|
NSDictionary* UIApplicationSceneManifest = [NSBundle.mainBundle objectForInfoDictionaryKey:@"UIApplicationSceneManifest"];
|
|
|
|
if(UIApplicationSceneManifest && [UIApplicationSceneManifest isKindOfClass:NSDictionary.class])
|
|
|
|
{
|
|
|
|
NSDictionary* UISceneConfiguration = UIApplicationSceneManifest[@"UISceneConfigurations"];
|
|
|
|
if(UISceneConfiguration && [UISceneConfiguration isKindOfClass:NSDictionary.class])
|
|
|
|
{
|
|
|
|
NSArray* UIWindowSceneSessionRoleApplication = UISceneConfiguration[@"UIWindowSceneSessionRoleApplication"];
|
|
|
|
if(UIWindowSceneSessionRoleApplication && [UIWindowSceneSessionRoleApplication isKindOfClass:NSArray.class])
|
|
|
|
{
|
|
|
|
NSDictionary* sceneToUse = nil;
|
|
|
|
if(UIWindowSceneSessionRoleApplication.count > 1)
|
|
|
|
{
|
|
|
|
for(NSDictionary* scene in UIWindowSceneSessionRoleApplication)
|
|
|
|
{
|
|
|
|
if([scene isKindOfClass:NSDictionary.class])
|
|
|
|
{
|
|
|
|
NSString* UISceneConfigurationName = scene[@"UISceneConfigurationName"];
|
|
|
|
if([UISceneConfigurationName isKindOfClass:NSString.class])
|
|
|
|
{
|
|
|
|
if([UISceneConfigurationName isEqualToString:@"Default Configuration"])
|
|
|
|
{
|
|
|
|
sceneToUse = scene;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!sceneToUse)
|
|
|
|
{
|
|
|
|
sceneToUse = UIWindowSceneSessionRoleApplication.firstObject;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sceneToUse = UIWindowSceneSessionRoleApplication.firstObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sceneToUse && [sceneToUse isKindOfClass:NSDictionary.class])
|
|
|
|
{
|
|
|
|
sceneDelegateClassName = sceneToUse[@"UISceneDelegateClassName"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(sceneDelegateClassName && [sceneDelegateClassName isKindOfClass:NSString.class])
|
|
|
|
{
|
2022-10-12 04:57:08 +08:00
|
|
|
Class newClass = objc_allocateClassPair([TSHSceneDelegate class], sceneDelegateClassName.UTF8String, 0);
|
2022-10-08 00:34:06 +08:00
|
|
|
objc_registerClassPair(newClass);
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
2022-10-07 07:25:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[], char *envp[]) {
|
|
|
|
@autoreleasepool {
|
2022-10-12 04:57:08 +08:00
|
|
|
#ifdef EMBEDDED_ROOT_HELPER
|
|
|
|
extern int rootHelperMain(int argc, char *argv[], char *envp[]);
|
2022-10-07 07:25:20 +08:00
|
|
|
if(getuid() == 0)
|
|
|
|
{
|
2022-10-12 04:57:08 +08:00
|
|
|
// I got this idea while taking a dump
|
2022-10-07 07:25:20 +08:00
|
|
|
// Don't judge
|
|
|
|
return rootHelperMain(argc, argv, envp);
|
|
|
|
}
|
2022-10-12 04:57:08 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
chineseWifiFixup();
|
|
|
|
if(sceneDelegateFix())
|
|
|
|
{
|
|
|
|
return UIApplicationMain(argc, argv, nil, NSStringFromClass(TSHAppDelegateWithScene.class));
|
|
|
|
}
|
2022-10-07 07:25:20 +08:00
|
|
|
else
|
|
|
|
{
|
2022-10-12 04:57:08 +08:00
|
|
|
return UIApplicationMain(argc, argv, nil, NSStringFromClass(TSHAppDelegateNoScene.class));
|
2022-10-07 07:25:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|