mirror of
https://github.com/J-D-K/JKSV.git
synced 2026-03-21 17:24:37 -05:00
Thread remote initialization.
This commit is contained in:
parent
e6df0ab2f8
commit
f7f6f91a47
2
Makefile
2
Makefile
|
|
@ -39,7 +39,7 @@ INCLUDES := include ./Libraries/FsLib/Switch/FsLib/include ./Libraries/SDLLib/SD
|
|||
EXEFS_SRC := exefs_src
|
||||
APP_TITLE := JKSV
|
||||
APP_AUTHOR := JK
|
||||
APP_VERSION := 10.02.2025
|
||||
APP_VERSION := 10.07.2025
|
||||
ROMFS := romfs
|
||||
ICON := icon.jpg
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,6 @@
|
|||
namespace builddate
|
||||
{
|
||||
inline constexpr int MONTH = 10;
|
||||
inline constexpr int DAY = 2;
|
||||
inline constexpr int DAY = 8;
|
||||
inline constexpr int YEAR = 2025;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "remote/Storage.hpp"
|
||||
#include "sys/threadpool.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
|
@ -12,11 +13,8 @@ namespace remote
|
|||
/// @brief Returns whether or not the console has an active internet connection.
|
||||
bool has_internet_connection() noexcept;
|
||||
|
||||
/// @brief Initializes the Storage instance to Google Drive.
|
||||
void initialize_google_drive();
|
||||
|
||||
/// @brief Initializes the Storage instance to WebDav
|
||||
void initialize_webdav();
|
||||
/// @brief Initializes the remote service according to the config on the sdmc.
|
||||
void initialize(sys::threadpool::JobData jobData);
|
||||
|
||||
/// @brief Returns the pointer to the Storage instance.
|
||||
remote::Storage *get_remote_storage() noexcept;
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ JKSV::JKSV()
|
|||
JKSV::create_directories();
|
||||
sys::threadpool::initialize();
|
||||
|
||||
sys::threadpool::push_job(remote::initialize, nullptr);
|
||||
data::launch_initialization(false, finish_initialization);
|
||||
FadeState::create_and_push(colors::BLACK, 0xFF, 0x00, nullptr);
|
||||
|
||||
|
|
@ -221,10 +222,4 @@ void JKSV::exit_services()
|
|||
accountExit();
|
||||
}
|
||||
|
||||
static void finish_initialization()
|
||||
{
|
||||
MainMenuState::create_and_push();
|
||||
|
||||
if (fslib::file_exists(remote::PATH_GOOGLE_DRIVE_CONFIG)) { remote::initialize_google_drive(); }
|
||||
else if (fslib::file_exists(remote::PATH_WEBDAV_CONFIG)) { remote::initialize_webdav(); }
|
||||
}
|
||||
static void finish_initialization() { MainMenuState::create_and_push(); }
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#include "StateManager.hpp"
|
||||
#include "appstates/TaskState.hpp"
|
||||
#include "error.hpp"
|
||||
#include "input.hpp"
|
||||
#include "logging/logger.hpp"
|
||||
#include "remote/GoogleDrive.hpp"
|
||||
#include "remote/WebDav.hpp"
|
||||
|
|
@ -28,15 +29,17 @@ namespace
|
|||
remote::GoogleDrive *drive{};
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
} // namespace
|
||||
|
||||
static void initialize_google_drive();
|
||||
static void initialize_webdav();
|
||||
|
||||
// Declarations here. Definitions at bottom.
|
||||
/// @brief This is the thread function that handles logging into Google.
|
||||
static void drive_sign_in(sys::threadpool::JobData taskData);
|
||||
|
||||
/// @brief This creates (if needed) the JKSV folder for Google Drive and sets it as the root.
|
||||
/// @param drive Pointer to the drive instance..
|
||||
/// @param drive Pointer to the drive instance.
|
||||
static void drive_set_jksv_root(remote::GoogleDrive *drive);
|
||||
|
||||
bool remote::has_internet_connection() noexcept
|
||||
|
|
@ -49,17 +52,25 @@ bool remote::has_internet_connection() noexcept
|
|||
return true;
|
||||
}
|
||||
|
||||
void remote::initialize_google_drive()
|
||||
void remote::initialize(sys::threadpool::JobData jobData)
|
||||
{
|
||||
const int popTicks = ui::PopMessageManager::DEFAULT_TICKS;
|
||||
|
||||
if (!remote::has_internet_connection())
|
||||
const bool driveExists = fslib::file_exists(remote::PATH_GOOGLE_DRIVE_CONFIG);
|
||||
const bool webdavExists = fslib::file_exists(remote::PATH_WEBDAV_CONFIG);
|
||||
if ((driveExists || webdavExists) && !remote::has_internet_connection())
|
||||
{
|
||||
const char *popNoInternet = strings::get_by_name(strings::names::REMOTE_POPS, 0);
|
||||
ui::PopMessageManager::push_message(popTicks, popNoInternet);
|
||||
ui::PopMessageManager::push_message(ui::PopMessageManager::DEFAULT_TICKS, popNoInternet);
|
||||
return;
|
||||
}
|
||||
|
||||
if (driveExists) { initialize_google_drive(); }
|
||||
else if (webdavExists) { initialize_webdav(); }
|
||||
}
|
||||
|
||||
void initialize_google_drive()
|
||||
{
|
||||
const int popTicks = ui::PopMessageManager::DEFAULT_TICKS;
|
||||
|
||||
s_storage = std::make_unique<remote::GoogleDrive>();
|
||||
remote::GoogleDrive *drive = static_cast<remote::GoogleDrive *>(s_storage.get());
|
||||
if (drive->sign_in_required())
|
||||
|
|
@ -67,7 +78,8 @@ void remote::initialize_google_drive()
|
|||
auto driveStruct = std::make_shared<DriveStruct>();
|
||||
driveStruct->drive = drive;
|
||||
|
||||
TaskState::create_and_push(drive_sign_in, driveStruct);
|
||||
// To do: StateManager isn't thread safe. This might/probably will cause data race randomly.
|
||||
TaskState::create_push_fade(drive_sign_in, driveStruct);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -79,10 +91,8 @@ void remote::initialize_google_drive()
|
|||
ui::PopMessageManager::push_message(popTicks, popDriveSuccess);
|
||||
}
|
||||
|
||||
void remote::initialize_webdav()
|
||||
void initialize_webdav()
|
||||
{
|
||||
if (!remote::has_internet_connection()) { return; }
|
||||
|
||||
s_storage = std::make_unique<remote::WebDav>();
|
||||
const int popTicks = ui::PopMessageManager::DEFAULT_TICKS;
|
||||
if (s_storage->is_initialized())
|
||||
|
|
@ -126,6 +136,10 @@ static void drive_sign_in(sys::threadpool::JobData taskData)
|
|||
|
||||
while (std::time(NULL) < expiration && !drive->poll_sign_in(deviceCode))
|
||||
{
|
||||
const bool bPressed = input::button_pressed(HidNpadButton_B);
|
||||
const bool bHeld = input::button_held(HidNpadButton_B);
|
||||
if (bPressed || bHeld) { break; }
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(pollingInterval));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user