Skip to content

Commit

Permalink
fix pac
Browse files Browse the repository at this point in the history
  • Loading branch information
yanue committed May 22, 2019
1 parent c7529cf commit 033e9da
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion V2rayU/ConfigWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ class ConfigWindowController: NSWindowController, NSWindowDelegate, NSTabViewDel
// edit item remark
V2rayServer.edit(rowIndex: self.serversTableView.selectedRow, url: uri)

if let importUri = ImportUri.importUri(uri: uri) {
if let importUri = ImportUri.importUri(uri: uri, checkExist: false) {
self.saveImport(importUri: importUri)
} else {
// download json file
Expand Down
12 changes: 1 addition & 11 deletions V2rayU/MainMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -404,17 +404,7 @@ class MenuController: NSObject, NSMenuDelegate {

@IBAction func copyExportCommand(_ sender: NSMenuItem) {
// Get the Http proxy config.
var httpPort = ""

let v2ray = V2rayServer.loadSelectedItem()

if v2ray != nil && v2ray!.isValid {
let cfg = V2rayConfig()
cfg.parseJson(jsonText: v2ray!.json)
httpPort = cfg.httpPort
} else {
return
}
let httpPort = UserDefaults.get(forKey: .localHttpPort) ?? "1087"

// Format an export string.
let command = "export http_proxy=http://127.0.0.1:\(httpPort);export https_proxy=http://127.0.0.1:\(httpPort);"
Expand Down
22 changes: 16 additions & 6 deletions V2rayU/Preference/PreferenceAdvance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ final class PreferenceAdvanceViewController: NSViewController, PreferencePane {
let muxConcurrent = UserDefaults.get(forKey: .muxConcurrent) ?? "8"

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

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

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


// save
UserDefaults.setBool(forKey: .enableUdp, value: enableUdpVal)
UserDefaults.setBool(forKey: .enableMux, value: enableMuxVal)
Expand All @@ -91,16 +91,22 @@ final class PreferenceAdvanceViewController: NSViewController, PreferencePane {

UserDefaults.set(forKey: .dnsServers, value: dnsServersVal)
UserDefaults.set(forKey: .muxConcurrent, value: String(muxConcurrentVal))
UserDefaults.set(forKey: .v2rayLogLevel, value: logLevelVal)


var logLevelName = "info"

if let logLevelVal = self.logLevel.selectedItem {
print("logLevelVal",logLevelVal)
logLevelName = logLevelVal.title
UserDefaults.set(forKey: .v2rayLogLevel, value: logLevelVal.title)
}
// replace
v2rayConfig.httpPort = httpPortVal
v2rayConfig.socksPort = sockPortVal
v2rayConfig.enableUdp = enableUdpVal
v2rayConfig.enableMux = enableMuxVal
v2rayConfig.dns = dnsServersVal
v2rayConfig.mux = Int(muxConcurrentVal)
v2rayConfig.logLevel = logLevelVal
v2rayConfig.logLevel = logLevelName

// set current server item and reload v2ray-core
let item = V2rayServer.loadSelectedItem()
Expand All @@ -115,6 +121,10 @@ final class PreferenceAdvanceViewController: NSViewController, PreferencePane {
}

// set HttpServerPacPort
HttpServerPacPort = Int(pacPortVal) ?? 1085
HttpServerPacPort = pacPortVal
PACUrl = "http://127.0.0.1:" + String(HttpServerPacPort) + "/pac/pac.js"
GeneratePACFile()
// generate plist
V2rayLaunch.generateLaunchAgentPlist()
}
}
2 changes: 1 addition & 1 deletion V2rayU/Preference/PreferencePac.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Alamofire
let PACRulesDirPath = AppResourcesPath + "/pac/"
let PACUserRuleFilePath = PACRulesDirPath + "user-rule.txt"
let PACFilePath = PACRulesDirPath + "pac.js"
let PACUrl = "http://127.0.0.1:" + String(HttpServerPacPort) + "/pac/pac.js"
var PACUrl = "http://127.0.0.1:" + String(HttpServerPacPort) + "/pac/pac.js"
let PACAbpFile = PACRulesDirPath + "abp.js"
let GFWListFilePath = PACRulesDirPath + "gfwlist.txt"
let GFWListURL = "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"
Expand Down
4 changes: 2 additions & 2 deletions V2rayU/Scanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class ImportUri {
var error: String = ""
var uri: String = ""

static func importUri(uri: String) -> ImportUri? {
if V2rayServer.exist(url: uri) {
static func importUri(uri: String,checkExist:Bool = true) -> ImportUri? {
if checkExist && V2rayServer.exist(url: uri) {
let importUri = ImportUri()
importUri.isValid = false
importUri.error = "Url already exists"
Expand Down
4 changes: 2 additions & 2 deletions V2rayU/V2rayLaunch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let launchHttpPlistFile = launchAgentDirPath + LAUNCH_HTTP_PLIST
let AppResourcesPath = Bundle.main.bundlePath + "/Contents/Resources"
let v2rayCorePath = AppResourcesPath + "/v2ray-core"
let v2rayCoreFile = v2rayCorePath + "/v2ray"
var HttpServerPacPort = 18765
var HttpServerPacPort = UserDefaults.get(forKey: .localPacPort) ?? "1085"

let cmdSh = AppResourcesPath + "/cmd.sh"
let cmdAppleScript = "do shell script \"" + cmdSh + "\" with administrator privileges"
Expand Down Expand Up @@ -58,7 +58,7 @@ class V2rayLaunch: NSObject {
dictAgent.write(toFile: launchAgentPlistFile, atomically: true)

// write http simple server plist
let httpArguments = ["/usr/bin/python", "-m", "SimpleHTTPServer", String(HttpServerPacPort)]
let httpArguments = ["/usr/bin/python", "-m", "SimpleHTTPServer", HttpServerPacPort]

let dictHttp: NSMutableDictionary = [
"Label": LAUNCH_HTTP_PLIST.replacingOccurrences(of: ".plist", with: ""),
Expand Down

0 comments on commit 033e9da

Please sign in to comment.