Permalink
Browse files

add UI for user rule

  • Loading branch information...
1 parent 9c10e72 commit 3b7b4635887c3a75ca2f14dbc73be74413102707 @clowwindy clowwindy committed Mar 6, 2015
Showing with 20 additions and 1 deletion.
  1. +1 −0 ShadowWeb/zh-Hans.lproj/Localizable.strings
  2. +19 −1 ShadowsocksX/SWBAppDelegate.m
@@ -53,6 +53,7 @@
"Please fill in the blanks." = "请填写以下内容。";
"Show Logs..." = "显示日志...";
"Edit PAC for Auto Proxy Mode..." = "编辑自动模式的 PAC...";
+"Edit User Rule for GFWList..." = "编辑 GFWList 的用户规则...";
"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";
"Show QR Code..." = "显示二维码...";
@@ -97,8 +97,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[menu addItem:[NSMenuItem separatorItem]];
[menu addItemWithTitle:_L(Edit PAC for Auto Proxy Mode...) action:@selector(editPAC) keyEquivalent:@""];
[menu addItemWithTitle:_L(Update PAC from GFWList) action:@selector(updatePACFromGFWList) keyEquivalent:@""];
- qrCodeMenuItem = [[NSMenuItem alloc] initWithTitle:_L(Show QR Code...) action:@selector(showQRCode) keyEquivalent:@""];
+ [menu addItemWithTitle:_L(Edit User Rule for GFWList...) action:@selector(editUserRule) keyEquivalent:@""];
+ [menu addItem:[NSMenuItem separatorItem]];
+ qrCodeMenuItem = [[NSMenuItem alloc] initWithTitle:_L(Generate QR Code...) action:@selector(showQRCode) keyEquivalent:@""];
[menu addItem:qrCodeMenuItem];
+ [menu addItem:[[NSMenuItem alloc] initWithTitle:_L(Scan QR Code from Screen...) action:@selector(scanQRCode) keyEquivalent:@""]];
+ [menu addItem:[NSMenuItem separatorItem]];
[menu addItemWithTitle:_L(Show Logs...) action:@selector(showLogs) keyEquivalent:@""];
[menu addItemWithTitle:_L(Help) action:@selector(showHelp) keyEquivalent:@""];
[menu addItem:[NSMenuItem separatorItem]];
@@ -264,6 +268,20 @@ - (void)editPAC {
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
}
+
+- (void)editUserRule {
+
+ if (![[NSFileManager defaultManager] fileExistsAtPath:userRulePath]) {
+ NSError *error = nil;
+ [[NSFileManager defaultManager] createDirectoryAtPath:configPath withIntermediateDirectories:NO attributes:nil error:&error];
+ // TODO check error
+ [@"! Put user rules line by line in this file.\n! See https://adblockplus.org/en/filter-cheatsheet\n" writeToFile:userRulePath atomically:YES encoding:NSUTF8StringEncoding error:&error];
+ }
+
+ NSArray *fileURLs = @[[NSURL fileURLWithPath:userRulePath]];
+ [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
+}
+
- (void)showQRCode {
NSURL *qrCodeURL = [ShadowsocksRunner generateSSURL];
if (qrCodeURL) {

0 comments on commit 3b7b463

Please sign in to comment.