From 1fc666ea3b481c6ae75fb2476add1f78b2a7fca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sonee=CC=81=20John?= Date: Wed, 10 Apr 2019 12:11:02 -0400 Subject: [PATCH] Attempt to fix #62 --- VirtualKVM.xcodeproj/project.pbxproj | 2 +- VirtualKVM/KVMAppDelegate.swift | 33 ++++++++++++++-------------- VirtualKVM/KVMController.m | 5 +++-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/VirtualKVM.xcodeproj/project.pbxproj b/VirtualKVM.xcodeproj/project.pbxproj index 58f54d1..8dd8f8e 100644 --- a/VirtualKVM.xcodeproj/project.pbxproj +++ b/VirtualKVM.xcodeproj/project.pbxproj @@ -76,7 +76,7 @@ }; 011D3E75225D46A600594DB6 /* Copy Helper */ = { isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; + buildActionMask = 12; dstPath = Contents/Library/LaunchServices; dstSubfolderSpec = 1; files = ( diff --git a/VirtualKVM/KVMAppDelegate.swift b/VirtualKVM/KVMAppDelegate.swift index b2f401f..efdfec1 100644 --- a/VirtualKVM/KVMAppDelegate.swift +++ b/VirtualKVM/KVMAppDelegate.swift @@ -18,51 +18,52 @@ class KVMAppDelegate: NSObject, NSApplicationDelegate, AppProtocol { private var currentHelperConnection: NSXPCConnection? func applicationDidFinishLaunching(_ aNotification: Notification) { + Uiltites.shared.setupLogging() + + print("Log path VirtualKVM: \(Uiltites.shared.logFilePath!)") // Update the current authorization database right // This will prompt the user for authentication if something needs updating. - do { try HelperAuthorization.authorizationRightsUpdateDatabase() } catch let error as NSError { - print("Error `authorizationRightsUpdateDatabase` \(error)") + Uiltites.shared.log?.error("Error `authorizationRightsUpdateDatabase` \(error)") } self.helperStatus { installed in guard installed == false else { return } - - print("Helper not installed, attempting installation.") + Uiltites.shared.log?.info("Helper not installed, attempting installation.") do { _ = try self.helperInstall() } catch { - print("Failed to install helper") + Uiltites.shared.log?.error("Failed to install helper") } } NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: KVMAppDelegate.shouldKillDisplayDaemonNotification), object: nil, queue: nil) { (_) in guard let helper = self.helper(nil) else { return } - helper.killProcess(arguments: "Safari", completion: { (existCode) in - print("Kill Display Daemon with code \(existCode)") + Uiltites.shared.log?.debug("shouldKillDisplayDaemonNotification") + helper.killProcess(arguments: "dpd", completion: { (existCode) in + Uiltites.shared.log?.info("Kill Display Daemon with code \(existCode)") }) } NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: KVMAppDelegate.shouldKillDisplayAudioDaemonNotification), object: nil, queue: nil) { (_) in - guard let helper = self.helper(nil) else { return } - helper.killProcess(arguments: "dpaudiothru", completion: { (existCode) in - print("Kill Display Audio Daemon with code \(existCode)") - }) + Uiltites.shared.log?.debug("shouldKillDisplayAudioDaemonNotification") + Uiltites.shared.stopAudioDaemon() } NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: KVMAppDelegate.shouldLaunchDisplayAudioDaemonNotification), object: nil, queue: nil) { (_) in - guard let helper = self.helper(nil) else { return } - - helper.launchProcess(path: "/usr/libexec/dpaudiothru", completion: { (existCode) in - print("Launch dpaudiothru with code \(existCode)") - }) + Uiltites.shared.log?.debug("shouldLaunchDisplayAudioDaemonNotification") + Uiltites.shared.startAudioDaemon() } } + func applicationWillTerminate(_ notification: Notification) { + Uiltites.shared.stopAudioDaemon() + } + // MARK: - // MARK: Helper Connection Methods diff --git a/VirtualKVM/KVMController.m b/VirtualKVM/KVMController.m index 754b0a5..a9c6f52 100644 --- a/VirtualKVM/KVMController.m +++ b/VirtualKVM/KVMController.m @@ -262,6 +262,9 @@ - (void)enableTargetDisplayMode { return; } + [[NSNotificationCenter defaultCenter]postNotificationName:KVMAppDelegate.shouldKillDisplayDaemonNotification object:nil]; + [[NSNotificationCenter defaultCenter]postNotificationName:KVMAppDelegate.shouldKillDisplayAudioDaemonNotification object:nil]; + CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); CGEventRef f2d = CGEventCreateKeyboardEvent(src, 0x90, true); @@ -278,8 +281,6 @@ - (void)enableTargetDisplayMode { CFRelease(f2u); CFRelease(src); - [[NSNotificationCenter defaultCenter]postNotificationName:KVMAppDelegate.shouldLaunchDisplayAudioDaemonNotification object:nil]; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ if (!self.thunderboltObserver.isInTargetDisplayMode) { //TDM wasn't enabled try again