Commit e17c415a authored by Jr Prévost's avatar Jr Prévost Committed by Gleb Pinigin

Restart HTTPServer after app resuming (close #8989)

  - save in NSUserDefault the status of the HTTPServer to auto start it.
  - VLCHTTPUploadController now lives in the AppDelegate.
Signed-off-by: Gleb Pinigin's avatarGleb Pinigin <gpinigin@gmail.com>
parent 9ad23a64
......@@ -9,6 +9,7 @@
//
#import "VLCDropboxTableViewController.h"
#import "VLCHTTPUploaderController.h"
@class VLCPlaylistViewController;
@class PAPasscodeViewController;
......@@ -25,4 +26,6 @@
@property (nonatomic, retain) NSDate *nextPasscodeCheckDate;
@property (nonatomic) VLCHTTPUploaderController *uploadController;
@end
......@@ -18,6 +18,7 @@
#import "VLCMovieViewController.h"
#import "PAPasscodeViewController.h"
#import "UINavigationController+Theme.h"
#import "VLCHTTPUploaderController.h"
@interface VLCAppDelegate () <PAPasscodeViewControllerDelegate, VLCMediaFileDiscovererDelegate> {
PAPasscodeViewController *_passcodeLockController;
......@@ -48,6 +49,9 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Init the HTTP Server
self.uploadController = [[VLCHTTPUploaderController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
_playlistViewController = [[VLCPlaylistViewController alloc] init];
......@@ -139,6 +143,11 @@
[self validatePasscode]; // Lock library when going to background
}
- (void)applicationWillTerminate:(UIApplication *)application
{
[[NSUserDefaults standardUserDefaults] synchronize];
}
#pragma mark - properties
- (VLCDropboxTableViewController *)dropboxTableViewController
......
......@@ -22,6 +22,7 @@
#define kVLCSettingSkipLoopFilterNone @(0)
#define kVLCSettingSkipLoopFilterNonRef @(1)
#define kVLCSettingSkipLoopFilterNonKey @(3)
#define kVLCSettingSaveHTTPUploadServerStatus @"isHTTPServerOn"
#define kVLCShowRemainingTime @"show-remaining-time"
#define kVLCRecentURLs @"recent-urls"
......
......@@ -35,6 +35,35 @@ static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE; // | HTTP_LOG_FLAG_TRACE
@implementation VLCHTTPUploaderController
- (id)init
{
if ( self = [super init] ) {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(applicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification object:nil];
return self;
}
else
return nil;
}
- (void)applicationDidBecomeActive: (NSNotification *)notification
{
BOOL isHTTPServerOn = [[NSUserDefaults standardUserDefaults] boolForKey:kVLCSettingSaveHTTPUploadServerStatus];
[self changeHTTPServerState:isHTTPServerOn];
}
- (void)applicationDidEnterBackground: (NSNotification *)notification
{
[self changeHTTPServerState:NO];
}
-(BOOL)changeHTTPServerState:(BOOL)state
{
if(state) {
......
......@@ -29,12 +29,15 @@
#import <arpa/inet.h>
@interface VLCMenuViewController () {
VLCHTTPUploaderController *_uploadController;
VLCHTTPDownloadViewController *_downloadViewController;
Reachability *_reachability;
}
- (void)_presentViewController:(UIViewController *)viewController;
- (void)_dismissModalViewController;
@property(nonatomic) VLCHTTPUploaderController *uploadController;
@property(nonatomic) VLCAppDelegate *appDelegate;;
@end
@implementation VLCMenuViewController
......@@ -74,6 +77,13 @@
[self netReachabilityChanged:nil];
self.appDelegate = [[UIApplication sharedApplication] delegate];
self.uploadController = self.appDelegate.uploadController;
BOOL isHTTPServerOn = [[NSUserDefaults standardUserDefaults] boolForKey:kVLCSettingSaveHTTPUploadServerStatus];
[self.httpUploadServerSwitch setOn:isHTTPServerOn];
[self updateHTTPServerAddress];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(netReachabilityChanged:) name:kReachabilityChangedNotification object:nil];
}
......@@ -169,22 +179,27 @@
return address;
}
- (IBAction)toggleHTTPServer:(UISwitch *)sender
- (void)updateHTTPServerAddress
{
_uploadController = [[VLCHTTPUploaderController alloc] init];
[_uploadController changeHTTPServerState: sender.on];
HTTPServer *server = _uploadController.httpServer;
HTTPServer *server = self.uploadController.httpServer;
if (server.isRunning)
self.httpUploadServerLocationLabel.text = [NSString stringWithFormat:@"http://%@:%i", [self _currentIPAddress], server.listeningPort];
else
self.httpUploadServerLocationLabel.text = NSLocalizedString(@"HTTP_UPLOAD_SERVER_OFF", @"");
}
- (IBAction)toggleHTTPServer:(UISwitch *)sender
{
[[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:kVLCSettingSaveHTTPUploadServerStatus];
[self.uploadController changeHTTPServerState:sender.on];
[self updateHTTPServerAddress];
[[NSUserDefaults standardUserDefaults] synchronize];
}
- (IBAction)showDropbox:(id)sender
{
VLCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
[self _presentViewController:appDelegate.dropboxTableViewController];
self.appDelegate.dropboxTableViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self _presentViewController:self.appDelegate.dropboxTableViewController];
}
#pragma mark - Private methods
......
......@@ -298,15 +298,20 @@
[self.tableView setEditing:editing animated:YES];
}
- (void)initMenuViewController
{
VLCMenuViewController *menuViewController = [[VLCMenuViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:menuViewController];
[navigationController loadTheme];
self.menuViewController = navigationController;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
navigationController.navigationBarHidden = YES;
}
- (IBAction)leftButtonAction:(id)sender
{
if (self.menuViewController == nil) {
VLCMenuViewController *menuViewController = [[VLCMenuViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:menuViewController];
[navigationController loadTheme];
self.menuViewController = navigationController;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
navigationController.navigationBarHidden = YES;
[self initMenuViewController];
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment