From a8e3b92fb50a38dde441cab1532cad7e69c84985 Mon Sep 17 00:00:00 2001 From: antoinealbaut23 <301678550+antoinealbaut23@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:24:02 +0200 Subject: [PATCH 1/2] Adopt the UIScene lifecycle on iOS Apps built with the iOS 27 SDK are terminated at launch by UIKit if they don't use the scene-based lifecycle. Add a SceneDelegate that creates the window from the existing iPhone/iPad storyboards, and forward home screen quick actions and launch shortcuts to the existing AppDelegate handling. Co-Authored-By: Claude Opus 5.5 --- Limelight/AppDelegate.h | 9 ++++++++ Limelight/AppDelegate.m | 39 ++++++++++++++++++++++++++++++++++ Limelight/Limelight-Info.plist | 21 ++++++++++++++---- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/Limelight/AppDelegate.h b/Limelight/AppDelegate.h index 90deb4076..c5b0a5ffb 100644 --- a/Limelight/AppDelegate.h +++ b/Limelight/AppDelegate.h @@ -23,3 +23,12 @@ - (NSURL*) getStoreURL; @end + +#if !TARGET_OS_TV +// Required by iOS 27: apps built with the current SDK must use the scene lifecycle +@interface SceneDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + +@end +#endif diff --git a/Limelight/AppDelegate.m b/Limelight/AppDelegate.m index 5db73f57d..487ba3bcb 100644 --- a/Limelight/AppDelegate.m +++ b/Limelight/AppDelegate.m @@ -212,3 +212,42 @@ - (NSURL*) getStoreURL { } @end + +#if !TARGET_OS_TV +@implementation SceneDelegate + +- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions { + if (![scene isKindOfClass:[UIWindowScene class]]) { + return; + } + + AppDelegate* appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate; + + // Shortcut used to launch the app (previously in the launch options) + UIApplicationShortcutItem* shortcut = connectionOptions.shortcutItem; + if (shortcut != nil) { + appDelegate.pcUuidToLoad = (NSString*)[shortcut.userInfo objectForKey:@"UUID"]; + } + + // Same storyboards as UIMainStoryboardFile / UIMainStoryboardFile~ipad + NSString* storyboardName = UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad ? @"iPad" : @"iPhone"; + UIStoryboard* storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil]; + + self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene*)scene]; + self.window.rootViewController = [storyboard instantiateInitialViewController]; + appDelegate.window = self.window; + [self.window makeKeyAndVisible]; +} + +- (void)windowScene:(UIWindowScene *)windowScene performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler { + [(AppDelegate*)UIApplication.sharedApplication.delegate application:UIApplication.sharedApplication + performActionForShortcutItem:shortcutItem + completionHandler:completionHandler]; +} + +- (void)sceneDidEnterBackground:(UIScene *)scene { + [(AppDelegate*)UIApplication.sharedApplication.delegate saveContext]; +} + +@end +#endif diff --git a/Limelight/Limelight-Info.plist b/Limelight/Limelight-Info.plist index 963c433d5..2004a6cfc 100644 --- a/Limelight/Limelight-Info.plist +++ b/Limelight/Limelight-Info.plist @@ -58,14 +58,27 @@ NSLocalNetworkUsageDescription Moonlight uses the local network to connect to your gaming PC for streaming. + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + SceneDelegate + + + + UIApplicationSupportsIndirectInputEvents UILaunchStoryboardName Launch Screen - UIMainStoryboardFile - iPhone - UIMainStoryboardFile~ipad - iPad UIRequiredDeviceCapabilities armv7 From 6d1ba0280d9200e6ffdb872d1a2951f4362e6e72 Mon Sep 17 00:00:00 2001 From: antoinealbaut23 <301678550+antoinealbaut23@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:24:02 +0200 Subject: [PATCH 2/2] Resize the video layer when the stream view changes size The display layer was sized once when the stream started, so the video didn't follow window size changes during a stream, such as folding or unfolding iPhone Duo. Let the stream view follow its parent and lay out the display layer again when the size changes. Fixes #728 Co-Authored-By: Claude Opus 5.5 --- Limelight/Stream/StreamManager.h | 2 ++ Limelight/Stream/StreamManager.m | 8 +++++ Limelight/Stream/VideoDecoderRenderer.h | 1 + Limelight/Stream/VideoDecoderRenderer.m | 30 +++++++++++++---- .../StreamFrameViewController.m | 32 +++++++++++++++++-- 5 files changed, 65 insertions(+), 8 deletions(-) diff --git a/Limelight/Stream/StreamManager.h b/Limelight/Stream/StreamManager.h index 277d6fe43..29611cb23 100644 --- a/Limelight/Stream/StreamManager.h +++ b/Limelight/Stream/StreamManager.h @@ -15,6 +15,8 @@ - (void) stopStream; +- (void) updateRendererLayout; + - (NSString*) getStatsOverlayText; @end diff --git a/Limelight/Stream/StreamManager.m b/Limelight/Stream/StreamManager.m index e776feef0..532f25c08 100644 --- a/Limelight/Stream/StreamManager.m +++ b/Limelight/Stream/StreamManager.m @@ -25,6 +25,7 @@ @implementation StreamManager { UIView* _renderView; id _callbacks; Connection* _connection; + VideoDecoderRenderer* _renderer; } - (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionCallbacks:(id)callbacks { @@ -100,12 +101,19 @@ - (void)main { // Initializing the renderer must be done on the main thread dispatch_async(dispatch_get_main_queue(), ^{ VideoDecoderRenderer* renderer = [[VideoDecoderRenderer alloc] initWithView:self->_renderView callbacks:self->_callbacks streamAspectRatio:(float)self->_config.width / (float)self->_config.height useFramePacing:self->_config.useFramePacing]; + self->_renderer = renderer; self->_connection = [[Connection alloc] initWithConfig:self->_config renderer:renderer connectionCallbacks:self->_callbacks]; NSOperationQueue* opQueue = [[NSOperationQueue alloc] init]; [opQueue addOperation:self->_connection]; }); } +// Must be called on the main thread +- (void) updateRendererLayout +{ + [_renderer updateDisplayLayerLayout]; +} + - (void) stopStream { [_connection terminate]; diff --git a/Limelight/Stream/VideoDecoderRenderer.h b/Limelight/Stream/VideoDecoderRenderer.h index 0513374b0..b62bbd38f 100644 --- a/Limelight/Stream/VideoDecoderRenderer.h +++ b/Limelight/Stream/VideoDecoderRenderer.h @@ -20,6 +20,7 @@ - (void)start; - (void)stop; - (void)setHdrMode:(BOOL)enabled; +- (void)updateDisplayLayerLayout; - (int)submitDecodeBuffer:(unsigned char *)data length:(int)length bufferType:(int)bufferType decodeUnit:(PDECODE_UNIT)du; diff --git a/Limelight/Stream/VideoDecoderRenderer.m b/Limelight/Stream/VideoDecoderRenderer.m index 5c89e5ade..7da0564bb 100644 --- a/Limelight/Stream/VideoDecoderRenderer.m +++ b/Limelight/Stream/VideoDecoderRenderer.m @@ -37,13 +37,8 @@ @implementation VideoDecoderRenderer { BOOL framePacing; } -- (void)reinitializeDisplayLayer +- (void)layoutDisplayLayer { - CALayer *oldLayer = displayLayer; - - displayLayer = [[AVSampleBufferDisplayLayer alloc] init]; - displayLayer.backgroundColor = [UIColor blackColor].CGColor; - // Ensure the AVSampleBufferDisplayLayer is sized to preserve the aspect ratio // of the video stream. We used to use AVLayerVideoGravityResizeAspect, but that // respects the PAR encoded in the SPS which causes our computed video-relative @@ -57,6 +52,29 @@ - (void)reinitializeDisplayLayer } displayLayer.position = CGPointMake(CGRectGetMidX(_view.bounds), CGRectGetMidY(_view.bounds)); displayLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height); +} + +// Called when the view size changes (e.g. folding or unfolding iPhone Duo) +- (void)updateDisplayLayerLayout +{ + if (displayLayer == nil) { + return; + } + + [CATransaction begin]; + [CATransaction setDisableActions:YES]; + [self layoutDisplayLayer]; + [CATransaction commit]; +} + +- (void)reinitializeDisplayLayer +{ + CALayer *oldLayer = displayLayer; + + displayLayer = [[AVSampleBufferDisplayLayer alloc] init]; + displayLayer.backgroundColor = [UIColor blackColor].CGColor; + + [self layoutDisplayLayer]; displayLayer.videoGravity = AVLayerVideoGravityResize; // Hide the layer until we get an IDR frame. This ensures we diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index a4c8f3448..431270456 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -44,6 +44,7 @@ @implementation StreamFrameViewController { UILabel *_tipLabel; UIActivityIndicatorView *_spinner; StreamView *_streamView; + CGSize _lastLayoutSize; UIScrollView *_scrollView; BOOL _userIsInteracting; CGSize _keyboardSize; @@ -107,7 +108,8 @@ - (void)viewDidLoad _controllerSupport = [[ControllerSupport alloc] initWithConfig:self.streamConfig delegate:self]; _inactivityTimer = nil; - _streamView = [[StreamView alloc] initWithFrame:self.view.frame]; + _streamView = [[StreamView alloc] initWithFrame:self.view.bounds]; + _streamView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; [_streamView setupStreamView:_controllerSupport interactionDelegate:self config:self.streamConfig]; #if TARGET_OS_TV @@ -188,7 +190,8 @@ - (void)viewDidLoad // Only enable scroll and zoom in absolute touch mode if (_settings.absoluteTouchMode) { - _scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame]; + _scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds]; + _scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; #if !TARGET_OS_TV [_scrollView.panGestureRecognizer setMinimumNumberOfTouches:2]; #endif @@ -215,6 +218,31 @@ - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { return _streamView; } +// The window can change size during a stream, for example when folding or +// unfolding iPhone Duo. Keep the stream view and video layer filling it. +- (void)viewDidLayoutSubviews { + [super viewDidLayoutSubviews]; + + CGSize size = self.view.bounds.size; + if (CGSizeEqualToSize(size, _lastLayoutSize)) { + return; + } + _lastLayoutSize = size; + + if (_scrollView != nil) { + // Reset any zoom so the stream view can match the new size + [_scrollView setZoomScale:1.0f animated:NO]; + _streamView.frame = _scrollView.bounds; + _scrollView.contentSize = _scrollView.bounds.size; + } + + _stageLabel.center = CGPointMake(size.width / 2, _stageLabel.center.y); + _spinner.center = CGPointMake(size.width / 2, _spinner.center.y); + _tipLabel.center = CGPointMake(size.width / 2, _tipLabel.center.y); + + [_streamMan updateRendererLayout]; +} + - (void)willMoveToParentViewController:(UIViewController *)parent { // Only cleanup when we're being destroyed if (parent == nil) {