Skip to content

Commit

Permalink
Prevent the app from sleeping when the lid is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
windows-server-2003 committed Nov 28, 2021
1 parent e1f08cc commit 4022e99
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/network/network_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ NetworkResult Access_http_post(NetworkSessionList &session_list, const std::stri

std::string url_get_host_name(const std::string &url);

void lock_network_state();
void unlock_network_state();

#define HTTP_STATUS_CODE_OK 200
#define HTTP_STATUS_CODE_NO_CONTENT 204
#define HTTP_STATUS_CODE_PARTIAL_CONTENT 206
Expand Down
19 changes: 19 additions & 0 deletions source/network/network_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,5 +641,24 @@ std::string NetworkResult::get_header(std::string key) {
}
}

static bool exclusive_state_entered = false;
void lock_network_state() {
int res = 0;
if (!exclusive_state_entered) {
Util_log_save("init", "ndmuInit()...", ndmuInit());
res = NDMU_EnterExclusiveState(NDM_EXCLUSIVE_STATE_INFRASTRUCTURE);
if (R_SUCCEEDED(res)) res = NDMU_LockState(); // prevents ndm from switching to StreetPass when the lid is closed
exclusive_state_entered = R_SUCCEEDED(res);
}
}
void unlock_network_state() {
int res = 0;
if (exclusive_state_entered) {
res = NDMU_UnlockState();
if (R_SUCCEEDED(res)) res = NDMU_LeaveExclusiveState();
ndmuExit();
exclusive_state_entered = R_FAILED(res);
}
}


4 changes: 4 additions & 0 deletions source/scene_switcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ void Menu_init(void)
Util_log_save(DEF_MENU_INIT_STR, "amInit()...", amInit());
Util_log_save(DEF_MENU_INIT_STR, "ndspInit()...", (sound_init_result = ndspInit()));//0xd880A7FA
Util_log_save(DEF_MENU_INIT_STR, "APT_SetAppCpuTimeLimit()...", APT_SetAppCpuTimeLimit(30));
lock_network_state();

aptSetSleepAllowed(false);

APT_CheckNew3DS(&is_new_3ds);

Expand Down Expand Up @@ -142,6 +145,7 @@ void Menu_exit(void)
thumbnail_downloader_thread_exit_request();
async_task_thread_exit_request();
misc_tasks_thread_exit_request();
unlock_network_state();
Util_log_save(DEF_MENU_EXIT_STR, "threadJoin()...", threadJoin(menu_worker_thread, time_out));
Util_log_save(DEF_MENU_EXIT_STR, "threadJoin()...", threadJoin(menu_check_connectivity_thread, time_out));
// Util_log_save(DEF_MENU_EXIT_STR, "threadJoin()...", threadJoin(menu_send_app_info_thread, time_out));
Expand Down

0 comments on commit 4022e99

Please sign in to comment.