From a021784d48ea6dbc7b33c032bfa600e5a8840f4e Mon Sep 17 00:00:00 2001 From: True Zhuanjia Date: Mon, 8 Jul 2024 19:06:59 +0800 Subject: [PATCH] replace force expand & close of settings view with background resolution width & height swap --- Limelight/Database/DataManager.h | 3 +- .../ViewControllers/MainFrameViewController.m | 31 ++++++++++++++++--- Moonlight.xcodeproj/project.pbxproj | 2 ++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Limelight/Database/DataManager.h b/Limelight/Database/DataManager.h index 70299456..018b3201 100644 --- a/Limelight/Database/DataManager.h +++ b/Limelight/Database/DataManager.h @@ -44,7 +44,8 @@ - (void) updateAppsForExistingHost:(TemporaryHost *)host; - (void) removeHost:(TemporaryHost*)host; - (void) removeApp:(TemporaryApp*)app; - +- (Settings*) retrieveSettings; +- (void) saveData; - (TemporarySettings*) getSettings; - (void) updateUniqueId:(NSString*)uniqueId; diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 5b891420..acc841c4 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -28,6 +28,7 @@ #import "ConnectionHelper.h" #import "LocalizationHelper.h" #import "CustomEdgeSwipeGestureRecognizer.h" +#import "DataManager.h" #if !TARGET_OS_TV #import "SettingsViewController.h" @@ -1075,11 +1076,27 @@ static NSMutableSet* hostList; //if([SettingsViewController isLandscapeNow] != _streamConfig.width > _streamConfig.height) - [self simulateSettingsButtonPress]; //force expand setting view if orientation changed since last quit from app. - [self simulateSettingsButtonPress]; //force expand setting view if orientation changed since last quit from app. - + //[self simulateSettingsButtonPress]; //force expand setting view if orientation changed since last quit from app. + //[self simulateSettingsButtonPress]; //force expand setting view if orientation changed since last quit from app. + [self swapResolutionWidthHeightAccordingly]; } +-(void)swapResolutionWidthHeightAccordingly{ + DataManager* dataMan = [[DataManager alloc] init]; + Settings *currentSettings = [dataMan retrieveSettings]; + CGFloat screenWidthInPoints = CGRectGetWidth([[UIScreen mainScreen] bounds]); + CGFloat screenHeightInPoints = CGRectGetHeight([[UIScreen mainScreen] bounds]); + bool needSwap = ((currentSettings.width.floatValue - currentSettings.height.floatValue) * (screenWidthInPoints - screenHeightInPoints)) < 0; + NSLog(@"need to swap width & height: %d", needSwap); + if(needSwap){ + CGFloat tmpLength = currentSettings.width.floatValue; + currentSettings.width = @(currentSettings.height.floatValue); + currentSettings.height = @(tmpLength); + [dataMan saveData]; + } +} + + #if TARGET_OS_TV -(void)handleCollectionViewLongPress:(UILongPressGestureRecognizer *)gestureRecognizer { @@ -1199,10 +1216,14 @@ static NSMutableSet* hostList; selector: @selector(handleEnterBackground) name: UIApplicationWillResignActiveNotification object: nil]; - [self simulateSettingsButtonPress]; //force reload resolution table in the setting - [self simulateSettingsButtonPress]; + //[self simulateSettingsButtonPress]; //force reload resolution table in the setting + //[self simulateSettingsButtonPress]; + [self swapResolutionWidthHeightAccordingly]; } + + + - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; diff --git a/Moonlight.xcodeproj/project.pbxproj b/Moonlight.xcodeproj/project.pbxproj index 8ba5e194..05b1f473 100644 --- a/Moonlight.xcodeproj/project.pbxproj +++ b/Moonlight.xcodeproj/project.pbxproj @@ -1542,6 +1542,7 @@ "$(PROJECT_DIR)/Limelight/ViewControllers/CustomOSCViewControl/Cells", "$(PROJECT_DIR)/Limelight/Input", "$(PROJECT_DIR)/Limelight/Localization", + "$(PROJECT_DIR)/Limelight/Database", ); INFOPLIST_FILE = "Limelight/Limelight-Info.plist"; INFOPLIST_KEY_CFBundleDisplayName = MoonlightZWM; @@ -1598,6 +1599,7 @@ "$(PROJECT_DIR)/Limelight/ViewControllers/CustomOSCViewControl/Cells", "$(PROJECT_DIR)/Limelight/Input", "$(PROJECT_DIR)/Limelight/Localization", + "$(PROJECT_DIR)/Limelight/Database", ); INFOPLIST_FILE = "Limelight/Limelight-Info.plist"; INFOPLIST_KEY_CFBundleDisplayName = MoonlightZWM;