disable sleep whilst downloading, uploading, using usb, inside ftp menu.

This commit is contained in:
ITotalJustice
2025-05-20 23:33:51 +01:00
parent cf908d63b9
commit a67171e2b8
7 changed files with 42 additions and 3 deletions

View File

@@ -165,6 +165,26 @@ public:
return (paths.unk[0] != '\0') || (paths.nintendo[0] != '\0');
}
static void SetAutoSleepDisabled(bool enable) {
static Mutex mutex{};
static int ref_count{};
mutexLock(&mutex);
ON_SCOPE_EXIT(mutexUnlock(&mutex));
if (enable) {
appletSetAutoSleepDisabled(true);
ref_count++;
} else {
if (ref_count) {
ref_count--;
}
if (!ref_count) {
appletSetAutoSleepDisabled(false);
}
}
}
// private:
static constexpr inline auto CONFIG_PATH = "/config/sphaira/config.ini";

View File

@@ -15,6 +15,7 @@ struct Base {
};
Base(u64 transfer_timeout);
virtual ~Base();
// sets up usb.
virtual Result Init() = 0;

View File

@@ -3,6 +3,7 @@
#include "defines.hpp"
#include "evman.hpp"
#include "fs.hpp"
#include "app.hpp"
#include <switch.h>
#include <cstring>
@@ -669,6 +670,9 @@ void SetCommonCurlOptions(CURL* curl, const Api& e) {
}
auto DownloadInternal(CURL* curl, const Api& e) -> ApiResult {
App::SetAutoSleepDisabled(true);
ON_SCOPE_EXIT(App::SetAutoSleepDisabled(false));
// check if stop has been requested before starting download
if (e.GetToken().stop_requested()) {
return {};

View File

@@ -1,6 +1,7 @@
#include "threaded_file_transfer.hpp"
#include "log.hpp"
#include "defines.hpp"
#include "app.hpp"
#include <vector>
#include <algorithm>
@@ -302,6 +303,9 @@ auto GetAlternateCore(int id) {
}
Result TransferInternal(ui::ProgressBox* pbox, s64 size, ReadFunctionCallback rfunc, WriteFunctionCallback wfunc, StartFunctionCallback sfunc) {
App::SetAutoSleepDisabled(true);
ON_SCOPE_EXIT(App::SetAutoSleepDisabled(false));
const auto WRITE_THREAD_CORE = sfunc ? pbox->GetCpuId() : GetAlternateCore(pbox->GetCpuId());
const auto READ_THREAD_CORE = GetAlternateCore(WRITE_THREAD_CORE);

View File

@@ -151,6 +151,8 @@ Menu::Menu() : MenuBase{"FTP Install (EXPERIMENTAL)"_i18n} {
App::DisplayInstallOptions(false);
}});
App::SetAutoSleepDisabled(true);
mutexInit(&m_mutex);
m_was_ftp_enabled = App::GetFtpEnable();
if (!m_was_ftp_enabled) {
@@ -182,6 +184,7 @@ Menu::~Menu() {
App::SetFtpEnable(false);
}
App::SetAutoSleepDisabled(false);
log_write("closing data!!!!\n");
}

View File

@@ -19,18 +19,25 @@
#include "usb/base.hpp"
#include "log.hpp"
#include "defines.hpp"
#include "app.hpp"
#include <ranges>
#include <cstring>
namespace sphaira::usb {
Base::Base(u64 transfer_timeout) {
App::SetAutoSleepDisabled(true);
m_transfer_timeout = transfer_timeout;
ueventCreate(GetCancelEvent(), true);
// this avoids allocations during transfers.
m_aligned.reserve(1024 * 1024 * 16);
}
Base::~Base() {
App::SetAutoSleepDisabled(false);
}
Result Base::TransferPacketImpl(bool read, void *page, u32 size, u32 *out_size_transferred, u64 timeout) {
u32 xfer_id;

View File

@@ -754,7 +754,7 @@ struct BufHelper {
};
Yati::Yati(ui::ProgressBox* _pbox, std::shared_ptr<source::Base> _source) : pbox{_pbox}, source{_source} {
appletSetMediaPlaybackState(true);
App::SetAutoSleepDisabled(true);
}
Yati::~Yati() {
@@ -768,11 +768,11 @@ Yati::~Yati() {
ncmContentStorageClose(std::addressof(ncm_cs[i]));
}
appletSetMediaPlaybackState(false);
if (config.boost_mode) {
appletSetCpuBoostMode(ApmCpuBoostMode_Normal);
}
App::SetAutoSleepDisabled(false);
}
Result Yati::Setup(const ConfigOverride& override) {