12
12
#import " SWBAppDelegate.h"
13
13
#import " GCDWebServer.h"
14
14
#import " ShadowsocksRunner.h"
15
+ #import " ProfileManager.h"
15
16
16
17
#define kShadowsocksIsRunningKey @" ShadowsocksIsRunning"
17
18
#define kShadowsocksRunningModeKey @" ShadowsocksMode"
@@ -26,6 +27,7 @@ @implementation SWBAppDelegate {
26
27
NSMenuItem *autoMenuItem;
27
28
NSMenuItem *globalMenuItem;
28
29
NSMenuItem *qrCodeMenuItem;
30
+ NSMenu *serversMenu;
29
31
BOOL isRunning;
30
32
NSString *runningMode;
31
33
NSData *originalPACData;
@@ -79,7 +81,14 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
79
81
[menu addItem: globalMenuItem];
80
82
81
83
[menu addItem: [NSMenuItem separatorItem ]];
82
- [menu addItemWithTitle: _L (Open Server Preferences...) action: @selector (showConfigWindow ) keyEquivalent: @" " ];
84
+
85
+ serversMenu = [[NSMenu alloc ] init ];
86
+ NSMenuItem *serversItem = [[NSMenuItem alloc ] init ];
87
+ [serversItem setTitle: @" Servers" ];
88
+ [serversItem setSubmenu: serversMenu];
89
+ [menu addItem: serversItem];
90
+
91
+ [menu addItem: [NSMenuItem separatorItem ]];
83
92
[menu addItemWithTitle: _L (Edit PAC for Auto Proxy Mode...) action: @selector (editPAC ) keyEquivalent: @" " ];
84
93
qrCodeMenuItem = [[NSMenuItem alloc ] initWithTitle: _L (Show QR Code...) action: @selector (showQRCode ) keyEquivalent: @" " ];
85
94
[menu addItem: qrCodeMenuItem];
@@ -122,6 +131,39 @@ - (void)enableGlobal {
122
131
[self reloadSystemProxy ];
123
132
}
124
133
134
+ - (void )chooseServer : (id )sender {
135
+ NSInteger tag = [sender tag ];
136
+ Configuration *configuration = [ProfileManager configuration ];
137
+ if (tag == -1 || tag < configuration.profiles .count ) {
138
+ configuration.current = tag;
139
+ }
140
+ [ProfileManager saveConfiguration: configuration];
141
+ [self updateServersMenu ];
142
+ }
143
+
144
+ - (void )updateServersMenu {
145
+ Configuration *configuration = [ProfileManager configuration ];
146
+ [serversMenu removeAllItems ];
147
+ int i = 0 ;
148
+ NSMenuItem *publicItem = [[NSMenuItem alloc ] initWithTitle: _L (Public Server) action: @selector (chooseServer: ) keyEquivalent: @" " ];
149
+ publicItem.tag = -1 ;
150
+ if (-1 == configuration.current ) {
151
+ [publicItem setState: 1 ];
152
+ }
153
+ [serversMenu addItem: publicItem];
154
+ for (Profile *profile in configuration.profiles ) {
155
+ NSMenuItem *item = [[NSMenuItem alloc ] initWithTitle: profile.server action: @selector (chooseServer: ) keyEquivalent: @" " ];
156
+ item.tag = i;
157
+ if (i == configuration.current ) {
158
+ [item setState: 1 ];
159
+ }
160
+ [serversMenu addItem: item];
161
+ i++;
162
+ }
163
+ [serversMenu addItem: [NSMenuItem separatorItem ]];
164
+ [serversMenu addItemWithTitle: _L (Open Server Preferences...) action: @selector (showConfigWindow ) keyEquivalent: @" " ];
165
+ }
166
+
125
167
- (void )updateMenu {
126
168
if (isRunning) {
127
169
statusMenuItem.title = _L (Shadowsocks: On);
@@ -151,7 +193,7 @@ - (void)updateMenu {
151
193
[qrCodeMenuItem setTarget: self ];
152
194
[qrCodeMenuItem setAction: @selector (showQRCode )];
153
195
}
154
-
196
+ [ self updateServersMenu ];
155
197
}
156
198
157
199
void onPACChange (
0 commit comments