TerasologyLauncher
TerasologyLauncher copied to clipboard
Handle hibernation/sleep mode during download
2014-03-19 21:29:01,057 INFO [AWT-EventQueue-0] - Cancel game download! [org.terasology.launcher.gui.LauncherFrame]
2014-03-19 21:29:04,307 ERROR [AWT-EventQueue-0] - Could not start game download! [org.terasology.launcher.gui.LauncherFrame]
java.io.IOException: Could not delete file! C:\Users\<USER>\AppData\Roaming\TerasologyLauncher\temp\TerasologyStable_30.zip
Which platforms do we want to target? I remember using the win32 api for one of my homeworks to prevent windows sleep while my 6 hour simulation was processing. From what I read on the internet, with the JNA project https://github.com/java-native-access/jna it would be possible to load the win32 dlls and make the necessary api calls.
If I remember right it was the SetThreadExecutionState command, where a flag could be set while the download is ongoing, and reset after it has finished. See the vista part for the accepted answer: http://stackoverflow.com/questions/629240/prevent-windows-from-going-into-sleep-when-my-program-is-running I also remember having to ask some permission with a bit more code before this command can be run, but it has been a long time...
In general, we want to target all platforms (Windows, Mac, Linux). As this will likely be platform specific code I'm fine if we start with a windows implementation (are there 32/64bit differences?). I'd highly appreciate a PR with something to discuss :wink:
Okay, I'll see what I can cook up. The name win32 api is just from tradition, 32/64 bit should not be an issue, but the method I outlined works for windows vista and above. But it's a start
JNA seems like a lot of work, keeping all the platform-dependent jars with the client, so I'll see if JNI is enough to load the system dlls'
JNA is already included in build.gradle
so you should be able to user whatever you need from it. No need to set anything up.
Ohh, cool! Thanks for pointing it out!
I did not find this function in JNA, so I opened a request for it https://github.com/java-native-access/jna/issues/720 . After it is added it can be used in the launcher.
Bump - neat to say that the related feature request was just implemented within the last day! Although I dunno if it has been released yet.
For linux https://linux.die.net/man/3/xscreensaversuspend this api call seems to be a promising
But the problem you want to solve isn't that the screensaver turns on or the display turns off, right?
You want to make sure the download isn't interrupted.
Shouldn't still be okay for the display to turn off as long as it doesn't put the CPU in sleep mode?
Shouldn't still be okay for the display to turn off as long as it doesn't put the CPU in sleep mode?
I'd say yep. We want to harden the game to where it can either keep going or resume gracefully. At the same time we probably shouldn't interfere with the OS settings - so don't suppress screen saver, sleep mode, etc, unless we can better advertise that to the user somehow. Which might be an option - like say we could put a very visible checkbox by the download button and if you click it the game will suppress things that could stall the download be it overzealous screen savers, sleep mode, etc.
Okay, in that case the xscreensaver API probably isn't what you want for Linux, as I expect that to only influence the display.
How sleep-on-idle is handled in Linux is probably a big "That Depends" on distribution & desktop environment, but this looks informative at least for systemd-based distributions, and has some links to how gnome-session handles it at the end: https://www.freedesktop.org/wiki/Software/systemd/inhibit/