Skip to content

Commit 5d7651b

Browse files
committed
editable PAC
1 parent 41212ae commit 5d7651b

File tree

6 files changed

+82
-7
lines changed

6 files changed

+82
-7
lines changed
5.2 MB
Binary file not shown.

Crashlytics.framework/Versions/A/Resources/Info.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>2.2.0</string>
18+
<string>2.2.1</string>
1919
<key>CFBundleSupportedPlatforms</key>
2020
<array>
2121
<string>iPhoneOS</string>
2222
</array>
2323
<key>CFBundleVersion</key>
24-
<string>33</string>
24+
<string>35</string>
2525
<key>DTPlatformName</key>
2626
<string>iphoneos</string>
2727
<key>MinimumOSVersion</key>

Crashlytics.framework/run

3.97 KB
Binary file not shown.

ShadowWeb/zh-Hans.lproj/Localizable.strings

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"Turn Shadowsocks Off" = "关闭 Shadowsocks";
4848
"Open Server Preferences..." = "打开服务器设定...";
4949
"Please fill in the blanks." = "请填写以下内容。";
50-
"Show Logs..." = "显示日志..";
50+
"Show Logs..." = "显示日志...";
51+
"Edit PAC..." = "编辑 PAC...";
5152
"Quit" = "退出";
5253
"https://github.com/shadowsocks/shadowsocks-iOS/wiki/Shadowsocks-for-OSX-Help" = "https://github.com/shadowsocks/shadowsocks-iOS/wiki/Shadowsocks-for-OSX-%E5%B8%AE%E5%8A%A9";

ShadowsocksX/SWBAppDelegate.m

+76-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ @implementation SWBAppDelegate {
2020
NSMenuItem *statusMenuItem;
2121
NSMenuItem *enableMenuItem;
2222
BOOL isRunning;
23+
NSData *originalPACData;
24+
FSEventStreamRef fsEventStream;
25+
NSString *configPath;
26+
NSString *PACPath;
2327
}
2428

29+
static SWBAppDelegate *appDelegate;
30+
2531
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
2632
[[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
2733

@@ -31,10 +37,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
3137
[self runProxy];
3238
});
3339

34-
NSData *pacData = [[NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"proxy" withExtension:@"pac.gz"]] gunzippedData];
40+
originalPACData = [[NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"proxy" withExtension:@"pac.gz"]] gunzippedData];
3541
GCDWebServer *webServer = [[GCDWebServer alloc] init];
3642
[webServer addHandlerForMethod:@"GET" path:@"/proxy.pac" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse *(GCDWebServerRequest *request) {
37-
return [GCDWebServerDataResponse responseWithData:pacData contentType:@"application/x-ns-proxy-autoconfig"];
43+
return [GCDWebServerDataResponse responseWithData:[self PACData] contentType:@"application/x-ns-proxy-autoconfig"];
3844
}
3945
];
4046

@@ -53,6 +59,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
5359
[menu addItem:enableMenuItem];
5460
[menu addItem:[NSMenuItem separatorItem]];
5561
[menu addItemWithTitle:_L(Open Server Preferences...) action:@selector(showConfigWindow) keyEquivalent:@""];
62+
[menu addItemWithTitle:_L(Edit PAC...) action:@selector(editPAC) keyEquivalent:@""];
5663
[menu addItemWithTitle:_L(Show Logs...) action:@selector(showLogs) keyEquivalent:@""];
5764
[menu addItemWithTitle:_L(Help) action:@selector(showHelp) keyEquivalent:@""];
5865
[menu addItem:[NSMenuItem separatorItem]];
@@ -64,6 +71,19 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
6471
configWindowController = [[SWBConfigWindowController alloc] initWithWindowNibName:@"ConfigWindow"];
6572

6673
[self updateMenu];
74+
75+
configPath = [NSString stringWithFormat:@"%@/%@", NSHomeDirectory(), @".ShadowsocksX"];
76+
PACPath = [NSString stringWithFormat:@"%@/%@", configPath, @"gfwlist.js"];
77+
[self monitorPAC:configPath];
78+
appDelegate = self;
79+
}
80+
81+
- (NSData *)PACData {
82+
if ([[NSFileManager defaultManager] fileExistsAtPath:PACPath]) {
83+
return [NSData dataWithContentsOfFile:PACPath];
84+
} else {
85+
return originalPACData;
86+
}
6787
}
6888

6989
- (void)toggleRunning {
@@ -86,6 +106,60 @@ - (void)updateMenu {
86106
}
87107
}
88108

109+
void onPACChange(
110+
ConstFSEventStreamRef streamRef,
111+
void *clientCallBackInfo,
112+
size_t numEvents,
113+
void *eventPaths,
114+
const FSEventStreamEventFlags eventFlags[],
115+
const FSEventStreamEventId eventIds[])
116+
{
117+
[appDelegate reloadPAC];
118+
}
119+
120+
- (void)reloadPAC {
121+
if (isRunning) {
122+
[self toggleSystemProxy:NO];
123+
[self toggleSystemProxy:YES];
124+
}
125+
}
126+
127+
- (void)monitorPAC:(NSString *)pacPath {
128+
if (fsEventStream) {
129+
return;
130+
}
131+
CFStringRef mypath = (__bridge CFStringRef)(pacPath);
132+
CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&mypath, 1, NULL);
133+
void *callbackInfo = NULL; // could put stream-specific data here.
134+
CFAbsoluteTime latency = 3.0; /* Latency in seconds */
135+
136+
/* Create the stream, passing in a callback */
137+
fsEventStream = FSEventStreamCreate(NULL,
138+
&onPACChange,
139+
callbackInfo,
140+
pathsToWatch,
141+
kFSEventStreamEventIdSinceNow, /* Or a previous event ID */
142+
latency,
143+
kFSEventStreamCreateFlagNone /* Flags explained in reference */
144+
);
145+
FSEventStreamScheduleWithRunLoop(fsEventStream, [[NSRunLoop mainRunLoop] getCFRunLoop], (__bridge CFStringRef)NSDefaultRunLoopMode);
146+
FSEventStreamStart(fsEventStream);
147+
}
148+
149+
- (void)editPAC {
150+
151+
if (![[NSFileManager defaultManager] fileExistsAtPath:PACPath]) {
152+
NSError *error = nil;
153+
[[NSFileManager defaultManager] createDirectoryAtPath:configPath withIntermediateDirectories:NO attributes:nil error:&error];
154+
// TODO check error
155+
[originalPACData writeToFile:PACPath atomically:YES];
156+
}
157+
[self monitorPAC:configPath];
158+
159+
NSArray *fileURLs = @[[NSURL fileURLWithPath:PACPath]];
160+
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
161+
}
162+
89163
- (void)showLogs {
90164
[[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Console.app"];
91165
}

ShadowsocksX/ShadowsocksX-Info.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<key>CFBundlePackageType</key>
1818
<string>APPL</string>
1919
<key>CFBundleShortVersionString</key>
20-
<string>1.0.7</string>
20+
<string>1.0.8</string>
2121
<key>CFBundleSignature</key>
2222
<string>????</string>
2323
<key>CFBundleURLTypes</key>
@@ -36,7 +36,7 @@
3636
</dict>
3737
</array>
3838
<key>CFBundleVersion</key>
39-
<string>1.0.7</string>
39+
<string>1.0.8</string>
4040
<key>LSApplicationCategoryType</key>
4141
<string>public.app-category.utilities</string>
4242
<key>LSMinimumSystemVersion</key>

0 commit comments

Comments
 (0)