johndbritton / teleport

Virtual KVM for macOS
GNU General Public License v2.0
790 stars 132 forks source link

Control sleep/wake #66

Closed reaperhulk closed 3 years ago

reaperhulk commented 3 years ago

This PR adds two new type of messages (wake and sleep) that are sent to the controlled machine. This allows you to wake the screen on the secondary when you wake the screen on your primary machine. It also adds an NSTimer which sends wake messages to prevent monitor sleep whenever the primary machine's monitor is awake.

Problems:

The workaround for the sleep issue right now would be to set the display sleep interval to 1 minute on the controlled machine. Since a wake ping is sent every ~50s it will never sleep, but once the primary display is put to sleep it will sleep within at most 60s.

reaperhulk commented 3 years ago

Pushed a newer revision that does the following in addition to previous functionality:

johndbritton commented 3 years ago

Thanks for the PR. I'm going to give this a review and see if I can test it out a bit locally.

I believe teleport supports more than one machine, but this assumes that [clientController currentConnection] is the only possible connection. If there exists a connection table that can be iterated over this is easy to fix though.

Yes, I'm pretty sure there is support for more than one machine and we should be sure not to drop that.

Testing?

We don't have any real testing. I opened https://github.com/johndbritton/teleport/issues/73 so that we can maybe issue prereleases and get feedback from people before making things official. I would love to get some unit testing in here.

Adds a "Sync lock status" preference, which, if enabled, causes the secondary machine to be locked when the primary locks.

This is a cool idea.

This uses a very ugly solution as a demo (sending the exact Control-Command-Q sequence for locking) and will not work in other localizations, etc etc. We should try to find a better solution.

Agreed, can we not just send this as a message instead of as a set of keys. This might be helpful https://stackoverflow.com/a/26492632

extern int SACLockScreenImmediate ( void );

int main ( ) {
    return SACLockScreenImmediate();
}
reaperhulk commented 3 years ago

We can use SACLockScreenImmediate, but it isn't a public API. I didn't know how to link against a private framework in Xcode but it looks like I figured out a reasonable method. Pushed.

reaperhulk commented 3 years ago

I think revisiting event sending to all peers probably is easier to do in a new PR, but I've addressed the prefs concern so this is ready for review I think.

Edit: One quick note: You may need to disable the hardened runtime for now. I'm not sure if this is just a local issue for me or what but I had to disable hardened runtime to successfully build the project.

johndbritton commented 3 years ago

Edit: One quick note: You may need to disable the hardened runtime for now. I'm not sure if this is just a local issue for me or what but I had to disable hardened runtime to successfully build the project.

What version of Xcode are you using? I recently upgraded to 12.3 and found that the Sparkle framework was not being included when Signing Certificate was set to Sign to run locally which resulted in a crash when running from Xcode. I was able to fix the issue by setting Signing Certificate to Developer ID Application and setting the team to the team I use to sign official releases.

I went back to an older version (before the Sparkle updates) and I had the same issue so I think this is a bug introduced with Xcode 12.3.

reaperhulk commented 3 years ago

I am on Xcode 12.3 and was using sign to run locally so that makes sense.

I was just experimenting with adding a broadcastMessage feature, but it looks like _connections doesn't actually maintain what we thought. When I have an active connection to my secondary machine it has a size of zero, d'oh. We'll have to dig further to see what we can find here...

Thanks for the merge though, this is getting pretty close to being very usable for me!

johndbritton commented 3 years ago

I'm going to make a new release for version 1.3.1 with these changes included. Can you update your machine to use v1.3.0 and upgrade using the auto-update feature and let me know if you have any issues?

reaperhulk commented 3 years ago

Sure, I'm going to bed shortly but let me install 1.3.0 right now and I'll check 1.3.1 as soon as you release.

johndbritton commented 3 years ago

@reaperhulk v1.3.1 is out. Thanks for the contribution.

reaperhulk commented 3 years ago

@johndbritton 🥳

Screen Shot 2020-12-20 at 11 23 17 PM

Upgraded without a problem. I did have to reset the positioning of the monitors in teleport after upgrade, but I've been mangling my preferences so much that I don't think that's a useful data point 😄