From fa5dcdc727b59cfb85385496db3c565a081e83f7 Mon Sep 17 00:00:00 2001 From: Duy Tran Khanh Date: Mon, 1 Feb 2021 06:12:05 +0700 Subject: [PATCH] Add SceneDelegate (for 13.0+) --- Natives/AppDelegate.m | 54 ++++++++++++---------------- Natives/CMakeLists.txt | 2 +- Natives/SceneDelegate.h | 7 ++++ Natives/SceneDelegate.m | 63 +++++++++++++++++++++++++++++++++ Natives/SurfaceViewController.m | 4 +-- Natives/aminimake.sh | 2 +- 6 files changed, 96 insertions(+), 36 deletions(-) create mode 100644 Natives/SceneDelegate.h create mode 100644 Natives/SceneDelegate.m diff --git a/Natives/AppDelegate.m b/Natives/AppDelegate.m index 6a82e52d..ac018896 100644 --- a/Natives/AppDelegate.m +++ b/Natives/AppDelegate.m @@ -1,47 +1,37 @@ #import "AppDelegate.h" - #import "LauncherViewController.h" +#import "SceneDelegate.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - UIWindow *window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; - self.window = window; - [self.window setWindowLevel:3000.0]; - [self.window makeKeyAndVisible]; - self.window.backgroundColor = [UIColor whiteColor]; - - LauncherViewController *vc = [[LauncherViewController alloc] init]; - self.window.rootViewController = vc; + if (@available(iOS 13.0, *)) { + + } else { + LauncherViewController *vc = [[LauncherViewController alloc] init]; + UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc]; + self.window = ([[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]); + [self.window makeKeyAndVisible]; + self.window.rootViewController = nav; + } return YES; } - -- (void)applicationWillResignActive:(UIApplication *)application -{ - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. + +#pragma mark - UISceneSession lifecycle + + +- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)connectingSceneSession options:(UISceneConnectionOptions *)options API_AVAILABLE(ios(13.0)){ + // Called when a new scene session is being created. + // Use this method to select a configuration to create the new scene with. + return [[UISceneConfiguration alloc] initWithName:@"Default Configuration" sessionRole:connectingSceneSession.role]; } -- (void)applicationDidEnterBackground:(UIApplication *)application -{ - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. -} -- (void)applicationWillEnterForeground:(UIApplication *)application -{ - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. -} - -- (void)applicationDidBecomeActive:(UIApplication *)application -{ - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. -} - -- (void)applicationWillTerminate:(UIApplication *)application -{ - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +- (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet *)sceneSessions API_AVAILABLE(ios(13.0)){ + // Called when the user discards a scene session. + // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. + // Use this method to release any resources that were specific to the discarded scenes, as they will not return. } @end diff --git a/Natives/CMakeLists.txt b/Natives/CMakeLists.txt index 88d66376..be0fb884 100644 --- a/Natives/CMakeLists.txt +++ b/Natives/CMakeLists.txt @@ -13,7 +13,7 @@ set_target_properties(PojavLauncher PROPERTIES MACOSX_FRAMEWORK_IDENTIFIER org.cmake.ExecutableTarget MACOSX_BUNDLE_INFO_PLIST "../Info.plist") -add_library(pojavexec SHARED log.m AppDelegate.m UILauncher.m LauncherViewController.m SurfaceViewController.m egl_bridge_ios.m ios_uikit_bridge.m egl_bridge.c input_bridge_v3.c utils.c) +add_library(pojavexec SHARED log.m AppDelegate.m SceneDelegate.m UILauncher.m LauncherViewController.m SurfaceViewController.m egl_bridge_ios.m ios_uikit_bridge.m egl_bridge.c input_bridge_v3.c utils.c) target_link_libraries(pojavexec "-Fresources/Frameworks" "-framework UIKit" diff --git a/Natives/SceneDelegate.h b/Natives/SceneDelegate.h new file mode 100644 index 00000000..9d3a8ba4 --- /dev/null +++ b/Natives/SceneDelegate.h @@ -0,0 +1,7 @@ +#import + +@interface SceneDelegate : UIResponder + +@property (strong, nonatomic) UIWindow * window; + +@end diff --git a/Natives/SceneDelegate.m b/Natives/SceneDelegate.m new file mode 100644 index 00000000..6565aac8 --- /dev/null +++ b/Natives/SceneDelegate.m @@ -0,0 +1,63 @@ + +#import "SceneDelegate.h" +#import "LauncherViewController.h" + +@interface SceneDelegate () + +@end + +@implementation SceneDelegate + + +- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions API_AVAILABLE(ios(13.0)) API_AVAILABLE(ios(13.0)) API_AVAILABLE(ios(13.0)){ + + if (@available(iOS 13.0, *)) { + LauncherViewController *vc = [[LauncherViewController alloc] init]; + UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc]; + UIWindowScene *windowScene = (UIWindowScene *)scene; + self.window = [[UIWindow alloc] initWithWindowScene:windowScene]; + self.window.frame = windowScene.coordinateSpace.bounds; + self.window.rootViewController = nav; + [self.window makeKeyAndVisible]; + } else { + + } + + +} + + +- (void)sceneDidDisconnect:(UIScene *)scene API_AVAILABLE(ios(13.0)){ + // Called as the scene is being released by the system. + // This occurs shortly after the scene enters the background, or when its session is discarded. + // Release any resources associated with this scene that can be re-created the next time the scene connects. + // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). +} + + +- (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){ + // Called when the scene has moved from an inactive state to an active state. + // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. +} + + +- (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){ + // Called when the scene will move from an active state to an inactive state. + // This may occur due to temporary interruptions (ex. an incoming phone call). +} + + +- (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){ + // Called as the scene transitions from the background to the foreground. + // Use this method to undo the changes made on entering the background. +} + + +- (void)sceneDidEnterBackground:(UIScene *)scene API_AVAILABLE(ios(13.0)){ + // Called as the scene transitions from the foreground to the background. + // Use this method to save data, release shared resources, and store enough scene-specific state information + // to restore the scene back to its current state. +} + + +@end diff --git a/Natives/SurfaceViewController.m b/Natives/SurfaceViewController.m index d71e13ff..75aef242 100644 --- a/Natives/SurfaceViewController.m +++ b/Natives/SurfaceViewController.m @@ -174,8 +174,8 @@ ADD_BUTTON_DEF(special_togglebtn) { } -(void)inputViewDidReturn { - sendData(EVENT_TYPE_ENTER, GLFW_KEY_BACKSPACE, 0, 1, 0); - sendData(EVENT_TYPE_ENTER, GLFW_KEY_BACKSPACE, 0, 0, 0); + sendData(EVENT_TYPE_KEY, GLFW_KEY_ENTER, 0, 1, 0); + sendData(EVENT_TYPE_KEY, GLFW_KEY_ENTER, 0, 0, 0); } ADD_BUTTON_DEF(special_keyboard) { diff --git a/Natives/aminimake.sh b/Natives/aminimake.sh index 7d46cfae..6fb49e73 100644 --- a/Natives/aminimake.sh +++ b/Natives/aminimake.sh @@ -5,7 +5,7 @@ set -e CFLAGS="-fmessage-length=0 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -Wno-trigraphs -fpascal-strings -O3 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wno-float-conversion -Wno-non-literal-null-conversion -Wno-objc-literal-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof" -clang -Wl,-rpath,/Applications/PojavLauncher.app/Frameworks -fobjc-arc -x objective-c -Fresources/Frameworks -framework UIKit -framework MetalANGLE -Iresources/Frameworks/MetalANGLE.framework/Headers -dynamiclib -isysroot /var/mobile/theos/sdks/iPhoneOS11.2.sdk $CFLAGS -o libpojavexec.dylib log.m AppDelegate.m UILauncher.m LauncherViewController.m SurfaceViewController.m egl_bridge_ios.m ios_uikit_bridge.m egl_bridge.c input_bridge_v3.c utils.c -DGLES_TESTZ -DUSE_EGLZ +clang -Wl,-rpath,/Applications/PojavLauncher.app/Frameworks -fobjc-arc -x objective-c -Fresources/Frameworks -framework UIKit -framework MetalANGLE -Iresources/Frameworks/MetalANGLE.framework/Headers -dynamiclib -isysroot /var/mobile/theos/sdks/iPhoneOS11.2.sdk $CFLAGS -o libpojavexec.dylib log.m AppDelegate.m SceneDelegate.m UILauncher.m LauncherViewController.m SurfaceViewController.m egl_bridge_ios.m ios_uikit_bridge.m egl_bridge.c input_bridge_v3.c utils.c -DGLES_TESTZ -DUSE_EGLZ ldid -S../entitlements.xml libpojavexec.dylib