Feature: Add addition logs

This commit is contained in:
yichengchen 2019-08-21 12:03:04 +08:00
parent bbcc0ad3cf
commit daf27fdac4
2 changed files with 88 additions and 2 deletions

View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1100"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F9A7C0682306E874007163C7"
BuildableName = "com.west2online.ClashX.ProxyConfigHelper"
BlueprintName = "com.west2online.ClashX.ProxyConfigHelper"
ReferencedContainer = "container:ClashX.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
debugAsWhichUser = "root"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F9A7C0682306E874007163C7"
BuildableName = "com.west2online.ClashX.ProxyConfigHelper"
BlueprintName = "com.west2online.ClashX.ProxyConfigHelper"
ReferencedContainer = "container:ClashX.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "F9A7C0682306E874007163C7"
BuildableName = "com.west2online.ClashX.ProxyConfigHelper"
BlueprintName = "com.west2online.ClashX.ProxyConfigHelper"
ReferencedContainer = "container:ClashX.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>

View File

@ -45,6 +45,7 @@ class SystemProxyManager: NSObject {
// MARK: - Public
func checkInstall() {
Logger.log(msg: "checkInstall", level: .debug)
helperStatus { [weak self] installed in
if installed {return}
if Thread.isMainThread {
@ -59,8 +60,9 @@ class SystemProxyManager: NSObject {
func saveProxy() {
guard !disableRestoreProxy else {return}
Logger.log(msg: "saveProxy", level: .debug)
helper()?.getCurrentProxySetting({ [weak self] info in
Logger.log(msg: "saveProxy done", level: .debug)
if let info = info as? [String : Any] {
self?.savedProxyInfo = info
}
@ -109,7 +111,8 @@ class SystemProxyManager: NSObject {
/// Install new helper daemon
private func installHelperDaemon() {
Logger.log(msg: "installHelperDaemon", level: .info)
// Create authorization reference for the user
var authRef: AuthorizationRef?
var authStatus = AuthorizationCreate(nil, nil, [], &authRef)
@ -189,9 +192,12 @@ class SystemProxyManager: NSObject {
connection = NSXPCConnection(machServiceName: SystemProxyManager.machServiceName, options: NSXPCConnection.Options.privileged)
connection?.remoteObjectInterface = NSXPCInterface(with: ProxyConfigRemoteProcessProtocol.self)
connection?.invalidationHandler = {
[weak self] in
guard let self = self else {return}
self.connection?.invalidationHandler = nil
OperationQueue.main.addOperation() {
self.connection = nil
self._helper = nil
Logger.log(msg: "XPC Connection Invalidated")
}
}
@ -227,6 +233,7 @@ class SystemProxyManager: NSObject {
var installed = false
let semaphore = DispatchSemaphore(value: 0)
helper.getVersion { installedHelperVersion in
Logger.log(msg: "helper version \(installedHelperVersion)", level: .debug)
installed = installedHelperVersion == helperVersion
}
_ = semaphore.wait(timeout: DispatchTime.now()+1)