Fix: replace all currentWindow() with static variable
This commit is contained in:
1 parent
15d2e1b275
commit
bc36365994
13 files changed
+34
-31
No files matched your search
@@ -2,6 +2,8 @@
|
||||
#import "ios_uikit_bridge.h"
|
||||
#import "utils.h"
|
||||
|
||||
extern UIWindow *mainWindow;
|
||||
|
||||
@interface SceneDelegate ()
|
||||
|
||||
@end
|
||||
@@ -13,6 +15,7 @@
|
||||
UIWindowScene *windowScene = (UIWindowScene *)scene;
|
||||
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
|
||||
self.window.frame = windowScene.coordinateSpace.bounds;
|
||||
mainWindow = self.window;
|
||||
launchInitialViewController(self.window);
|
||||
[self.window makeKeyAndVisible];
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#import "SceneExternalDelegate.h"
|
||||
#import "SurfaceViewController.h"
|
||||
|
||||
extern UIWindow* currentWindow();
|
||||
extern UIWindow *externalWindow;
|
||||
|
||||
@interface SceneExternalDelegate ()
|
||||
|
||||
@@ -15,8 +15,9 @@ extern UIWindow* currentWindow();
|
||||
UIWindowScene *windowScene = (UIWindowScene *)scene;
|
||||
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
|
||||
self.window.frame = windowScene.coordinateSpace.bounds;
|
||||
externalWindow = self.window;
|
||||
if (SurfaceViewController.isRunning && getPrefBool(@"video.fullscreen_airplay")) {
|
||||
[currentWindow().rootViewController performSelector:@selector(switchToExternalDisplay)];
|
||||
[UIWindow.mainWindow.rootViewController performSelector:@selector(switchToExternalDisplay)];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +28,7 @@ extern UIWindow* currentWindow();
|
||||
// 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).
|
||||
if (SurfaceViewController.isRunning && getPrefBool(@"video.fullscreen_airplay")) {
|
||||
[currentWindow().rootViewController performSelector:@selector(switchToInternalDisplay)];
|
||||
[UIWindow.mainWindow.rootViewController performSelector:@selector(switchToInternalDisplay)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
noteLabel.text = localize(@"game.note.airplay", nil);
|
||||
[self.touchView addSubview:noteLabel];
|
||||
|
||||
UIWindow *secondWindow = currentWindowInScene(1);
|
||||
UIWindow *secondWindow = UIWindow.externalWindow;
|
||||
secondWindow.rootViewController = [[UIViewController alloc] init];
|
||||
[secondWindow.rootViewController.view addSubview:self.surfaceView];
|
||||
[secondWindow.rootViewController.view addSubview:self.mousePointerView];
|
||||
@@ -29,7 +29,7 @@
|
||||
[self.surfaceView removeFromSuperview];
|
||||
[self.mousePointerView removeFromSuperview];
|
||||
|
||||
UIWindow *secondWindow = currentWindowInScene(1);
|
||||
UIWindow *secondWindow = UIWindow.externalWindow;
|
||||
secondWindow.hidden = YES;
|
||||
|
||||
[self.touchView.subviews[0] removeFromSuperview];
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "UIKit+hook.h"
|
||||
|
||||
#import "customcontrols/ControlLayout.h"
|
||||
#import "GameSurfaceView.h"
|
||||
|
||||
@@ -1064,7 +1064,7 @@ int touchesMovedCount;
|
||||
}
|
||||
|
||||
+ (BOOL)isRunning {
|
||||
return [currentWindow().rootViewController isKindOfClass:SurfaceViewController.class];
|
||||
return [UIWindow.mainWindow.rootViewController isKindOfClass:SurfaceViewController.class];
|
||||
}
|
||||
|
||||
+ (GameSurfaceView *)surface {
|
||||
|
||||
@@ -32,6 +32,11 @@
|
||||
@property(assign, nonatomic) NSInteger nonEditingLinebreakMode;
|
||||
@end
|
||||
|
||||
@interface UIWindow(global)
|
||||
+ (UIWindow *)mainWindow;
|
||||
+ (UIWindow *)externalWindow;
|
||||
@end
|
||||
|
||||
/*
|
||||
@interface WFTextTokenTextView : UITextField
|
||||
@property(nonatomic) NSString* placeholder
|
||||
|
||||
+11
-16
@@ -4,6 +4,8 @@
|
||||
#import "UIKit+hook.h"
|
||||
#import "utils.h"
|
||||
|
||||
__weak UIWindow *mainWindow, *externalWindow;
|
||||
|
||||
void swizzle(Class class, SEL originalAction, SEL swizzledAction) {
|
||||
method_exchangeImplementations(class_getInstanceMethod(class, originalAction), class_getInstanceMethod(class, swizzledAction));
|
||||
}
|
||||
@@ -119,6 +121,14 @@ void init_hookUIKitConstructor(void) {
|
||||
|
||||
@implementation UIWindow(hook)
|
||||
|
||||
+ (UIWindow *)mainWindow {
|
||||
return mainWindow;
|
||||
}
|
||||
|
||||
+ (UIWindow *)externalWindow {
|
||||
return externalWindow;
|
||||
}
|
||||
|
||||
- (UIViewController *)visibleViewController {
|
||||
UIViewController *current = self.rootViewController;
|
||||
while (current.presentedViewController) {
|
||||
@@ -144,21 +154,6 @@ void init_hookUIKitConstructor(void) {
|
||||
}
|
||||
@end
|
||||
|
||||
UIWindow* currentWindowInScene(BOOL external) {
|
||||
id delegate = UIApplication.sharedApplication.delegate;
|
||||
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes.allObjects) {
|
||||
if (external != (scene.session.role == UIWindowSceneSessionRoleApplication)) {
|
||||
delegate = scene.delegate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return [delegate window];
|
||||
}
|
||||
|
||||
UIWindow* currentWindow() {
|
||||
return currentWindowInScene(0);
|
||||
}
|
||||
|
||||
UIViewController* currentVC() {
|
||||
return currentWindow().visibleViewController;
|
||||
return UIWindow.mainWindow.visibleViewController;
|
||||
}
|
||||
@@ -119,7 +119,7 @@ NSMutableDictionary* createButton(NSString* name, int* keycodes, NSString* dynam
|
||||
debugLabel.lineBreakMode = NSLineBreakByWordWrapping;
|
||||
debugLabel.numberOfLines = 0;
|
||||
debugLabel.userInteractionEnabled = NO;
|
||||
[currentWindow() addSubview:debugLabel];
|
||||
[UIWindow.mainWindow addSubview:debugLabel];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@ BOOL leftShiftHeld;
|
||||
deltaX *= deltaTimeScale;
|
||||
deltaY *= deltaTimeScale;
|
||||
|
||||
SurfaceViewController *vc = (id)(currentWindow().rootViewController);
|
||||
SurfaceViewController *vc = (id)UIWindow.mainWindow.rootViewController;
|
||||
[vc sendTouchPoint:CGPointMake(deltaX, deltaY) withEvent:ACTION_MOVE_MOTION];
|
||||
}
|
||||
lastFrameTime = frameTime;
|
||||
|
||||
@@ -62,7 +62,7 @@ static CMMotionManager* cmInstance;
|
||||
lastYValue = cmInstance.deviceMotion.rotationRate.y / (M_PI*90) * windowHeight * factor;
|
||||
}
|
||||
|
||||
SurfaceViewController *vc = (id)(currentWindow().rootViewController);
|
||||
SurfaceViewController *vc = (id)UIWindow.mainWindow.rootViewController;
|
||||
[vc sendTouchPoint:CGPointMake(lastXValue, lastYValue) withEvent:ACTION_MOVE_MOTION];
|
||||
|
||||
lastFrameTime = frameTime;
|
||||
|
||||
@@ -55,7 +55,7 @@ void openURLGlobal(NSString *path) {
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if ([path hasPrefix:@"http"]) {
|
||||
openLink(currentWindow().rootViewController, [NSURL URLWithString:path]);
|
||||
openLink(UIWindow.mainWindow.rootViewController, [NSURL URLWithString:path]);
|
||||
dispatch_group_leave(group);
|
||||
return;
|
||||
}
|
||||
@@ -395,7 +395,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSetGrabbing(JNIE
|
||||
isGrabbing = grabbing;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
SurfaceViewController *vc = ((SurfaceViewController *)currentWindow().rootViewController);
|
||||
SurfaceViewController *vc = ((SurfaceViewController *)UIWindow.mainWindow.rootViewController);
|
||||
[vc updateGrabState];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ void internal_showDialog(NSString* title, NSString* message) {
|
||||
UIAlertAction* okAction = [UIAlertAction actionWithTitle:localize(@"OK", nil) style:UIAlertActionStyleDefault handler:nil];
|
||||
[alert addAction:okAction];
|
||||
|
||||
UIWindow *alertWindow = [[UIWindow alloc] initWithWindowScene:currentWindow().windowScene];
|
||||
UIWindow *alertWindow = [[UIWindow alloc] initWithWindowScene:UIWindow.mainWindow.windowScene];
|
||||
alertWindow.frame = UIScreen.mainScreen.bounds;
|
||||
alertWindow.rootViewController = [UIViewController new];
|
||||
alertWindow.windowLevel = 1000;
|
||||
@@ -128,7 +128,7 @@ void UIKit_returnToSplitView() {
|
||||
// Researching memory-safe ways to return from SurfaceViewController to the split view
|
||||
// so that the app doesn't close when quitting the game (similar behaviour to Android)
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIWindow *window = currentWindow();
|
||||
UIWindow *window = UIWindow.mainWindow;
|
||||
|
||||
// Return from JavaGUIViewController
|
||||
if ([window.rootViewController isKindOfClass:LauncherSplitViewController.class]) {
|
||||
|
||||
@@ -65,8 +65,6 @@ void init_setupMultiDir();
|
||||
|
||||
BOOL PLPatchMachOPlatformForFile(const char *path);
|
||||
|
||||
UIWindow* currentWindow();
|
||||
UIWindow* currentWindowInScene(BOOL external);
|
||||
UIViewController* currentVC();
|
||||
void openLink(UIViewController* sender, NSURL* link);
|
||||
|
||||
|
||||
Reference in new issue
Block a user