Moves Calibre settings into 1 single Calibre setting which will match how the KOReader PR works too

This commit is contained in:
Justin Mitchell
2026-01-03 22:42:37 -05:00
parent e457c8683c
commit 2976113c0a
3 changed files with 233 additions and 53 deletions

View File

@@ -1,21 +1,18 @@
#include "SettingsActivity.h"
#include <GfxRenderer.h>
#include <WiFi.h>
#include <cstring>
#include "CalibreSettingsActivity.h"
#include "CrossPointSettings.h"
#include "MappedInputManager.h"
#include "OtaUpdateActivity.h"
#include "activities/network/CalibreWirelessActivity.h"
#include "activities/network/WifiSelectionActivity.h"
#include "activities/util/KeyboardEntryActivity.h"
#include "fontIds.h"
// Define the static settings list
namespace {
constexpr int settingsCount = 15;
constexpr int settingsCount = 14;
const SettingInfo settingsList[settingsCount] = {
// Should match with SLEEP_SCREEN_MODE
{"Sleep Screen", SettingType::ENUM, &CrossPointSettings::sleepScreen, {"Dark", "Light", "Custom", "Cover"}},
@@ -45,8 +42,7 @@ const SettingInfo settingsList[settingsCount] = {
&CrossPointSettings::paragraphAlignment,
{"Justify", "Left", "Center", "Right"}},
{"Reader Side Margin", SettingType::ENUM, &CrossPointSettings::sideMargin, {"None", "Small", "Medium", "Large"}},
{"Calibre Web URL", SettingType::ACTION, nullptr, {}},
{"Calibre Wireless Device", SettingType::TOGGLE, &CrossPointSettings::calibreWirelessEnabled, {}},
{"Calibre Settings", SettingType::ACTION, nullptr, {}},
{"Check for updates", SettingType::ACTION, nullptr, {}},
};
} // namespace
@@ -135,59 +131,19 @@ void SettingsActivity::toggleCurrentSetting() {
// Toggle the boolean value using the member pointer
const bool currentValue = SETTINGS.*(setting.valuePtr);
SETTINGS.*(setting.valuePtr) = !currentValue;
// Special handling for Calibre Wireless Device - launch activity when toggled ON
if (std::string(setting.name) == "Calibre Wireless Device" && !currentValue) {
SETTINGS.saveToFile();
xSemaphoreTake(renderingMutex, portMAX_DELAY);
exitActivity();
// Check WiFi connectivity first
if (WiFi.status() != WL_CONNECTED) {
enterNewActivity(new WifiSelectionActivity(renderer, mappedInput, [this](bool connected) {
exitActivity();
if (connected) {
enterNewActivity(new CalibreWirelessActivity(renderer, mappedInput, [this] {
exitActivity();
updateRequired = true;
}));
} else {
// WiFi connection failed/cancelled, turn off the setting
SETTINGS.calibreWirelessEnabled = 0;
SETTINGS.saveToFile();
updateRequired = true;
}
}));
} else {
enterNewActivity(new CalibreWirelessActivity(renderer, mappedInput, [this] {
exitActivity();
updateRequired = true;
}));
}
xSemaphoreGive(renderingMutex);
return; // Don't save again at the end
}
} else if (setting.type == SettingType::ENUM && setting.valuePtr != nullptr) {
const uint8_t currentValue = SETTINGS.*(setting.valuePtr);
SETTINGS.*(setting.valuePtr) = (currentValue + 1) % static_cast<uint8_t>(setting.enumValues.size());
} else if (setting.type == SettingType::ACTION) {
if (std::string(setting.name) == "Calibre Web URL") {
if (strcmp(setting.name, "Calibre Settings") == 0) {
xSemaphoreTake(renderingMutex, portMAX_DELAY);
exitActivity();
enterNewActivity(new KeyboardEntryActivity(
renderer, mappedInput, "Calibre Web URL", SETTINGS.opdsServerUrl, 10, 127, false,
[this](const std::string& url) {
strncpy(SETTINGS.opdsServerUrl, url.c_str(), sizeof(SETTINGS.opdsServerUrl) - 1);
SETTINGS.opdsServerUrl[sizeof(SETTINGS.opdsServerUrl) - 1] = '\0';
SETTINGS.saveToFile();
exitActivity();
updateRequired = true;
},
[this] {
exitActivity();
updateRequired = true;
}));
enterNewActivity(new CalibreSettingsActivity(renderer, mappedInput, [this] {
exitActivity();
updateRequired = true;
}));
xSemaphoreGive(renderingMutex);
} else if (std::string(setting.name) == "Check for updates") {
} else if (strcmp(setting.name, "Check for updates") == 0) {
xSemaphoreTake(renderingMutex, portMAX_DELAY);
exitActivity();
enterNewActivity(new OtaUpdateActivity(renderer, mappedInput, [this] {