mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-17 06:01:13 +00:00
Allow the stream to be inactive for 10 seconds before terminating
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
@implementation StreamFrameViewController {
|
@implementation StreamFrameViewController {
|
||||||
ControllerSupport *_controllerSupport;
|
ControllerSupport *_controllerSupport;
|
||||||
StreamManager *_streamMan;
|
StreamManager *_streamMan;
|
||||||
|
NSTimer *_inactivityTimer;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidAppear:(BOOL)animated
|
- (void)viewDidAppear:(BOOL)animated
|
||||||
@@ -42,7 +43,7 @@
|
|||||||
[UIApplication sharedApplication].idleTimerDisabled = YES;
|
[UIApplication sharedApplication].idleTimerDisabled = YES;
|
||||||
|
|
||||||
_controllerSupport = [[ControllerSupport alloc] initWithConfig:self.streamConfig];
|
_controllerSupport = [[ControllerSupport alloc] initWithConfig:self.streamConfig];
|
||||||
|
_inactivityTimer = nil;
|
||||||
_streamMan = [[StreamManager alloc] initWithConfig:self.streamConfig
|
_streamMan = [[StreamManager alloc] initWithConfig:self.streamConfig
|
||||||
renderView:self.view
|
renderView:self.view
|
||||||
connectionCallbacks:self];
|
connectionCallbacks:self];
|
||||||
@@ -53,6 +54,24 @@
|
|||||||
selector:@selector(applicationWillResignActive:)
|
selector:@selector(applicationWillResignActive:)
|
||||||
name:UIApplicationWillResignActiveNotification
|
name:UIApplicationWillResignActiveNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||||
|
selector: @selector(applicationDidBecomeActive:)
|
||||||
|
name: UIApplicationDidBecomeActiveNotification
|
||||||
|
object: nil];
|
||||||
|
|
||||||
|
[[NSNotificationCenter defaultCenter] addObserver: self
|
||||||
|
selector: @selector(applicationDidEnterBackground:)
|
||||||
|
name: UIApplicationDidEnterBackgroundNotification
|
||||||
|
object: nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)viewDidDisappear:(BOOL)animated {
|
||||||
|
if (_inactivityTimer != nil) {
|
||||||
|
[_inactivityTimer invalidate];
|
||||||
|
_inactivityTimer = nil;
|
||||||
|
}
|
||||||
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) returnToMainFrame {
|
- (void) returnToMainFrame {
|
||||||
@@ -61,13 +80,55 @@
|
|||||||
[self.navigationController popToRootViewControllerAnimated:YES];
|
[self.navigationController popToRootViewControllerAnimated:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This will fire if the user opens control center or gets a low battery message
|
||||||
- (void)applicationWillResignActive:(NSNotification *)notification {
|
- (void)applicationWillResignActive:(NSNotification *)notification {
|
||||||
|
if (_inactivityTimer != nil) {
|
||||||
|
[_inactivityTimer invalidate];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Terminate the stream if the app is inactive for 10 seconds
|
||||||
|
Log(LOG_I, @"Starting inactivity termination timer");
|
||||||
|
_inactivityTimer = [NSTimer scheduledTimerWithTimeInterval:10
|
||||||
|
target:self
|
||||||
|
selector:@selector(inactiveTimerExpired:)
|
||||||
|
userInfo:nil
|
||||||
|
repeats:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)inactiveTimerExpired:(NSTimer*)timer {
|
||||||
|
Log(LOG_I, @"Terminating stream after inactivity");
|
||||||
|
|
||||||
|
[_streamMan stopStream];
|
||||||
|
[self returnToMainFrame];
|
||||||
|
|
||||||
|
_inactivityTimer = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)applicationDidBecomeActive:(NSNotification *)notification {
|
||||||
|
// Stop the background timer, since we're foregrounded again
|
||||||
|
if (_inactivityTimer != nil) {
|
||||||
|
Log(LOG_I, @"Stopping inactivity timer after becoming active again");
|
||||||
|
[_inactivityTimer invalidate];
|
||||||
|
_inactivityTimer = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This fires when the home button is pressed
|
||||||
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||||
|
Log(LOG_I, @"Terminating stream immediately for backgrounding");
|
||||||
|
|
||||||
|
if (_inactivityTimer != nil) {
|
||||||
|
[_inactivityTimer invalidate];
|
||||||
|
_inactivityTimer = nil;
|
||||||
|
}
|
||||||
|
|
||||||
[_streamMan stopStream];
|
[_streamMan stopStream];
|
||||||
[self returnToMainFrame];
|
[self returnToMainFrame];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)edgeSwiped {
|
- (void)edgeSwiped {
|
||||||
Log(LOG_D, @"User swiped to end stream");
|
Log(LOG_I, @"User swiped to end stream");
|
||||||
|
|
||||||
[_streamMan stopStream];
|
[_streamMan stopStream];
|
||||||
[self returnToMainFrame];
|
[self returnToMainFrame];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user