disable sleep whilst downloading, uploading, using usb, inside ftp menu.
This commit is contained in:
@@ -165,6 +165,26 @@ public:
|
|||||||
return (paths.unk[0] != '\0') || (paths.nintendo[0] != '\0');
|
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:
|
// private:
|
||||||
static constexpr inline auto CONFIG_PATH = "/config/sphaira/config.ini";
|
static constexpr inline auto CONFIG_PATH = "/config/sphaira/config.ini";
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ struct Base {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Base(u64 transfer_timeout);
|
Base(u64 transfer_timeout);
|
||||||
|
virtual ~Base();
|
||||||
|
|
||||||
// sets up usb.
|
// sets up usb.
|
||||||
virtual Result Init() = 0;
|
virtual Result Init() = 0;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "defines.hpp"
|
#include "defines.hpp"
|
||||||
#include "evman.hpp"
|
#include "evman.hpp"
|
||||||
#include "fs.hpp"
|
#include "fs.hpp"
|
||||||
|
#include "app.hpp"
|
||||||
|
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -669,6 +670,9 @@ void SetCommonCurlOptions(CURL* curl, const Api& e) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
auto DownloadInternal(CURL* curl, const Api& e) -> ApiResult {
|
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
|
// check if stop has been requested before starting download
|
||||||
if (e.GetToken().stop_requested()) {
|
if (e.GetToken().stop_requested()) {
|
||||||
return {};
|
return {};
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "threaded_file_transfer.hpp"
|
#include "threaded_file_transfer.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
#include "defines.hpp"
|
#include "defines.hpp"
|
||||||
|
#include "app.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@@ -302,6 +303,9 @@ auto GetAlternateCore(int id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Result TransferInternal(ui::ProgressBox* pbox, s64 size, ReadFunctionCallback rfunc, WriteFunctionCallback wfunc, StartFunctionCallback sfunc) {
|
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 WRITE_THREAD_CORE = sfunc ? pbox->GetCpuId() : GetAlternateCore(pbox->GetCpuId());
|
||||||
const auto READ_THREAD_CORE = GetAlternateCore(WRITE_THREAD_CORE);
|
const auto READ_THREAD_CORE = GetAlternateCore(WRITE_THREAD_CORE);
|
||||||
|
|
||||||
|
|||||||
@@ -151,6 +151,8 @@ Menu::Menu() : MenuBase{"FTP Install (EXPERIMENTAL)"_i18n} {
|
|||||||
App::DisplayInstallOptions(false);
|
App::DisplayInstallOptions(false);
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
App::SetAutoSleepDisabled(true);
|
||||||
|
|
||||||
mutexInit(&m_mutex);
|
mutexInit(&m_mutex);
|
||||||
m_was_ftp_enabled = App::GetFtpEnable();
|
m_was_ftp_enabled = App::GetFtpEnable();
|
||||||
if (!m_was_ftp_enabled) {
|
if (!m_was_ftp_enabled) {
|
||||||
@@ -182,6 +184,7 @@ Menu::~Menu() {
|
|||||||
App::SetFtpEnable(false);
|
App::SetFtpEnable(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App::SetAutoSleepDisabled(false);
|
||||||
log_write("closing data!!!!\n");
|
log_write("closing data!!!!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,18 +19,25 @@
|
|||||||
#include "usb/base.hpp"
|
#include "usb/base.hpp"
|
||||||
#include "log.hpp"
|
#include "log.hpp"
|
||||||
#include "defines.hpp"
|
#include "defines.hpp"
|
||||||
|
#include "app.hpp"
|
||||||
#include <ranges>
|
#include <ranges>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
namespace sphaira::usb {
|
namespace sphaira::usb {
|
||||||
|
|
||||||
Base::Base(u64 transfer_timeout) {
|
Base::Base(u64 transfer_timeout) {
|
||||||
|
App::SetAutoSleepDisabled(true);
|
||||||
|
|
||||||
m_transfer_timeout = transfer_timeout;
|
m_transfer_timeout = transfer_timeout;
|
||||||
ueventCreate(GetCancelEvent(), true);
|
ueventCreate(GetCancelEvent(), true);
|
||||||
// this avoids allocations during transfers.
|
// this avoids allocations during transfers.
|
||||||
m_aligned.reserve(1024 * 1024 * 16);
|
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) {
|
Result Base::TransferPacketImpl(bool read, void *page, u32 size, u32 *out_size_transferred, u64 timeout) {
|
||||||
u32 xfer_id;
|
u32 xfer_id;
|
||||||
|
|
||||||
|
|||||||
@@ -754,7 +754,7 @@ struct BufHelper {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Yati::Yati(ui::ProgressBox* _pbox, std::shared_ptr<source::Base> _source) : pbox{_pbox}, source{_source} {
|
Yati::Yati(ui::ProgressBox* _pbox, std::shared_ptr<source::Base> _source) : pbox{_pbox}, source{_source} {
|
||||||
appletSetMediaPlaybackState(true);
|
App::SetAutoSleepDisabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
Yati::~Yati() {
|
Yati::~Yati() {
|
||||||
@@ -768,11 +768,11 @@ Yati::~Yati() {
|
|||||||
ncmContentStorageClose(std::addressof(ncm_cs[i]));
|
ncmContentStorageClose(std::addressof(ncm_cs[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
appletSetMediaPlaybackState(false);
|
|
||||||
|
|
||||||
if (config.boost_mode) {
|
if (config.boost_mode) {
|
||||||
appletSetCpuBoostMode(ApmCpuBoostMode_Normal);
|
appletSetCpuBoostMode(ApmCpuBoostMode_Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
App::SetAutoSleepDisabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Yati::Setup(const ConfigOverride& override) {
|
Result Yati::Setup(const ConfigOverride& override) {
|
||||||
|
|||||||
Reference in New Issue
Block a user