iOS: Fix restarts after the scene change (for backend change etc)

This commit is contained in:
Henrik Rydgård 2025-10-17 21:07:53 +02:00
parent 34385ea1fd
commit 3cc57b7a2b
4 changed files with 23 additions and 4 deletions

View File

@ -10,7 +10,6 @@
@property (strong, nonatomic) UIScreen *screen;
@property (nonatomic, strong) NSDictionary *launchOptions;
- (void)restart:(const char *)args;
- (BOOL)launchPPSSPP:(int)argc argv:(char**)argv;
@end

View File

@ -3,7 +3,10 @@
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate>
- (void)restart:(const char *)args;
@property (strong, nonatomic) UIWindow * window;
@property (strong, nonatomic) UIViewController *viewController;
@property (strong, nonatomic) UIWindowScene *windowScene;
@end

View File

@ -32,7 +32,12 @@
NSLog(@"✅ Window already exists, not creating again!");
return;
}
self.windowScene = windowScene;
[self launchPPSSPP];
}
-(void) launchPPSSPP {
INFO_LOG(Log::G3D, "SceneDelegate: Launching PPSSPP");
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
NSDictionary *launchOptions = appDelegate.launchOptions;
@ -50,7 +55,7 @@
NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/assets/"];
NativeInit(argc, (const char**)argv, documentsPath.UTF8String, bundlePath.UTF8String, NULL);
self.window = [[UIWindow alloc] initWithWindowScene:windowScene];
self.window = [[UIWindow alloc] initWithWindowScene:self.windowScene];
// self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Choose viewcontroller depending on backend.
@ -87,7 +92,7 @@
NativeShutdown();
// Launch a fresh instance
[self launchPPSSPP:0 argv:nullptr];
[self launchPPSSPP];
// Notify new view controller
[self.viewController didBecomeActive];

View File

@ -26,6 +26,7 @@
#import "ViewController.h"
#import "iOSCoreAudio.h"
#import "IAPManager.h"
#import "SceneDelegate.h"
#include "Common/MemoryUtil.h"
#include "Common/Audio/AudioBackend.h"
@ -439,7 +440,18 @@ bool System_MakeRequest(SystemRequestType type, int requestId, const std::string
switch (type) {
case SystemRequestType::RESTART_APP:
dispatch_async(dispatch_get_main_queue(), ^{
[(AppDelegate *)[[UIApplication sharedApplication] delegate] restart:param1.c_str()];
// Get the connected scenes
NSSet<UIScene *> *scenes = [UIApplication sharedApplication].connectedScenes;
// Loop through scenes to find a UIWindowScene that is active
for (UIScene *scene in scenes) {
if ([scene isKindOfClass:[UIWindowScene class]]) {
UIWindowScene *windowScene = (UIWindowScene *)scene;
SceneDelegate *sceneDelegate = (SceneDelegate *)windowScene.delegate;
[sceneDelegate restart:param1.c_str()];
break; // call only on the first active scene
}
}
});
return true;