From 3b7b4635887c3a75ca2f14dbc73be74413102707 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Fri, 6 Mar 2015 18:48:21 +0800 Subject: [PATCH] add UI for user rule --- ShadowWeb/zh-Hans.lproj/Localizable.strings | 1 + ShadowsocksX/SWBAppDelegate.m | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ShadowWeb/zh-Hans.lproj/Localizable.strings b/ShadowWeb/zh-Hans.lproj/Localizable.strings index 32bbd9fa..b8f485dc 100644 --- a/ShadowWeb/zh-Hans.lproj/Localizable.strings +++ b/ShadowWeb/zh-Hans.lproj/Localizable.strings @@ -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..." = "显示二维码..."; diff --git a/ShadowsocksX/SWBAppDelegate.m b/ShadowsocksX/SWBAppDelegate.m index 43d9c45e..5f21a5e2 100644 --- a/ShadowsocksX/SWBAppDelegate.m +++ b/ShadowsocksX/SWBAppDelegate.m @@ -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) {