Skip to content

Commit

Permalink
add UI for user rule
Browse files Browse the repository at this point in the history
  • Loading branch information
clowwindy committed Mar 6, 2015
1 parent 9c10e72 commit 3b7b463
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions ShadowWeb/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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..." = "显示二维码...";
Expand Down
20 changes: 19 additions & 1 deletion ShadowsocksX/SWBAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3b7b463

Please sign in to comment.