Skip to content

Commit

Permalink
update version: 1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yanue committed Dec 2, 2019
1 parent e1d4fb0 commit 661d662
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 81 deletions.
4 changes: 2 additions & 2 deletions V2rayU/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class AppDelegate: NSObject, NSApplicationDelegate {
UserDefaults.set(forKey: .v2rayCoreVersion, value: V2rayCore.version)
}
if UserDefaults.get(forKey: .autoCheckVersion) == nil {
UserDefaults.setBool(forKey: .v2rayCoreVersion, value: true)
UserDefaults.setBool(forKey: .autoCheckVersion, value: true)
}
if UserDefaults.get(forKey: .autoLaunch) == nil {
SMLoginItemSetEnabled(launcherAppIdentifier as CFString, true)
UserDefaults.setBool(forKey: .v2rayCoreVersion, value: true)
UserDefaults.setBool(forKey: .autoLaunch, value: true)
}
if UserDefaults.get(forKey: .runMode) == nil {
UserDefaults.set(forKey: .runMode, value: RunMode.manual.rawValue)
Expand Down
29 changes: 11 additions & 18 deletions V2rayU/Base.lproj/PreferencePac.xib
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="PreferencePacViewController" customModule="V2rayU" customModuleProvider="target">
<connections>
<outlet property="gfwPacListUrl" destination="zr7-bd-EAE" id="Bb8-mK-cmI"/>
<outlet property="gfwPacListUrl" destination="Uoq-RS-CX7" id="XMz-bH-GHS"/>
<outlet property="tips" destination="D20-Eu-3f8" id="Fbo-j7-S8j"/>
<outlet property="userRulesView" destination="TVW-6s-N8F" id="f19-R4-Xf5"/>
<outlet property="view" destination="bXz-rK-jao" id="xYY-dt-fo2"/>
Expand All @@ -32,22 +32,6 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" allowsCharacterPickerTouchBarItem="YES" translatesAutoresizingMaskIntoConstraints="NO" id="zr7-bd-EAE">
<rect key="frame" x="20" y="20" width="420" height="45"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" state="on" borderStyle="bezel" alignment="left" drawsBackground="YES" id="RXK-Mf-gKW">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
<connections>
<binding destination="-2" name="displayPatternValue1" keyPath="self.gfwPacListUrl" id="Mxg-5a-CDL">
<dictionary key="options">
<string key="NSDisplayPattern">%{value1}@</string>
</dictionary>
</binding>
</connections>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3Cg-gM-BHl">
<rect key="frame" x="326" y="70" width="120" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
Expand All @@ -63,11 +47,20 @@
<rect key="frame" x="98" y="99" width="251" height="17"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" lineBreakMode="clipping" alignment="center" id="NE5-JO-Q74">
<font key="font" metaFont="system" size="12"/>
<font key="font" metaFont="label" size="12"/>
<color key="textColor" name="systemRedColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Uoq-RS-CX7">
<rect key="frame" x="20" y="20" width="420" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" id="Mzi-Yb-HhA">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</customView>
<customView fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="8NJ-ru-j3U">
Expand Down
4 changes: 2 additions & 2 deletions V2rayU/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<string>1.5.1</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand All @@ -34,7 +34,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(MARKETING_VERSION)</string>
<string>1.5.1</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion V2rayU/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class MenuController: NSObject, NSMenuDelegate {
// pac mode
if runMode == .pac {
// generate pac file
_ = GeneratePACFile()
_ = GeneratePACFile(rewrite: false)
}

V2rayLaunch.setSystemProxy(mode: runMode)
Expand Down
20 changes: 10 additions & 10 deletions V2rayU/Preference/PreferenceAdvance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class PreferenceAdvanceViewController: NSViewController, PreferencePane {
@IBOutlet weak var logLevel: NSPopUpButton!
@IBOutlet weak var dnsServers: NSTextField!
@IBOutlet weak var tips: NSTextField!

override var nibName: NSNib.Name? {
return "PreferenceAdvance"
}
Expand All @@ -51,7 +51,7 @@ final class PreferenceAdvanceViewController: NSViewController, PreferencePane {
let muxConcurrent = UserDefaults.get(forKey: .muxConcurrent) ?? "8"

// select item
print("host",localSockHost,localHttpHost)
print("host", localSockHost, localHttpHost)
self.logLevel.selectItem(withTitle: UserDefaults.get(forKey: .v2rayLogLevel) ?? "info")

self.enableUdp.state = enableUdpState ? .on : .off
Expand Down Expand Up @@ -81,7 +81,7 @@ final class PreferenceAdvanceViewController: NSViewController, PreferencePane {

let dnsServersVal = self.dnsServers.stringValue
let muxConcurrentVal = self.muxConcurrent.intValue

// save
UserDefaults.setBool(forKey: .enableUdp, value: enableUdpVal)
UserDefaults.setBool(forKey: .enableMux, value: enableMuxVal)
Expand All @@ -93,12 +93,12 @@ final class PreferenceAdvanceViewController: NSViewController, PreferencePane {
UserDefaults.set(forKey: .localPacPort, value: pacPortVal)
UserDefaults.set(forKey: .dnsServers, value: dnsServersVal)
UserDefaults.set(forKey: .muxConcurrent, value: String(muxConcurrentVal))
print("self.sockHost.stringValue",self.sockHost.stringValue)
print("self.sockHost.stringValue", self.sockHost.stringValue)

var logLevelName = "info"

if let logLevelVal = self.logLevel.selectedItem {
print("logLevelVal",logLevelVal)
print("logLevelVal", logLevelVal)
logLevelName = logLevelVal.title
UserDefaults.set(forKey: .v2rayLogLevel, value: logLevelVal.title)
}
Expand All @@ -125,14 +125,14 @@ final class PreferenceAdvanceViewController: NSViewController, PreferencePane {

// set HttpServerPacPort
HttpServerPacPort = pacPortVal
PACUrl = "http://127.0.0.1:" + String(HttpServerPacPort) + "/pac/proxy.pac"
PACUrl = "http://127.0.0.1:" + String(HttpServerPacPort) + "/pac/proxy.js"

_ = GeneratePACFile()
_ = GeneratePACFile(rewrite: true)
// restart pac http server
V2rayLaunch.startHttpServer()

self.tips.stringValue = "save success."

DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
// your code here
self.tips.stringValue = ""
Expand Down
91 changes: 48 additions & 43 deletions V2rayU/Preference/PreferencePac.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import Alamofire

let PACRulesDirPath = AppResourcesPath + "/pac/"
let PACUserRuleFilePath = PACRulesDirPath + "user-rule.txt"
let PACFilePath = PACRulesDirPath + "proxy.pac"
var PACUrl = "http://127.0.0.1:" + String(HttpServerPacPort) + "/pac/proxy.pac"
let PACFilePath = PACRulesDirPath + "proxy.js"
var PACUrl = "http://127.0.0.1:" + String(HttpServerPacPort) + "/pac/proxy.js"
let PACAbpFile = PACRulesDirPath + "abp.js"
let GFWListFilePath = PACRulesDirPath + "gfwlist.txt"
let GFWListURL = "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"
Expand All @@ -40,9 +40,9 @@ final class PreferencePacViewController: NSViewController, PreferencePane {

let gfwUrl = UserDefaults.get(forKey: .gfwPacListUrl)
if gfwUrl != nil {
gfwPacListUrl.stringValue = gfwUrl!
self.gfwPacListUrl.stringValue = gfwUrl!
} else {
gfwPacListUrl.stringValue = GFWListURL
self.gfwPacListUrl.stringValue = GFWListURL
}

// read userRules from UserDefaults
Expand All @@ -66,6 +66,7 @@ final class PreferencePacViewController: NSViewController, PreferencePane {
}

@IBAction func viewPacFile(_ sender: Any) {
print("viewPacFile PACUrl", PACUrl)
guard let url = URL(string: PACUrl) else {
return
}
Expand All @@ -82,9 +83,9 @@ final class PreferencePacViewController: NSViewController, PreferencePane {

try str.data(using: String.Encoding.utf8)?.write(to: URL(fileURLWithPath: PACUserRuleFilePath), options: .atomic)

UpdatePACFromGFWList()
UpdatePACFromGFWList(gfwPacListUrl: self.gfwPacListUrl.stringValue)

if GeneratePACFile() {
if GeneratePACFile(rewrite: true) {
// Popup a user notification
self.tips.stringValue = "PAC has been updated by User Rules."
} else {
Expand All @@ -99,17 +100,56 @@ final class PreferencePacViewController: NSViewController, PreferencePane {
}
}
}

func UpdatePACFromGFWList(gfwPacListUrl: String) {
// Make the dir if rulesDirPath is not exesited.
if !FileManager.default.fileExists(atPath: PACRulesDirPath) {
do {
try FileManager.default.createDirectory(atPath: PACRulesDirPath, withIntermediateDirectories: true, attributes: nil)
} catch {
}
}

Alamofire.request(gfwPacListUrl).responseString {
response in
if response.result.isSuccess {
if let v = response.result.value {
do {
try v.write(toFile: GFWListFilePath, atomically: true, encoding: String.Encoding.utf8)

if GeneratePACFile(rewrite: true) {
// Popup a user notification
self.tips.stringValue = "PAC has been updated by latest GFW List."
}
} catch {
// Popup a user notification
self.tips.stringValue = "Failed to Write latest GFW List."
}
}
} else {
// Popup a user notification
self.tips.stringValue = "Failed to download latest GFW List."
}
}
}
}

// Because of LocalSocks5.ListenPort may be changed
func GeneratePACFile() -> Bool {
func GeneratePACFile(rewrite: Bool) -> Bool {
let socks5Address = "127.0.0.1"

let sockPort = UserDefaults.get(forKey: .localSockPort) ?? "1080"

// permission
_ = shell(launchPath: "/bin/bash", arguments: ["-c", "cd " + AppResourcesPath + " && /bin/chmod -R 755 ./pac"])

// if PACFilePath exist and not need rewrite
if (!rewrite && FileManager.default.fileExists(atPath: PACFilePath)) {
return true
}

print("GeneratePACFile rewrite", sockPort)

do {
let gfwlist = try String(contentsOfFile: GFWListFilePath, encoding: String.Encoding.utf8)
if let data = Data(base64Encoded: gfwlist, options: .ignoreUnknownCharacters) {
Expand Down Expand Up @@ -162,6 +202,7 @@ func GeneratePACFile() -> Bool {
} else {
jsStr = jsStr!.replacingOccurrences(of: "__SOCKS5ADDR__", with: socks5Address)
}
print("PACFilePath", PACFilePath)

// Write the pac js to file.
try jsStr!.data(using: String.Encoding.utf8)?.write(to: URL(fileURLWithPath: PACFilePath), options: .atomic)
Expand All @@ -176,39 +217,3 @@ func GeneratePACFile() -> Bool {
}
return false
}

func UpdatePACFromGFWList() {
// Make the dir if rulesDirPath is not exesited.
if !FileManager.default.fileExists(atPath: PACRulesDirPath) {
do {
try FileManager.default.createDirectory(atPath: PACRulesDirPath
, withIntermediateDirectories: true, attributes: nil)
} catch {
}
}

Alamofire.request(GFWListURL).responseString {
response in
if response.result.isSuccess {
if let v = response.result.value {
do {
try v.write(toFile: GFWListFilePath, atomically: true, encoding: String.Encoding.utf8)

if GeneratePACFile() {
// Popup a user notification
let notification = NSUserNotification()
notification.title = "PAC has been updated by latest GFW List."
NSUserNotificationCenter.default.deliver(notification)
}
} catch {

}
}
} else {
// Popup a user notification
let notification = NSUserNotification()
notification.title = "Failed to download latest GFW List."
NSUserNotificationCenter.default.deliver(notification)
}
}
}
7 changes: 4 additions & 3 deletions V2rayU/Scanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class ImportUri {
vmessItem.port = vmess.port
var user = V2rayOutboundVMessUser()
if id.count > 0 {
vmess.id = id
// vmess.id = id
}
user.id = vmess.id
user.alterId = vmess.alterId
Expand Down Expand Up @@ -370,7 +370,7 @@ class VmessUri {
self.error = "error decode Str"
return
}

print("decodeStr", decodeStr)
// main
var uuid_ = ""
var host_ = ""
Expand All @@ -391,6 +391,7 @@ class VmessUri {
self.address = host_port[0]
self.port = Int(host_port[1]) ?? 0
}
print("VmessUri self",self)

// params
let params = paramsStr.components(separatedBy: "&")
Expand Down Expand Up @@ -431,7 +432,7 @@ class VmessUri {
self.downlinkCapacity = Int(param[1]) ?? 20
break
case "remark":
self.remark = param[1]
self.remark = param[1].urlDecoded()
break
default:
break
Expand Down
12 changes: 12 additions & 0 deletions V2rayU/Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ extension String {
let result = urlTest.evaluate(with: self)
return result
}

//将原始的url编码为合法的url
func urlEncoded() -> String {
let encodeUrlString = self.addingPercentEncoding(withAllowedCharacters:
.urlQueryAllowed)
return encodeUrlString ?? self
}

//将编码后的url转换回原始的url
func urlDecoded() -> String {
return self.removingPercentEncoding ?? self
}
}

// run custom shell
Expand Down
4 changes: 2 additions & 2 deletions V2rayU/V2rayLaunch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ class V2rayLaunch: NSObject {
}
}

_ = GeneratePACFile()
_ = GeneratePACFile(rewrite: false)

let pacPort = UserDefaults.get(forKey: .localPacPort) ?? "11085"

webServer.addGETHandler(forBasePath: "/", directoryPath: AppResourcesPath, indexFilename: nil, cacheAge: 3600, allowRangeRequests: true)
webServer.addGETHandler(forBasePath: "/", directoryPath: AppResourcesPath, indexFilename: nil, cacheAge: 0, allowRangeRequests: true)

do {
try webServer.start(options: [
Expand Down

0 comments on commit 661d662

Please sign in to comment.