Skip to content

Commit 3b7b463

Browse files
committed
add UI for user rule
1 parent 9c10e72 commit 3b7b463

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

ShadowWeb/zh-Hans.lproj/Localizable.strings

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"Please fill in the blanks." = "请填写以下内容。";
5454
"Show Logs..." = "显示日志...";
5555
"Edit PAC for Auto Proxy Mode..." = "编辑自动模式的 PAC...";
56+
"Edit User Rule for GFWList..." = "编辑 GFWList 的用户规则...";
5657
"Quit" = "退出";
5758
"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";
5859
"Show QR Code..." = "显示二维码...";

ShadowsocksX/SWBAppDelegate.m

+19-1
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
9797
[menu addItem:[NSMenuItem separatorItem]];
9898
[menu addItemWithTitle:_L(Edit PAC for Auto Proxy Mode...) action:@selector(editPAC) keyEquivalent:@""];
9999
[menu addItemWithTitle:_L(Update PAC from GFWList) action:@selector(updatePACFromGFWList) keyEquivalent:@""];
100-
qrCodeMenuItem = [[NSMenuItem alloc] initWithTitle:_L(Show QR Code...) action:@selector(showQRCode) keyEquivalent:@""];
100+
[menu addItemWithTitle:_L(Edit User Rule for GFWList...) action:@selector(editUserRule) keyEquivalent:@""];
101+
[menu addItem:[NSMenuItem separatorItem]];
102+
qrCodeMenuItem = [[NSMenuItem alloc] initWithTitle:_L(Generate QR Code...) action:@selector(showQRCode) keyEquivalent:@""];
101103
[menu addItem:qrCodeMenuItem];
104+
[menu addItem:[[NSMenuItem alloc] initWithTitle:_L(Scan QR Code from Screen...) action:@selector(scanQRCode) keyEquivalent:@""]];
105+
[menu addItem:[NSMenuItem separatorItem]];
102106
[menu addItemWithTitle:_L(Show Logs...) action:@selector(showLogs) keyEquivalent:@""];
103107
[menu addItemWithTitle:_L(Help) action:@selector(showHelp) keyEquivalent:@""];
104108
[menu addItem:[NSMenuItem separatorItem]];
@@ -264,6 +268,20 @@ - (void)editPAC {
264268
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
265269
}
266270

271+
272+
- (void)editUserRule {
273+
274+
if (![[NSFileManager defaultManager] fileExistsAtPath:userRulePath]) {
275+
NSError *error = nil;
276+
[[NSFileManager defaultManager] createDirectoryAtPath:configPath withIntermediateDirectories:NO attributes:nil error:&error];
277+
// TODO check error
278+
[@"! 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];
279+
}
280+
281+
NSArray *fileURLs = @[[NSURL fileURLWithPath:userRulePath]];
282+
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs:fileURLs];
283+
}
284+
267285
- (void)showQRCode {
268286
NSURL *qrCodeURL = [ShadowsocksRunner generateSSURL];
269287
if (qrCodeURL) {

0 commit comments

Comments
 (0)