aria2
aria2 copied to clipboard
Add ability to prevent system from entering sleep/hibernation while downloading
My Windows systems (desktops and battery-powered devices) are set to automatically sleep/hibernate on user inactivity after a specified time period. All the well-coded download managers, media players, disc burners, presentation software etc. that I use nowadays are able to deny the system from entering sleep/hibernation while they are busy executing user-initiated tasks, and so I don't have to tinker with my power settings unnecessarily. Windows has long provided power management APIs to enable such use cases.
Currently however I have to either remember to manually modify my active power plan both before and after using aria2 (which is naturally cumbersome and often leads to an undesirable system state when I forget either of the two), or I need to use a batch file every time that automates the before/after power plan edits using powercfg or similar (which is painful as well).
It would thus be highly desirable if aria2 itself could invoke the standard OS power management APIs, exposed to end users via something like a --keep-system-awake-till-done option. The program's documentation doesn't seem to mention which versions of Windows it works on, but if XP and Vista are no longer supported then the enhanced PowerCreateRequest/PowerSetRequest/PowerClearRequest APIs can be used, otherwise the still supported SetThreadExecutionState API can be relied upon.
Further detailed information about the APIs is available from the usual sources, including MSDN of course and specifically the Power Availability Requests document available here (the New Functions for Availability Requests section therein should help).
Thanks for reading, and I hope this feature will be implemented in a future version of this wonderful utility.
@nmaier Are you interested in this?
Really useful and i think this is an important feature for the future.
If using the older SetThreadExecutionState()
API, the skeleton code might look like:
#ifdef _WIN32
namespace {
// Call once on startup
void win32PreventSleep(void)
{
SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);
}
// Call once on shutdown (or ignore and let the OS clear the flag on process exit/crash
void win32AllowSleep(void)
{
SetThreadExecutionState(ES_CONTINUOUS);
}
}
#endif
@0xABD, according to MSDN:
ES_AWAYMODE_REQUIRED should be used only by media-recording and media-distribution applications that must perform critical background processing on desktop computers while the computer appears to be sleeping.
ES_SYSTEM_REQUIRED should be quite enough to prevent a computer from sleeping.
In xubuntu i have a similar issue the pc suspend. aria2c version:
aria2 versión 1.36.0 Copyright (C) 2006, 2019 Tatsuhiro Tsujikawa
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
** Configuration ** Funciones activadas: Async DNS, BitTorrent, Firefox3 Cookie, GZip, HTTPS, Message Digest, Metalink, XML-RPC, SFTP Hash Algorithms: sha-1, sha-224, sha-256, sha-384, sha-512, md5, adler32 Libraries: zlib/1.2.11 libxml2/2.9.12 sqlite3/3.36.0 GnuTLS/3.7.1 nettle GMP/6.2.1 c-ares/1.17.1 libssh2/1.10.0 Compiler: gcc 11.2.0 built by x86_64-pc-linux-gnu on Aug 21 2021 15:26:28 Sistema: Linux 6.2.0-34-generic #34~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 7 13:12:03 UTC 2 x86_64