mirror of
https://github.com/zhigang1992/shadowsocks-iOS.git
synced 2026-01-12 22:52:17 +08:00
editable PAC
This commit is contained in:
BIN
Crashlytics.framework/Versions/A/Crashlytics
vendored
BIN
Crashlytics.framework/Versions/A/Crashlytics
vendored
Binary file not shown.
@@ -15,13 +15,13 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>2.2.0</string>
|
||||
<string>2.2.1</string>
|
||||
<key>CFBundleSupportedPlatforms</key>
|
||||
<array>
|
||||
<string>iPhoneOS</string>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>33</string>
|
||||
<string>35</string>
|
||||
<key>DTPlatformName</key>
|
||||
<string>iphoneos</string>
|
||||
<key>MinimumOSVersion</key>
|
||||
|
||||
BIN
Crashlytics.framework/run
vendored
BIN
Crashlytics.framework/run
vendored
Binary file not shown.
@@ -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";
|
||||
@@ -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"];
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0.7</string>
|
||||
<string>1.0.8</string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleURLTypes</key>
|
||||
@@ -36,7 +36,7 @@
|
||||
</dict>
|
||||
</array>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0.7</string>
|
||||
<string>1.0.8</string>
|
||||
<key>LSApplicationCategoryType</key>
|
||||
<string>public.app-category.utilities</string>
|
||||
<key>LSMinimumSystemVersion</key>
|
||||
|
||||
Reference in New Issue
Block a user