TerasologyLauncher icon indicating copy to clipboard operation
TerasologyLauncher copied to clipboard

Handle hibernation/sleep mode during download

Open mkalb opened this issue 10 years ago • 14 comments

mkalb avatar Mar 07 '14 08:03 mkalb

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

mkalb avatar Mar 19 '14 20:03 mkalb

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.

Avalancs avatar Oct 18 '16 20:10 Avalancs

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...

Avalancs avatar Oct 18 '16 20:10 Avalancs

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:

skaldarnar avatar Oct 18 '16 20:10 skaldarnar

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

Avalancs avatar Oct 18 '16 20:10 Avalancs

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'

Avalancs avatar Oct 18 '16 21:10 Avalancs

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.

skaldarnar avatar Oct 25 '16 16:10 skaldarnar

Ohh, cool! Thanks for pointing it out!

Avalancs avatar Oct 25 '16 20:10 Avalancs

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.

Avalancs avatar Oct 29 '16 23:10 Avalancs

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.

Cervator avatar Nov 17 '16 06:11 Cervator

For linux https://linux.die.net/man/3/xscreensaversuspend this api call seems to be a promising

Avalancs avatar Sep 25 '18 21:09 Avalancs

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?

keturn avatar Oct 06 '18 23:10 keturn

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.

Cervator avatar Oct 07 '18 00:10 Cervator

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/

keturn avatar Oct 07 '18 00:10 keturn