Skip to content

Commit b7586da

Browse files
committed
fix profiles
1 parent 4afc19b commit b7586da

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

AppProxyCap

ShadowsocksX/ProfileManager.m

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ + (Configuration *)configuration {
4545
}
4646

4747
+ (void)saveConfiguration:(Configuration *)configuration {
48+
if (configuration.profiles.count == 0) {
49+
configuration.current = -1;
50+
}
51+
if (configuration.current != -1 && configuration.current >= configuration.profiles.count) {
52+
configuration.current = 0;
53+
}
4854
[[NSUserDefaults standardUserDefaults] setObject:[configuration JSONData] forKey:CONFIG_DATA_KEY];
4955
[ProfileManager reloadShadowsocksRunner];
5056
}

ShadowsocksX/SWBConfigWindowController.m

+14-10
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,16 @@ - (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row {
5858
return YES;
5959
}
6060
if (row >= 0 && row < configuration.profiles.count) {
61-
return [self validateCurrentProfile];
61+
if ([self validateCurrentProfile]) {
62+
[self saveCurrentProfile];
63+
} else {
64+
return NO;
65+
}
6266
}
6367
// always allow selection to no selection
6468
return YES;
6569
}
6670

67-
- (void)tableViewSelectionIsChanging:(NSNotification *)notification {
68-
if (self.tableView.selectedRow >= 0) {
69-
[self saveCurrentProfile];
70-
}
71-
}
72-
7371
- (void)tableViewSelectionDidChange:(NSNotification *)notification {
7472
if (self.tableView.selectedRow >= 0) {
7573
[self loadCurrentProfile];
@@ -116,9 +114,14 @@ - (IBAction)remove:(id)sender {
116114
[((NSMutableArray *) configuration.profiles) removeObjectAtIndex:selection];
117115
[self.tableView reloadData];
118116
[self updateSettingsBoxVisible:self];
119-
}
120-
if (configuration.profiles.count > 0) {
121-
[self.tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:(configuration.profiles.count - 1)] byExtendingSelection:NO];
117+
if (configuration.profiles.count > 0) {
118+
[self.tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:(configuration.profiles.count - 1)] byExtendingSelection:NO];
119+
}
120+
[self loadCurrentProfile];
121+
if (configuration.current > selection) {
122+
// select the original profile
123+
configuration.current = configuration.current - 1;
124+
}
122125
}
123126
}
124127

@@ -196,6 +199,7 @@ - (IBAction)OK:(id)sender {
196199
if ([self saveCurrentProfile]) {
197200
[self saveSettings];
198201
[ShadowsocksRunner reloadConfig];
202+
[self.delegate configurationDidChange];
199203
[self.window performClose:self];
200204
} else {
201205
[self shakeWindow];

0 commit comments

Comments
 (0)