Skip to content

Improvement: Do not continue re-connect after quit/shutdown/hibernate/suspend #1310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 16 additions & 24 deletions XBMC Remote/HostManagementViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,7 @@ - (void)modifyHost:(NSIndexPath*)item {
[serverListTableView deselectRowAtIndexPath:item animated:YES];
cell.accessoryType = UITableViewCellAccessoryNone;
storeServerSelection = nil;
AppDelegate.instance.obj.serverDescription = @"";
AppDelegate.instance.obj.serverUser = @"";
AppDelegate.instance.obj.serverPass = @"";
AppDelegate.instance.obj.serverRawIP = @"";
AppDelegate.instance.obj.serverIP = @"";
AppDelegate.instance.obj.serverPort = @"";
AppDelegate.instance.obj.serverHWAddr = @"";
AppDelegate.instance.obj.tcpPort = 0;
[Utilities resetKodiServerParameters];
[[NSNotificationCenter defaultCenter] postNotificationName:@"XBMCServerHasChanged" object:nil];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:@(-1) forKey:@"lastServer"];
Expand Down Expand Up @@ -169,15 +162,8 @@ - (void)deselectServerAtIndexPath:(NSIndexPath*)indexPath {
[serverListTableView deselectRowAtIndexPath:indexPath animated:YES];
cell.accessoryType = UITableViewCellAccessoryNone;
storeServerSelection = nil;
AppDelegate.instance.obj.serverDescription = @"";
AppDelegate.instance.obj.serverUser = @"";
AppDelegate.instance.obj.serverPass = @"";
AppDelegate.instance.obj.serverRawIP = @"";
AppDelegate.instance.obj.serverIP = @"";
AppDelegate.instance.obj.serverPort = @"";
AppDelegate.instance.obj.serverHWAddr = @"";
[Utilities resetKodiServerParameters];
AppDelegate.instance.serverOnLine = NO;
AppDelegate.instance.obj.tcpPort = 0;
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:@(-1) forKey:@"lastServer"];
((UIImageView*)[cell viewWithTag:XIB_HOST_MGMT_CELL_ICON]).image = [UIImage imageNamed:@"connection_off"];
Expand Down Expand Up @@ -235,14 +221,7 @@ - (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEdi
}
else if (storeServerSelection.row == indexPath.row) {
storeServerSelection = nil;
AppDelegate.instance.obj.serverDescription = @"";
AppDelegate.instance.obj.serverUser = @"";
AppDelegate.instance.obj.serverPass = @"";
AppDelegate.instance.obj.serverRawIP = @"";
AppDelegate.instance.obj.serverIP = @"";
AppDelegate.instance.obj.serverPort = @"";
AppDelegate.instance.obj.serverHWAddr = @"";
AppDelegate.instance.obj.tcpPort = 0;
[Utilities resetKodiServerParameters];
[[NSNotificationCenter defaultCenter] postNotificationName:@"XBMCServerHasChanged" object:nil];
[userDefaults setObject:@(-1) forKey:@"lastServer"];
}
Expand Down Expand Up @@ -288,6 +267,14 @@ - (IBAction)editTable:(id)sender forceClose:(BOOL)forceClose {
}
}

#pragma mark - Helper

- (void)handleDisconnectActiveServer {
// Deselect any current active server
NSIndexPath *selection = [serverListTableView indexPathForSelectedRow];
[self deselectServerAtIndexPath:selection];
}

#pragma mark - Long Press & Action sheet

- (void)handleLongPress {
Expand Down Expand Up @@ -657,6 +644,11 @@ - (void)viewDidLoad {
selector:@selector(enablePopGestureRecognizer:)
name:@"ECSlidingViewTopDidReset"
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleDisconnectActiveServer)
name:@"DisconnectActiveServer"
object:nil];
}

- (void)powerControl {
Expand Down
1 change: 1 addition & 0 deletions XBMC Remote/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,6 @@ typedef NS_ENUM(NSInteger, LogoBackgroundType) {
+ (UIViewController*)topMostController;
+ (UIViewController*)topMostControllerIgnoringClass:(Class)ignoredClass;
+ (uint64_t)memoryFootprint;
+ (void)resetKodiServerParameters;

@end
49 changes: 39 additions & 10 deletions XBMC Remote/Utilities.m
Original file line number Diff line number Diff line change
Expand Up @@ -507,11 +507,14 @@ + (UIAlertController*)createAlertCopyClipboard:(NSString*)title message:(NSStrin
return alertCtrl;
}

+ (void)powerAction:(NSString*)command {
+ (void)powerAction:(NSString*)command onSuccess:(void (^)(void))onSuccess {
[[Utilities getJsonRPC] callMethod:command withParameters:@{} onCompletion:^(NSString *methodName, NSInteger callId, id methodResult, DSJSONRPCError *methodError, NSError *error) {
// User already confirmed, so we only show a short-lived message.
if (methodError == nil && error == nil) {
[Utilities showMessage:LOCALIZED_STR(@"Command executed") color:SUCCESS_MESSAGE_COLOR];
if (onSuccess) {
onSuccess();
}
}
else {
[Utilities showMessage:LOCALIZED_STR(@"Cannot do that") color:ERROR_MESSAGE_COLOR];
Expand All @@ -538,47 +541,55 @@ + (UIAlertController*)createPowerControl {
}
else {
UIAlertAction *action_pwr_off_system = [UIAlertAction actionWithTitle:LOCALIZED_STR(@"Power off System") style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
[self powerAction:@"System.Shutdown"];
[self powerAction:@"System.Shutdown" onSuccess:^{
[Utilities disconnectFromActiveServer];
}];
}];
[alertCtrl addAction:action_pwr_off_system];

UIAlertAction *action_quit_kodi = [UIAlertAction actionWithTitle:LOCALIZED_STR(@"Quit XBMC application") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self powerAction:@"Application.Quit"];
[self powerAction:@"Application.Quit" onSuccess:^{
[Utilities disconnectFromActiveServer];
}];
}];
[alertCtrl addAction:action_quit_kodi];

UIAlertAction *action_hibernate = [UIAlertAction actionWithTitle:LOCALIZED_STR(@"Hibernate") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self powerAction:@"System.Hibernate"];
[self powerAction:@"System.Hibernate" onSuccess:^{
[Utilities disconnectFromActiveServer];
}];
}];
[alertCtrl addAction:action_hibernate];

UIAlertAction *action_suspend = [UIAlertAction actionWithTitle:LOCALIZED_STR(@"Suspend") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self powerAction:@"System.Suspend"];
[self powerAction:@"System.Suspend" onSuccess:^{
[Utilities disconnectFromActiveServer];
}];
}];
[alertCtrl addAction:action_suspend];

UIAlertAction *action_reboot = [UIAlertAction actionWithTitle:LOCALIZED_STR(@"Reboot") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self powerAction:@"System.Reboot"];
[self powerAction:@"System.Reboot" onSuccess:nil];
}];
[alertCtrl addAction:action_reboot];

UIAlertAction *action_scan_audio_lib = [UIAlertAction actionWithTitle:LOCALIZED_STR(@"Update Audio Library") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self powerAction:@"AudioLibrary.Scan"];
[self powerAction:@"AudioLibrary.Scan" onSuccess:nil];
}];
[alertCtrl addAction:action_scan_audio_lib];

UIAlertAction *action_clean_audio_lib = [UIAlertAction actionWithTitle:LOCALIZED_STR(@"Clean Audio Library") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self powerAction:@"AudioLibrary.Clean"];
[self powerAction:@"AudioLibrary.Clean" onSuccess:nil];
}];
[alertCtrl addAction:action_clean_audio_lib];

UIAlertAction *action_scan_video_lib = [UIAlertAction actionWithTitle:LOCALIZED_STR(@"Update Video Library") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self powerAction:@"VideoLibrary.Scan"];
[self powerAction:@"VideoLibrary.Scan" onSuccess:nil];
}];
[alertCtrl addAction:action_scan_video_lib];

UIAlertAction *action_clean_video_lib = [UIAlertAction actionWithTitle:LOCALIZED_STR(@"Clean Video Library") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
[self powerAction:@"VideoLibrary.Clean"];
[self powerAction:@"VideoLibrary.Clean" onSuccess:nil];
}];
[alertCtrl addAction:action_clean_video_lib];
}
Expand Down Expand Up @@ -1417,4 +1428,22 @@ + (uint64_t)memoryFootprint {
return vmInfo.phys_footprint;
}

+ (void)resetKodiServerParameters {
AppDelegate.instance.obj.serverDescription = @"";
AppDelegate.instance.obj.serverUser = @"";
AppDelegate.instance.obj.serverPass = @"";
AppDelegate.instance.obj.serverRawIP = @"";
AppDelegate.instance.obj.serverIP = @"";
AppDelegate.instance.obj.serverPort = @"";
AppDelegate.instance.obj.serverHWAddr = @"";
AppDelegate.instance.obj.tcpPort = 0;
}

+ (void)disconnectFromActiveServer {
[Utilities resetKodiServerParameters];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:@(-1) forKey:@"lastServer"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"DisconnectActiveServer" object:nil];
}

@end
Loading