diff --git a/Crashlytics.framework/Versions/A/Crashlytics b/Crashlytics.framework/Versions/A/Crashlytics index f286bd1..b0a896a 100644 Binary files a/Crashlytics.framework/Versions/A/Crashlytics and b/Crashlytics.framework/Versions/A/Crashlytics differ diff --git a/Crashlytics.framework/Versions/A/Resources/Info.plist b/Crashlytics.framework/Versions/A/Resources/Info.plist index 608be39..a97463c 100644 --- a/Crashlytics.framework/Versions/A/Resources/Info.plist +++ b/Crashlytics.framework/Versions/A/Resources/Info.plist @@ -15,13 +15,13 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.2.0 + 2.2.1 CFBundleSupportedPlatforms iPhoneOS CFBundleVersion - 33 + 35 DTPlatformName iphoneos MinimumOSVersion diff --git a/Crashlytics.framework/run b/Crashlytics.framework/run index d3ddf05..ca71288 100755 Binary files a/Crashlytics.framework/run and b/Crashlytics.framework/run differ diff --git a/ShadowWeb/zh-Hans.lproj/Localizable.strings b/ShadowWeb/zh-Hans.lproj/Localizable.strings index 8e139ab..b3f6abc 100644 --- a/ShadowWeb/zh-Hans.lproj/Localizable.strings +++ b/ShadowWeb/zh-Hans.lproj/Localizable.strings @@ -47,6 +47,7 @@ "Turn Shadowsocks Off" = "关闭 Shadowsocks"; "Open Server Preferences..." = "打开服务器设定..."; "Please fill in the blanks." = "请填写以下内容。"; -"Show Logs..." = "显示日志.."; +"Show Logs..." = "显示日志..."; +"Edit PAC..." = "编辑 PAC..."; "Quit" = "退出"; "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"; \ No newline at end of file diff --git a/ShadowsocksX/SWBAppDelegate.m b/ShadowsocksX/SWBAppDelegate.m index 27ed8e3..4f112fb 100644 --- a/ShadowsocksX/SWBAppDelegate.m +++ b/ShadowsocksX/SWBAppDelegate.m @@ -20,8 +20,14 @@ NSMenuItem *statusMenuItem; NSMenuItem *enableMenuItem; BOOL isRunning; + NSData *originalPACData; + FSEventStreamRef fsEventStream; + NSString *configPath; + NSString *PACPath; } +static SWBAppDelegate *appDelegate; + - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL]; @@ -31,10 +37,10 @@ [self runProxy]; }); - NSData *pacData = [[NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"proxy" withExtension:@"pac.gz"]] gunzippedData]; + originalPACData = [[NSData dataWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"proxy" withExtension:@"pac.gz"]] gunzippedData]; GCDWebServer *webServer = [[GCDWebServer alloc] init]; [webServer addHandlerForMethod:@"GET" path:@"/proxy.pac" requestClass:[GCDWebServerRequest class] processBlock:^GCDWebServerResponse *(GCDWebServerRequest *request) { - return [GCDWebServerDataResponse responseWithData:pacData contentType:@"application/x-ns-proxy-autoconfig"]; + return [GCDWebServerDataResponse responseWithData:[self PACData] contentType:@"application/x-ns-proxy-autoconfig"]; } ]; @@ -53,6 +59,7 @@ [menu addItem:enableMenuItem]; [menu addItem:[NSMenuItem separatorItem]]; [menu addItemWithTitle:_L(Open Server Preferences...) action:@selector(showConfigWindow) keyEquivalent:@""]; + [menu addItemWithTitle:_L(Edit PAC...) action:@selector(editPAC) keyEquivalent:@""]; [menu addItemWithTitle:_L(Show Logs...) action:@selector(showLogs) keyEquivalent:@""]; [menu addItemWithTitle:_L(Help) action:@selector(showHelp) keyEquivalent:@""]; [menu addItem:[NSMenuItem separatorItem]]; @@ -64,6 +71,19 @@ configWindowController = [[SWBConfigWindowController alloc] initWithWindowNibName:@"ConfigWindow"]; [self updateMenu]; + + configPath = [NSString stringWithFormat:@"%@/%@", NSHomeDirectory(), @".ShadowsocksX"]; + PACPath = [NSString stringWithFormat:@"%@/%@", configPath, @"gfwlist.js"]; + [self monitorPAC:configPath]; + appDelegate = self; +} + +- (NSData *)PACData { + if ([[NSFileManager defaultManager] fileExistsAtPath:PACPath]) { + return [NSData dataWithContentsOfFile:PACPath]; + } else { + return originalPACData; + } } - (void)toggleRunning { @@ -86,6 +106,60 @@ } } +void onPACChange( + ConstFSEventStreamRef streamRef, + void *clientCallBackInfo, + size_t numEvents, + void *eventPaths, + const FSEventStreamEventFlags eventFlags[], + const FSEventStreamEventId eventIds[]) +{ + [appDelegate reloadPAC]; +} + +- (void)reloadPAC { + if (isRunning) { + [self toggleSystemProxy:NO]; + [self toggleSystemProxy:YES]; + } +} + +- (void)monitorPAC:(NSString *)pacPath { + if (fsEventStream) { + return; + } + CFStringRef mypath = (__bridge CFStringRef)(pacPath); + CFArrayRef pathsToWatch = CFArrayCreate(NULL, (const void **)&mypath, 1, NULL); + void *callbackInfo = NULL; // could put stream-specific data here. + CFAbsoluteTime latency = 3.0; /* Latency in seconds */ + + /* Create the stream, passing in a callback */ + fsEventStream = FSEventStreamCreate(NULL, + &onPACChange, + callbackInfo, + pathsToWatch, + kFSEventStreamEventIdSinceNow, /* Or a previous event ID */ + latency, + kFSEventStreamCreateFlagNone /* Flags explained in reference */ + ); + FSEventStreamScheduleWithRunLoop(fsEventStream, [[NSRunLoop mainRunLoop] getCFRunLoop], (__bridge CFStringRef)NSDefaultRunLoopMode); + FSEventStreamStart(fsEventStream); +} + +- (void)editPAC { + + if (![[NSFileManager defaultManager] fileExistsAtPath:PACPath]) { + NSError *error = nil; + [[NSFileManager defaultManager] createDirectoryAtPath:configPath withIntermediateDirectories:NO attributes:nil error:&error]; + // TODO check error + [originalPACData writeToFile:PACPath atomically:YES]; + } + [self monitorPAC:configPath]; + + NSArray *fileURLs = @[[NSURL fileURLWithPath:PACPath]]; + [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs]; +} + - (void)showLogs { [[NSWorkspace sharedWorkspace] launchApplication:@"/Applications/Utilities/Console.app"]; } diff --git a/ShadowsocksX/ShadowsocksX-Info.plist b/ShadowsocksX/ShadowsocksX-Info.plist index 8cd8151..f4c4c18 100644 --- a/ShadowsocksX/ShadowsocksX-Info.plist +++ b/ShadowsocksX/ShadowsocksX-Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0.7 + 1.0.8 CFBundleSignature ???? CFBundleURLTypes @@ -36,7 +36,7 @@ CFBundleVersion - 1.0.7 + 1.0.8 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion