mirror of
https://github.com/bolucat/Archive.git
synced 2025-12-24 13:28:37 +08:00
Update On Wed Jul 17 20:32:38 CEST 2024
This commit is contained in:
@@ -131,7 +131,6 @@
|
||||
665DC9BA22A542F90062337B /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
|
||||
6662C20A240EA782000AF6CD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = V2rayU/Base.lproj/PreferenceDns.xib; sourceTree = SOURCE_ROOT; };
|
||||
6662C20C240EA794000AF6CD /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "../zh-Hans.lproj/PreferenceDns.strings"; sourceTree = "<group>"; };
|
||||
6662C20D240EA797000AF6CD /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "../zh-HK.lproj/PreferenceDns.strings"; sourceTree = "<group>"; };
|
||||
667029D221AFB86E0079EF41 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/QrcodeWindow.xib; sourceTree = "<group>"; };
|
||||
66784AFB2170486D00AD307F /* Util.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Util.swift; sourceTree = "<group>"; };
|
||||
667ECE6F2A9A05EB009B00EC /* V2rayUTool */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = V2rayUTool; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@@ -139,15 +138,6 @@
|
||||
6683B1EA21C2AD1A004A1C5F /* pac */ = {isa = PBXFileReference; lastKnownFileType = folder; name = pac; path = Build/pac; sourceTree = "<group>"; };
|
||||
669468492C076C2800146109 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
|
||||
66973EB621797719001FEA1E /* ServiceManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ServiceManagement.framework; path = System/Library/Frameworks/ServiceManagement.framework; sourceTree = SDKROOT; };
|
||||
669A73A7233776B800807CF9 /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "zh-HK.lproj/MainMenu.strings"; sourceTree = "<group>"; };
|
||||
669A73A8233776B900807CF9 /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "zh-HK.lproj/ConfigWindow.strings"; sourceTree = "<group>"; };
|
||||
669A73A9233776B900807CF9 /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "zh-HK.lproj/QrcodeWindow.strings"; sourceTree = "<group>"; };
|
||||
669A73AA233776B900807CF9 /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "../zh-HK.lproj/PreferenceAbout.strings"; sourceTree = "<group>"; };
|
||||
669A73AB233776B900807CF9 /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "../zh-HK.lproj/PreferenceAdvance.strings"; sourceTree = "<group>"; };
|
||||
669A73AC233776B900807CF9 /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "../zh-HK.lproj/PreferenceGeneral.strings"; sourceTree = "<group>"; };
|
||||
669A73AD233776B900807CF9 /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "../zh-HK.lproj/PreferencePac.strings"; sourceTree = "<group>"; };
|
||||
669A73AE233776B900807CF9 /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "../zh-HK.lproj/PreferenceSubscription.strings"; sourceTree = "<group>"; };
|
||||
66A358662C39517B00914A25 /* zh-HK */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-HK"; path = "zh-HK.lproj/Localizable.strings"; sourceTree = "<group>"; };
|
||||
66A358672C39517F00914A25 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
|
||||
66A358682C3959AE00914A25 /* build.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = build.plist; sourceTree = "<group>"; };
|
||||
66A5CE4521706B5A009B08B2 /* Pods_V2rayU.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Pods_V2rayU.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
@@ -447,7 +437,6 @@
|
||||
en,
|
||||
Base,
|
||||
"zh-Hans",
|
||||
"zh-HK",
|
||||
);
|
||||
mainGroup = 664EB368216C9A5E00B6AE0D;
|
||||
productRefGroup = 664EB372216C9A5E00B6AE0D /* Products */;
|
||||
@@ -587,7 +576,6 @@
|
||||
isa = PBXVariantGroup;
|
||||
children = (
|
||||
66107B8922DEE445002FFB60 /* en */,
|
||||
66A358662C39517B00914A25 /* zh-HK */,
|
||||
66A358672C39517F00914A25 /* zh-Hans */,
|
||||
);
|
||||
name = Localizable.strings;
|
||||
@@ -615,7 +603,6 @@
|
||||
children = (
|
||||
664EB379216C9A5F00B6AE0D /* Base */,
|
||||
66F3029C22AAA0A600FCA4E2 /* zh-Hans */,
|
||||
669A73A7233776B800807CF9 /* zh-HK */,
|
||||
);
|
||||
name = MainMenu.xib;
|
||||
sourceTree = "<group>";
|
||||
@@ -625,7 +612,6 @@
|
||||
children = (
|
||||
6662C20A240EA782000AF6CD /* Base */,
|
||||
6662C20C240EA794000AF6CD /* zh-Hans */,
|
||||
6662C20D240EA797000AF6CD /* zh-HK */,
|
||||
);
|
||||
name = PreferenceDns.xib;
|
||||
sourceTree = "<group>";
|
||||
@@ -635,7 +621,6 @@
|
||||
children = (
|
||||
667029D221AFB86E0079EF41 /* Base */,
|
||||
66F3029E22AAA0A600FCA4E2 /* zh-Hans */,
|
||||
669A73A9233776B900807CF9 /* zh-HK */,
|
||||
);
|
||||
name = QrcodeWindow.xib;
|
||||
sourceTree = "<group>";
|
||||
@@ -645,7 +630,6 @@
|
||||
children = (
|
||||
66FEAD4F217EE14C009DECF9 /* Base */,
|
||||
66F3029D22AAA0A600FCA4E2 /* zh-Hans */,
|
||||
669A73A8233776B900807CF9 /* zh-HK */,
|
||||
);
|
||||
name = ConfigWindow.xib;
|
||||
sourceTree = "<group>";
|
||||
@@ -655,7 +639,6 @@
|
||||
children = (
|
||||
6D6DFD730D8572B1FCAB1FFE /* Base */,
|
||||
66F302A322AAA0A700FCA4E2 /* zh-Hans */,
|
||||
669A73AE233776B900807CF9 /* zh-HK */,
|
||||
);
|
||||
name = PreferenceSubscription.strings;
|
||||
sourceTree = "<group>";
|
||||
@@ -665,7 +648,6 @@
|
||||
children = (
|
||||
6D6DFE1CDFAD9828F2FDE1A5 /* Base */,
|
||||
66F302A022AAA0A600FCA4E2 /* zh-Hans */,
|
||||
669A73AB233776B900807CF9 /* zh-HK */,
|
||||
66C5B194240B58B8008A22CA /* en */,
|
||||
);
|
||||
name = PreferenceAdvance.strings;
|
||||
@@ -676,7 +658,6 @@
|
||||
children = (
|
||||
6D6DF3A2857899778B719CE1 /* Base */,
|
||||
66F3029F22AAA0A600FCA4E2 /* zh-Hans */,
|
||||
669A73AA233776B900807CF9 /* zh-HK */,
|
||||
);
|
||||
name = PreferenceAbout.strings;
|
||||
sourceTree = "<group>";
|
||||
@@ -686,7 +667,6 @@
|
||||
children = (
|
||||
6D6DF81E59907A2C7579BFE2 /* Base */,
|
||||
66F302A122AAA0A600FCA4E2 /* zh-Hans */,
|
||||
669A73AC233776B900807CF9 /* zh-HK */,
|
||||
662F0ACE2AB720C700884C17 /* en */,
|
||||
);
|
||||
name = PreferenceGeneral.strings;
|
||||
@@ -697,7 +677,6 @@
|
||||
children = (
|
||||
6D6DF181C5D472DBBB71B72A /* Base */,
|
||||
66F302A222AAA0A700FCA4E2 /* zh-Hans */,
|
||||
669A73AD233776B900807CF9 /* zh-HK */,
|
||||
);
|
||||
name = PreferencePac.strings;
|
||||
sourceTree = "<group>";
|
||||
@@ -843,6 +822,7 @@
|
||||
CURRENT_PROJECT_VERSION = 4.2.2;
|
||||
DEFINES_MODULE = YES;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
"DEVELOPMENT_TEAM[sdk=macosx*]" = "";
|
||||
ENABLE_ONLY_ACTIVE_RESOURCES = YES;
|
||||
INFOPLIST_FILE = V2rayU/Info.plist;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = V2rayU;
|
||||
@@ -856,6 +836,7 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.yanue.V2rayU;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
|
||||
SKIP_INSTALL = NO;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Common/V2rayU-Bridging-header.h";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
||||
@@ -878,6 +859,7 @@
|
||||
CURRENT_PROJECT_VERSION = 4.2.2;
|
||||
DEFINES_MODULE = YES;
|
||||
DEVELOPMENT_TEAM = "";
|
||||
"DEVELOPMENT_TEAM[sdk=macosx*]" = "";
|
||||
ENABLE_ONLY_ACTIVE_RESOURCES = YES;
|
||||
INFOPLIST_FILE = V2rayU/Info.plist;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = V2rayU;
|
||||
@@ -891,6 +873,7 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.yanue.V2rayU;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
"PROVISIONING_PROFILE_SPECIFIER[sdk=macosx*]" = "";
|
||||
SKIP_INSTALL = NO;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Common/V2rayU-Bridging-header.h";
|
||||
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
|
||||
|
||||
@@ -52,6 +52,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||
print("applicationDidFinishLaunching")
|
||||
FirebaseApp.configure()
|
||||
|
||||
// check installed
|
||||
V2rayLaunch.checkInstall()
|
||||
|
||||
// default settings
|
||||
self.checkDefault()
|
||||
|
||||
|
||||
@@ -36,8 +36,6 @@ class MenuController: NSObject, NSMenuDelegate {
|
||||
|
||||
// hide new version
|
||||
newVersionItem.isHidden = true
|
||||
|
||||
self.showRouting();
|
||||
|
||||
// windowWillClose Notification
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(configWindowWillClose(notification:)), name: NSWindow.willCloseNotification, object: nil)
|
||||
@@ -123,6 +121,7 @@ class MenuController: NSObject, NSMenuDelegate {
|
||||
configWindow.reloadData()
|
||||
}
|
||||
}
|
||||
self.showRouting();
|
||||
}
|
||||
|
||||
func showRouting() {
|
||||
|
||||
@@ -169,23 +169,11 @@ extension String {
|
||||
// shell("/bin/bash",["-c","cd ~ && ls -la"])
|
||||
func shell(launchPath: String, arguments: [String]) -> String? {
|
||||
do {
|
||||
let task = Process()
|
||||
task.launchPath = launchPath
|
||||
task.arguments = arguments
|
||||
|
||||
let pipe = Pipe()
|
||||
task.standardOutput = pipe
|
||||
task.launch()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
let output = String(data: data, encoding: String.Encoding.utf8)!
|
||||
|
||||
if output.count > 0 {
|
||||
// remove newline character.
|
||||
let lastIndex = output.index(before: output.endIndex)
|
||||
return String(output[output.startIndex ..< lastIndex])
|
||||
}
|
||||
let output = try runCommand(at: launchPath, with: arguments)
|
||||
return output
|
||||
} catch let error {
|
||||
print("shell error: \(error)")
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,17 +363,14 @@ func findFreePort() -> UInt16 {
|
||||
}
|
||||
|
||||
func isPortOpen(port: UInt16) -> Bool {
|
||||
let process = Process()
|
||||
process.launchPath = "/usr/sbin/lsof"
|
||||
process.arguments = ["-i", ":\(port)"]
|
||||
|
||||
let pipe = Pipe()
|
||||
process.standardOutput = pipe
|
||||
process.launch()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
let output = String(data: data, encoding: .utf8)
|
||||
return output?.contains("LISTEN") ?? false
|
||||
do {
|
||||
let output = try runCommand(at: "/usr/sbin/lsof", with: ["-i", ":\(port)"])
|
||||
NSLog("isPortOpen: \(output)")
|
||||
return output.contains("LISTEN")
|
||||
} catch let error {
|
||||
NSLog("isPortOpen: \(error)")
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getUsablePort(port: UInt16) -> (Bool, UInt16) {
|
||||
@@ -512,7 +497,6 @@ func getProxyUrlSessionConfigure(httpProxyPort: uint16) -> URLSessionConfigurati
|
||||
return configuration
|
||||
}
|
||||
|
||||
|
||||
func getHttpProxyPort() -> UInt16 {
|
||||
return UInt16(UserDefaults.get(forKey: .localHttpPort) ?? "1087") ?? 1087
|
||||
}
|
||||
@@ -525,7 +509,7 @@ func getPacPort() -> UInt16 {
|
||||
return UInt16(UserDefaults.get(forKey: .localPacPort) ?? "11085") ?? 11085
|
||||
}
|
||||
|
||||
func killAllPing(){
|
||||
func killAllPing() {
|
||||
let pskillCmd = "ps aux | grep v2ray | grep '.V2rayU/.config.' | awk '{print $2}' | xargs kill"
|
||||
let msg = shell(launchPath: "/bin/bash", arguments: ["-c", pskillCmd])
|
||||
NSLog("killAllPing: \(String(describing: msg))")
|
||||
@@ -534,17 +518,16 @@ func killAllPing(){
|
||||
NSLog("rmPingJson: \(String(describing: msg1))")
|
||||
}
|
||||
|
||||
func killSelfV2ray(){
|
||||
func killSelfV2ray() {
|
||||
let pskillCmd = "ps aux | grep v2ray | grep '.V2rayU/config.json' | awk '{print $2}' | xargs kill"
|
||||
let msg = shell(launchPath: "/bin/bash", arguments: ["-c", pskillCmd])
|
||||
NSLog("killSelfV2ray: \(String(describing: msg))")
|
||||
}
|
||||
|
||||
|
||||
func OpenLogs() {
|
||||
if !FileManager.default.fileExists(atPath: logFilePath) {
|
||||
let txt = ""
|
||||
try! txt.write(to: URL.init(fileURLWithPath: logFilePath), atomically: true, encoding: String.Encoding.utf8)
|
||||
try! txt.write(to: URL(fileURLWithPath: logFilePath), atomically: true, encoding: String.Encoding.utf8)
|
||||
}
|
||||
|
||||
let task = Process.launchedProcess(launchPath: "/usr/bin/open", arguments: [logFilePath])
|
||||
@@ -558,7 +541,7 @@ func OpenLogs() {
|
||||
|
||||
func ClearLogs() {
|
||||
let txt = ""
|
||||
try! txt.write(to: URL.init(fileURLWithPath: logFilePath), atomically: true, encoding: String.Encoding.utf8)
|
||||
try! txt.write(to: URL(fileURLWithPath: logFilePath), atomically: true, encoding: String.Encoding.utf8)
|
||||
}
|
||||
|
||||
func showDock(state: Bool) {
|
||||
@@ -580,3 +563,44 @@ func showDock(state: Bool) {
|
||||
func noticeTip(title: String = "", informativeText: String = "") {
|
||||
makeToast(message: title + " : " + informativeText)
|
||||
}
|
||||
|
||||
enum CommandExecutionError: Error {
|
||||
case fileNotFound(String)
|
||||
case insufficientPermissions(String)
|
||||
case unknown(Error)
|
||||
}
|
||||
|
||||
func runCommand(at path: String, with arguments: [String]) throws -> String {
|
||||
let process = Process()
|
||||
process.executableURL = URL(fileURLWithPath: path)
|
||||
process.arguments = arguments
|
||||
|
||||
let pipe = Pipe()
|
||||
process.standardOutput = pipe
|
||||
process.standardError = pipe
|
||||
|
||||
do {
|
||||
try process.run()
|
||||
process.waitUntilExit()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
if let output = String(data: data, encoding: .utf8) {
|
||||
return output
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
} catch {
|
||||
if (error as NSError).domain == NSCocoaErrorDomain {
|
||||
switch (error as NSError).code {
|
||||
case NSFileNoSuchFileError:
|
||||
throw CommandExecutionError.fileNotFound(path)
|
||||
case NSFileReadNoPermissionError:
|
||||
throw CommandExecutionError.insufficientPermissions(path)
|
||||
default:
|
||||
throw CommandExecutionError.unknown(error)
|
||||
}
|
||||
} else {
|
||||
throw CommandExecutionError.unknown(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import SystemConfiguration
|
||||
import Swifter
|
||||
import SystemConfiguration
|
||||
|
||||
let LAUNCH_AGENT_NAME = "yanue.v2rayu.v2ray-core"
|
||||
let AppResourcesPath = Bundle.main.bundlePath + "/Contents/Resources"
|
||||
@@ -28,17 +28,22 @@ enum RunMode: String {
|
||||
case backup
|
||||
case restore
|
||||
}
|
||||
// Create a Process instance with async launch
|
||||
var v2rayProcess = Process()
|
||||
|
||||
// 高版本macos执行NSAppleScript会出现授权失败
|
||||
func executeAppleScriptWithOsascript(script: String) {
|
||||
do {
|
||||
let output = try runCommand(at: "/usr/bin/osascript", with: ["-e", "do shell script \"" + script + "\" with administrator privileges"])
|
||||
print("executeAppleScript-Output: \(output)")
|
||||
} catch {
|
||||
print("executeAppleScript-Error: \(error)")
|
||||
let title = NSLocalizedString("InstallFailedTitle", comment: "")
|
||||
let toast = String(format: NSLocalizedString("InstallFailedMessage", comment: ""), error.localizedDescription, script)
|
||||
alertDialog(title: title, message: toast)
|
||||
}
|
||||
}
|
||||
|
||||
class V2rayLaunch: NSObject {
|
||||
|
||||
static func install() {
|
||||
V2rayLaunch.Stop()
|
||||
|
||||
// generate plist
|
||||
V2rayLaunch.generateLaunchAgentPlist()
|
||||
|
||||
static func checkInstall() {
|
||||
// Ensure launch agent directory is existed.
|
||||
let fileMgr = FileManager.default
|
||||
if !fileMgr.fileExists(atPath: AppHomePath) {
|
||||
@@ -60,7 +65,7 @@ class V2rayLaunch: NSObject {
|
||||
if !needRunInstall && !FileManager.default.isExecutableFile(atPath: v2rayUTool) {
|
||||
needRunInstall = true
|
||||
}
|
||||
if !needRunInstall && !FileManager.default.fileExists(atPath: v2rayCorePath+"/geoip.dat") {
|
||||
if !needRunInstall && !FileManager.default.fileExists(atPath: v2rayCorePath + "/geoip.dat") {
|
||||
NSLog("\(v2rayCorePath)/geoip.dat not exists,need install")
|
||||
needRunInstall = true
|
||||
}
|
||||
@@ -89,7 +94,7 @@ class V2rayLaunch: NSObject {
|
||||
let toolVersion = shell(launchPath: "/bin/bash", arguments: ["-c", "\(v2rayUTool) version"])
|
||||
NSLog("toolVersion - \(v2rayUTool): \(String(describing: toolVersion))")
|
||||
if toolVersion != nil {
|
||||
let _version = toolVersion ?? "" // old version
|
||||
let _version = toolVersion ?? "" // old version
|
||||
if _version.contains("Usage:") {
|
||||
NSLog("\(v2rayUTool) old version,need install")
|
||||
needRunInstall = true
|
||||
@@ -110,18 +115,36 @@ class V2rayLaunch: NSObject {
|
||||
return
|
||||
}
|
||||
|
||||
let doSh = "cd " + AppResourcesPath + " && sudo chown root:admin ./install.sh && sudo chmod a+rsx ./install.sh && ./install.sh"
|
||||
print("runAppleScript:" + doSh)
|
||||
var error: NSDictionary?
|
||||
if let scriptObject = NSAppleScript(source: "do shell script \"" + doSh + "\" with administrator privileges") {
|
||||
let output: NSAppleEventDescriptor = scriptObject.executeAndReturnError(&error)
|
||||
print(output.stringValue ?? "")
|
||||
if (error != nil) {
|
||||
print("error: \(String(describing: error))")
|
||||
showInstallAlert()
|
||||
|
||||
V2rayLaunch.Stop()
|
||||
|
||||
// generate plist
|
||||
V2rayLaunch.generateLaunchAgentPlist()
|
||||
}
|
||||
|
||||
static func showInstallAlert() {
|
||||
DispatchQueue.main.async {
|
||||
let alert = NSAlert()
|
||||
alert.messageText = NSLocalizedString("InstallAlertTitle", comment: "")
|
||||
alert.alertStyle = .warning
|
||||
alert.addButton(withTitle: NSLocalizedString("Install", comment: ""))
|
||||
alert.addButton(withTitle: NSLocalizedString("Quit", comment: ""))
|
||||
switch alert.runModal() {
|
||||
case .alertFirstButtonReturn:
|
||||
install()
|
||||
default:
|
||||
NSApp.terminate(self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func install() {
|
||||
let doSh = "cd " + AppResourcesPath + " && sudo chown root:admin ./install.sh && sudo chmod a+rsx ./install.sh && ./install.sh"
|
||||
// Create authorization reference for the user
|
||||
executeAppleScriptWithOsascript(script: doSh)
|
||||
}
|
||||
|
||||
static func generateLaunchAgentPlist() {
|
||||
let launchAgentDirPath = NSHomeDirectory() + "/Library/LaunchAgents/"
|
||||
let launchAgentPlistFile = launchAgentDirPath + LAUNCH_AGENT_NAME + ".plist"
|
||||
@@ -148,31 +171,30 @@ class V2rayLaunch: NSObject {
|
||||
|
||||
dictAgent.write(toFile: launchAgentPlistFile, atomically: true)
|
||||
// unload launch service(避免更改后无法生效)
|
||||
Process.launchedProcess(launchPath: "/bin/launchctl", arguments: ["unload", "-F", launchAgentPlistFile]).waitUntilExit()
|
||||
do {
|
||||
_ = try runCommand(at: "/bin/launchctl", with: ["unload", "-F", launchAgentPlistFile])
|
||||
} catch {
|
||||
}
|
||||
// load launch service
|
||||
let task = Process.launchedProcess(launchPath: "/bin/launchctl", arguments: ["load", "-wF", launchAgentPlistFile])
|
||||
task.waitUntilExit()
|
||||
if task.terminationStatus == 0 {
|
||||
NSLog("launchctl load \(launchAgentPlistFile) succeeded.")
|
||||
} else {
|
||||
NSLog("launchctl load \(launchAgentPlistFile) failed.")
|
||||
do {
|
||||
let output = try runCommand(at: "/bin/launchctl", with: ["load", "-wF", launchAgentPlistFile])
|
||||
NSLog("launchctl load \(launchAgentPlistFile) succeeded. \(output)")
|
||||
} catch let error {
|
||||
NSLog("launchctl load \(launchAgentPlistFile) failed. \(error)")
|
||||
}
|
||||
}
|
||||
|
||||
static func runAtStart(){
|
||||
static func runAtStart() {
|
||||
// clear not available
|
||||
V2rayServer.clearItems()
|
||||
|
||||
// install before launch
|
||||
V2rayLaunch.install()
|
||||
|
||||
// start http server
|
||||
startHttpServer()
|
||||
|
||||
// start or show servers
|
||||
if UserDefaults.getBool(forKey: .v2rayTurnOn) {
|
||||
// start and show servers
|
||||
self.startV2rayCore()
|
||||
startV2rayCore()
|
||||
} else {
|
||||
// show off status
|
||||
menuController.setStatusOff()
|
||||
@@ -198,7 +220,7 @@ class V2rayLaunch: NSObject {
|
||||
// set icon
|
||||
menuController.setStatusOn(mode: mode)
|
||||
|
||||
self.setSystemProxy(mode: mode)
|
||||
setSystemProxy(mode: mode)
|
||||
}
|
||||
|
||||
static func ToggleRunning() {
|
||||
@@ -211,9 +233,9 @@ class V2rayLaunch: NSObject {
|
||||
}
|
||||
}
|
||||
|
||||
static func restartV2ray(){
|
||||
static func restartV2ray() {
|
||||
// start
|
||||
self.startV2rayCore()
|
||||
startV2rayCore()
|
||||
}
|
||||
|
||||
// start v2ray core
|
||||
@@ -228,7 +250,7 @@ class V2rayLaunch: NSObject {
|
||||
let runMode = RunMode(rawValue: UserDefaults.get(forKey: .runMode) ?? "global") ?? .global
|
||||
|
||||
// create json file
|
||||
self.createJsonFile(item: v2ray)
|
||||
createJsonFile(item: v2ray)
|
||||
|
||||
// launch
|
||||
let started = V2rayLaunch.Start()
|
||||
@@ -238,7 +260,7 @@ class V2rayLaunch: NSObject {
|
||||
}
|
||||
|
||||
// set run mode
|
||||
self.setRunMode(mode: runMode)
|
||||
setRunMode(mode: runMode)
|
||||
|
||||
// reload menu
|
||||
menuController.showServers()
|
||||
@@ -259,7 +281,7 @@ class V2rayLaunch: NSObject {
|
||||
}
|
||||
|
||||
static func Start() -> Bool {
|
||||
self.Stop()
|
||||
Stop()
|
||||
|
||||
// close port
|
||||
let httpPort = getHttpProxyPort()
|
||||
@@ -273,6 +295,7 @@ class V2rayLaunch: NSObject {
|
||||
toast = "http port \(httpPort) has been used, please replace it from advance setting"
|
||||
title = "Port is already in use"
|
||||
}
|
||||
NSLocalizedString("", comment: "")
|
||||
alertDialog(title: title, message: toast)
|
||||
DispatchQueue.main.async {
|
||||
preferencesWindowController.show(preferencePane: .advanceTab)
|
||||
@@ -298,53 +321,38 @@ class V2rayLaunch: NSObject {
|
||||
}
|
||||
|
||||
// just start: stop is so slow
|
||||
let task = Process.launchedProcess(launchPath: "/bin/launchctl", arguments: ["start", LAUNCH_AGENT_NAME])
|
||||
task.waitUntilExit()
|
||||
if task.terminationStatus == 0 {
|
||||
NSLog("Start v2ray-core succeeded.")
|
||||
do {
|
||||
let output = try runCommand(at: "/bin/launchctl", with: ["start", LAUNCH_AGENT_NAME])
|
||||
print("Start v2ray-core: ok \(output)")
|
||||
return true
|
||||
} else {
|
||||
NSLog("Start v2ray-core failed.")
|
||||
makeToast(message: "Start v2ray-core failed.")
|
||||
} catch let error {
|
||||
alertDialog(title: "Start v2ray-core failed.", message: error.localizedDescription)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
static func Stop() {
|
||||
let task = Process.launchedProcess(launchPath: "/bin/launchctl", arguments: ["stop", LAUNCH_AGENT_NAME])
|
||||
task.waitUntilExit()
|
||||
if task.terminationStatus == 0 {
|
||||
NSLog("Stop v2ray-core succeeded.")
|
||||
} else {
|
||||
NSLog("Stop v2ray-core failed.")
|
||||
}
|
||||
}
|
||||
|
||||
static func checkV2rayUTool() {
|
||||
// Ensure launch agent directory is existed.
|
||||
if !FileManager.default.isExecutableFile(atPath: v2rayUTool) {
|
||||
self.install()
|
||||
}
|
||||
|
||||
// Ensure permission with root admin
|
||||
if !checkFileIsRootAdmin(file: v2rayUTool) {
|
||||
self.install()
|
||||
do {
|
||||
let output = try runCommand(at: "/bin/launchctl", with: ["stop", LAUNCH_AGENT_NAME])
|
||||
print("setSystemProxy: ok \(output)")
|
||||
} catch let error {
|
||||
alertDialog(title: "Stop Error", message: error.localizedDescription)
|
||||
}
|
||||
}
|
||||
|
||||
static func checkV2rayCore() {
|
||||
if !FileManager.default.fileExists(atPath: v2rayCoreFile) {
|
||||
print("\(v2rayCoreFile) not exists,need install")
|
||||
self.install()
|
||||
install()
|
||||
}
|
||||
if !FileManager.default.isExecutableFile(atPath: v2rayCoreFile) {
|
||||
print("\(v2rayCoreFile) not accessable")
|
||||
self.install()
|
||||
install()
|
||||
}
|
||||
}
|
||||
|
||||
static func setSystemProxy(mode: RunMode) {
|
||||
print("v2rayUTool", v2rayUTool,mode)
|
||||
print("setSystemProxy", v2rayUTool, mode)
|
||||
let pacUrl = getPacUrl()
|
||||
var httpPort: String = ""
|
||||
var sockPort: String = ""
|
||||
@@ -353,13 +361,12 @@ class V2rayLaunch: NSObject {
|
||||
httpPort = UserDefaults.get(forKey: .localHttpPort) ?? "1087"
|
||||
sockPort = UserDefaults.get(forKey: .localSockPort) ?? "1080"
|
||||
}
|
||||
|
||||
let task = Process.launchedProcess(launchPath: v2rayUTool, arguments: ["-mode", mode.rawValue, "-pac-url", pacUrl, "-http-port", httpPort, "-sock-port", sockPort])
|
||||
task.waitUntilExit()
|
||||
if task.terminationStatus == 0 {
|
||||
NSLog("setSystemProxy " + mode.rawValue + " succeeded.")
|
||||
} else {
|
||||
NSLog("setSystemProxy " + mode.rawValue + " failed.")
|
||||
do {
|
||||
let output = try runCommand(at: v2rayUTool, with: ["-mode", mode.rawValue, "-pac-url", pacUrl, "-http-port", httpPort, "-sock-port", sockPort])
|
||||
print("setSystemProxy: ok \(output)")
|
||||
} catch let error {
|
||||
alertDialog(title: "setSystemProxy Error", message: error.localizedDescription)
|
||||
showInstallAlert()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -413,7 +420,7 @@ class V2rayLaunch: NSObject {
|
||||
jsonText = vCfg.combineManual()
|
||||
|
||||
do {
|
||||
let jsonFilePath = URL.init(fileURLWithPath: JsonConfigFilePath)
|
||||
let jsonFilePath = URL(fileURLWithPath: JsonConfigFilePath)
|
||||
|
||||
// delete before config
|
||||
if FileManager.default.fileExists(atPath: JsonConfigFilePath) {
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
/*
|
||||
/*
|
||||
Localizable.strings
|
||||
V2rayU
|
||||
|
||||
Created by yanue on 2019/7/17.
|
||||
Copyright © 2019 yanue. All rights reserved.
|
||||
*/
|
||||
/* Alert titles */
|
||||
"InstallAlertTitle" = "V2rayU needs to install V2rayUTool into ~/.V2rayU/V2rayUTool with administrator privileges";
|
||||
"InstallFailedTitle" = "Install V2rayUTool Failed"
|
||||
"InstallFailedMessage" = "Error: %s,\nYou need execute scripts manually:\n %s"
|
||||
|
||||
@@ -5,3 +5,8 @@
|
||||
Created by yanue on 2019/7/17.
|
||||
Copyright © 2019 yanue. All rights reserved.
|
||||
*/
|
||||
"InstallAlertTitle" = "V2rayU 需要使用管理员权限安装 V2rayUTool 到 ~/.V2rayU/V2rayUTool";
|
||||
"InstallV2rayUToolFailed" = "安装 V2rayUTool 失败"
|
||||
"HttpPortInUseMessage" = "http端口 %@ 已被使用, 请更换";
|
||||
"Install" = "Install"
|
||||
"Quit" = "Quit"
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
/*
|
||||
/*
|
||||
Localizable.strings
|
||||
V2rayU
|
||||
|
||||
Created by yanue on 2019/7/17.
|
||||
Copyright © 2019 yanue. All rights reserved.
|
||||
*/
|
||||
"InstallAlertTitle" = "V2rayU 需要使用管理员权限安装 V2rayUTool 到 ~/.V2rayU/V2rayUTool";
|
||||
"InstallFailedTitle" = "安装 V2rayUTool 失败"
|
||||
"InstallFailedMessage" = "安装失败: %s\n, 你需要在命令行手动执行一下: %s"
|
||||
|
||||
Reference in New Issue
Block a user