add edit user rule window

This commit is contained in:
bjzhou1990
2016-08-01 15:28:59 +08:00
parent 9e0c650e33
commit 995d43a41e
8 changed files with 185 additions and 31 deletions

View File

@ -52,6 +52,8 @@
9BEEF0751D04EF3E00FC52B3 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BEEF0731D04EF3E00FC52B3 /* PreferencesWindowController.swift */; };
9BEEF0781D04FE8A00FC52B3 /* LaunchAgentUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BEEF0771D04FE8A00FC52B3 /* LaunchAgentUtils.swift */; };
9BEEF07B1D05631500FC52B3 /* AdvPreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BEEF0791D05631500FC52B3 /* AdvPreferencesWindowController.swift */; };
C8E42A6C1D4F270A0074C7EA /* UserRulesController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8E42A6A1D4F270A0074C7EA /* UserRulesController.swift */; };
C8E42A6E1D4F2CAF0074C7EA /* UserRulesController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C8E42A701D4F2CAF0074C7EA /* UserRulesController.xib */; };
E0E57CCA7EB34B90F9D340F2 /* Pods_ShadowsocksX_NGTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 388120F062D7EB7DD0D8DDCA /* Pods_ShadowsocksX_NGTests.framework */; };
F0809FF1595BE2966343D3C7 /* libPods-proxy_conf_helper.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1E7783AEDB4A3BDDC9FF16AC /* libPods-proxy_conf_helper.a */; };
/* End PBXBuildFile section */
@ -159,6 +161,9 @@
9BEEF0771D04FE8A00FC52B3 /* LaunchAgentUtils.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LaunchAgentUtils.swift; sourceTree = "<group>"; };
9BEEF0791D05631500FC52B3 /* AdvPreferencesWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdvPreferencesWindowController.swift; sourceTree = "<group>"; };
B4E6A97CA843F3943524B686 /* Pods-proxy_conf_helper.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-proxy_conf_helper.debug.xcconfig"; path = "Pods/Target Support Files/Pods-proxy_conf_helper/Pods-proxy_conf_helper.debug.xcconfig"; sourceTree = "<group>"; };
C8E42A6A1D4F270A0074C7EA /* UserRulesController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserRulesController.swift; sourceTree = "<group>"; };
C8E42A6F1D4F2CAF0074C7EA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/UserRulesController.xib; sourceTree = "<group>"; };
C8E42A721D4F2CB10074C7EA /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/UserRulesController.strings"; sourceTree = "<group>"; };
E9E9FB3855DA55D0710EE7BD /* Pods-ShadowsocksX-NG.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShadowsocksX-NG.release.xcconfig"; path = "Pods/Target Support Files/Pods-ShadowsocksX-NG/Pods-ShadowsocksX-NG.release.xcconfig"; sourceTree = "<group>"; };
FE3237E9FB24D9B924A0E630 /* Pods-ShadowsocksX-NG.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ShadowsocksX-NG.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ShadowsocksX-NG/Pods-ShadowsocksX-NG.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -307,6 +312,8 @@
9B2491B91D0ACC3E003BBECC /* AdvPreferencesWindowController.xib */,
9BA04B241D24044D005AAD7F /* ProxyPreferencesController.swift */,
9B0D55481D2CC85400A4A8E2 /* ProxyPreferencesController.xib */,
C8E42A6A1D4F270A0074C7EA /* UserRulesController.swift */,
C8E42A701D4F2CAF0074C7EA /* UserRulesController.xib */,
);
name = UI;
sourceTree = "<group>";
@ -450,6 +457,7 @@
9B0D55461D2CC85400A4A8E2 /* ProxyPreferencesController.xib in Resources */,
9B2491B41D0ACC3A003BBECC /* PreferencesWindowController.xib in Resources */,
9B3FFF291D08A1DF0019A709 /* user-rule.txt in Resources */,
C8E42A6E1D4F2CAF0074C7EA /* UserRulesController.xib in Resources */,
9BEEF06A1D04D4D500FC52B3 /* start_ss_local.sh in Resources */,
9B3FFF391D08CF110019A709 /* qrcode.min.js in Resources */,
9B3FFF3A1D08CF110019A709 /* qrcode.htm in Resources */,
@ -625,6 +633,7 @@
9B0BFFE91D0460A70040E62B /* AppDelegate.swift in Sources */,
9BA04B231D23D5A5005AAD7F /* ProxyConfTool.m in Sources */,
9BEEF0781D04FE8A00FC52B3 /* LaunchAgentUtils.swift in Sources */,
C8E42A6C1D4F270A0074C7EA /* UserRulesController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -705,6 +714,15 @@
name = AdvPreferencesWindowController.xib;
sourceTree = "<group>";
};
C8E42A701D4F2CAF0074C7EA /* UserRulesController.xib */ = {
isa = PBXVariantGroup;
children = (
C8E42A6F1D4F2CAF0074C7EA /* Base */,
C8E42A721D4F2CB10074C7EA /* zh-Hans */,
);
name = UserRulesController.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */

View File

@ -16,7 +16,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
var preferencesWinCtrl: PreferencesWindowController!
var advPreferencesWinCtrl: AdvPreferencesWindowController!
var proxyPreferencesWinCtrl: ProxyPreferencesController!
var editUserRulesWinCtrl: UserRulesController!
var launchAtLoginController: LaunchAtLoginController = LaunchAtLoginController()
@IBOutlet weak var window: NSWindow!
@ -181,23 +182,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
}
@IBAction func editUserRulesForPAC(sender: NSMenuItem) {
let url = NSURL(fileURLWithPath: PACUserRuleFilePath)
NSWorkspace.sharedWorkspace().openURL(url)
}
@IBAction func applyUserRulesForPAC(sender: NSMenuItem) {
if GeneratePACFile() {
// Popup a user notification
let notification = NSUserNotification()
notification.title = "PAC has been updated by User Rules.".localized
NSUserNotificationCenter.defaultUserNotificationCenter()
.deliverNotification(notification)
} else {
let notification = NSUserNotification()
notification.title = "It's failed to update PAC by User Rules.".localized
NSUserNotificationCenter.defaultUserNotificationCenter()
.deliverNotification(notification)
if editUserRulesWinCtrl != nil {
editUserRulesWinCtrl.close()
}
let ctrl = UserRulesController(windowNibName: "UserRulesController")
editUserRulesWinCtrl = ctrl
ctrl.showWindow(self)
NSApp.activateIgnoringOtherApps(true)
ctrl.window?.makeKeyAndOrderFront(self)
}
@IBAction func showQRCodeForCurrentServer(sender: NSMenuItem) {

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
@ -76,12 +76,6 @@
<action selector="editUserRulesForPAC:" target="Voe-Tx-rLC" id="ZtK-2d-Pcl"/>
</connections>
</menuItem>
<menuItem title="Apply User Rules For PAC" id="6qf-cg-HXc">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="applyUserRulesForPAC:" target="Voe-Tx-rLC" id="iAp-Ae-0zV"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="bMX-qn-Qwi"/>
<menuItem title="Advance Proxy Preference..." id="sbx-yz-3lO">
<modifierMask key="keyEquivalentModifierMask"/>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
<capability name="box content view" minToolsVersion="7.0"/>
</dependencies>
<objects>
@ -25,7 +25,7 @@
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="423" y="365" width="544" height="330"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1057"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="544" height="330"/>
<autoresizingMask key="autoresizingMask"/>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="ProxyPreferencesController" customModule="ShadowsocksX_NG" customModuleProvider="target">
@ -16,7 +16,7 @@
<window title="Advance Proxy Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<rect key="contentRect" x="503" y="308" width="298" height="311"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="877"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1057"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="298" height="311"/>
<autoresizingMask key="autoresizingMask"/>

View File

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10116" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10116"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="UserRulesController" customModule="ShadowsocksX_NG" customModuleProvider="target">
<connections>
<outlet property="didCancel" destination="2bi-hW-nd9" id="wKx-Nb-7Kt"/>
<outlet property="userRulesView" destination="4yV-hS-knY" id="HF3-TH-oBY"/>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<window title="User Rules" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="F0z-JX-Cv5">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<rect key="contentRect" x="196" y="240" width="480" height="270"/>
<rect key="screenRect" x="0.0" y="0.0" width="1920" height="1057"/>
<view key="contentView" id="se5-gp-TjO">
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="N2T-OG-SO9">
<rect key="frame" x="385" y="13" width="81" height="32"/>
<buttonCell key="cell" type="push" title="OK" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="0Sc-cm-Vyu">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
DQ
</string>
<modifierMask key="keyEquivalentModifierMask" command="YES"/>
</buttonCell>
<connections>
<action selector="didOK:" target="-2" id="216-18-SFI"/>
</connections>
</button>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="2bi-hW-nd9">
<rect key="frame" x="304" y="13" width="81" height="32"/>
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="QAR-9i-kmv">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
<string key="keyEquivalent" base64-UTF8="YES">
Gw
</string>
</buttonCell>
<connections>
<action selector="didCancel:" target="-2" id="SFh-eD-YLV"/>
</connections>
</button>
<scrollView fixedFrame="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="J3L-MK-p8I">
<rect key="frame" x="20" y="61" width="440" height="189"/>
<clipView key="contentView" ambiguous="YES" id="fO6-Dc-ZUL">
<rect key="frame" x="1" y="1" width="423" height="187"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView ambiguous="YES" importsGraphics="NO" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" usesFontPanel="YES" verticallyResizable="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="4yV-hS-knY">
<rect key="frame" x="0.0" y="0.0" width="423" height="187"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="423" height="187"/>
<size key="maxSize" width="463" height="10000000"/>
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="423" height="187"/>
<size key="maxSize" width="463" height="10000000"/>
</textView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</clipView>
<scroller key="horizontalScroller" hidden="YES" verticalHuggingPriority="750" doubleValue="1" horizontal="YES" id="z0Z-PW-muW">
<rect key="frame" x="-100" y="-100" width="87" height="18"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
<scroller key="verticalScroller" verticalHuggingPriority="750" doubleValue="1" horizontal="NO" id="Us9-yx-gj4">
<rect key="frame" x="424" y="1" width="15" height="187"/>
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
</subviews>
</view>
<connections>
<outlet property="delegate" destination="-2" id="0bl-1N-AYu"/>
</connections>
<point key="canvasLocation" x="343" y="474"/>
</window>
</objects>
</document>

View File

@ -0,0 +1,53 @@
//
// UserRulesController.swift
// ShadowsocksX-NG
//
// Created by on 16/8/1.
// Copyright © 2016 qiuyuzhou. All rights reserved.
//
import Cocoa
class UserRulesController: NSWindowController {
@IBOutlet var userRulesView: NSTextView!
override func windowDidLoad() {
super.windowDidLoad()
let fileMgr = NSFileManager.defaultManager()
if !fileMgr.fileExistsAtPath(PACUserRuleFilePath) {
let src = NSBundle.mainBundle().pathForResource("user-rule", ofType: "txt")
try! fileMgr.copyItemAtPath(src!, toPath: PACUserRuleFilePath)
}
let str = try? String(contentsOfFile: PACUserRuleFilePath, encoding: NSUTF8StringEncoding)
userRulesView.string = str
}
@IBAction func didCancel(sender: AnyObject) {
window?.performClose(self)
}
@IBAction func didOK(sender: AnyObject) {
if let str = userRulesView.string {
do {
try str.dataUsingEncoding(NSUTF8StringEncoding)?.writeToFile(PACUserRuleFilePath, options: .DataWritingAtomic)
if GeneratePACFile() {
// Popup a user notification
let notification = NSUserNotification()
notification.title = "PAC has been updated by User Rules.".localized
NSUserNotificationCenter.defaultUserNotificationCenter()
.deliverNotification(notification)
} else {
let notification = NSUserNotification()
notification.title = "It's failed to update PAC by User Rules.".localized
NSUserNotificationCenter.defaultUserNotificationCenter()
.deliverNotification(notification)
}
} catch {}
}
window?.performClose(self)
}
}

View File

@ -0,0 +1,9 @@
/* Class = "NSButtonCell"; title = "OK"; ObjectID = "0Sc-cm-Vyu"; */
"0Sc-cm-Vyu.title" = "确定";
/* Class = "NSWindow"; title = "User Rules"; ObjectID = "F0z-JX-Cv5"; */
"F0z-JX-Cv5.title" = "用户规则";
/* Class = "NSButtonCell"; title = "Cancel"; ObjectID = "QAR-9i-kmv"; */
"QAR-9i-kmv.title" = "取消";