Skip to content

Commit

Permalink
Attempt to fix #62
Browse files Browse the repository at this point in the history
  • Loading branch information
SoneeJohn committed Apr 10, 2019
1 parent 950d813 commit 1fc666e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion VirtualKVM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
};
011D3E75225D46A600594DB6 /* Copy Helper */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
buildActionMask = 12;
dstPath = Contents/Library/LaunchServices;
dstSubfolderSpec = 1;
files = (
Expand Down
33 changes: 17 additions & 16 deletions VirtualKVM/KVMAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions VirtualKVM/KVMController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 1fc666e

Please sign in to comment.