feat(mcp): restore MCP service with display charging toggle
- Restore MCP system (McpSystem 1900+ LOC, McpHandler, McpScreensaver, McpSettings, McpOverride apps) - Use audio-stream instead of direct I2S for MP3 playback (fixes fast playback, uses native resampler) - Register McpSettings + McpOverride in Tactility.cpp so Settings shows MCP Screen - DisplaySettings: add ScreensaverType::McpScreen and disableScreensaverWhenCharging flag - Display app: add 'Disable on charging' toggle, handles McpScreen screensaver type - DisplayIdle: skip screensaver while charging, support McpScreen screensaver, isDeviceCharging check via PowerDevice - WebServer: coexistence with MCP (McpHandler) - Avoid formatting churn from previous commits Squashed from range eaa248b0..8970143f (6 commits) into single clean commit
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#include <Tactility/settings/McpSettings.h>
|
||||
#include <Tactility/file/PropertiesFile.h>
|
||||
#include <Tactility/file/File.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
constexpr auto* TAG = "McpSettings";
|
||||
#include <Tactility/Paths.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace tt::settings::mcp {
|
||||
|
||||
|
||||
static std::string getSettingsFilePath() {
|
||||
return getUserDataPath() + "/settings/mcp.properties";
|
||||
}
|
||||
|
||||
constexpr auto* KEY_MCP_ENABLED = "mcpEnabled";
|
||||
|
||||
bool load(McpSettings& settings) {
|
||||
auto settings_path = getSettingsFilePath();
|
||||
if (!file::isFile(settings_path)) {
|
||||
return false;
|
||||
}
|
||||
std::map<std::string, std::string> map;
|
||||
if (!file::loadPropertiesFile(settings_path, map)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto mcp_enabled = map.find(KEY_MCP_ENABLED);
|
||||
settings.mcpEnabled = (mcp_enabled != map.end())
|
||||
? (mcp_enabled->second == "1" || mcp_enabled->second == "true")
|
||||
: false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
McpSettings getDefault() {
|
||||
return McpSettings{
|
||||
.mcpEnabled = false
|
||||
};
|
||||
}
|
||||
|
||||
McpSettings loadOrGetDefault() {
|
||||
McpSettings settings;
|
||||
if (!load(settings)) {
|
||||
settings = getDefault();
|
||||
if (!save(settings)) {
|
||||
LOG_W(TAG, "Failed to save default MCP settings");
|
||||
}
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
bool save(const McpSettings& settings) {
|
||||
std::map<std::string, std::string> map;
|
||||
map[KEY_MCP_ENABLED] = settings.mcpEnabled ? "true" : "false";
|
||||
|
||||
auto settings_path = getSettingsFilePath();
|
||||
if (!file::findOrCreateParentDirectory(settings_path, 0755)) {
|
||||
LOG_E(TAG, "Failed to create parent dir for %s", settings_path.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file::savePropertiesFile(settings_path, map)) {
|
||||
LOG_E(TAG, "Failed to save MCP settings to %s", settings_path.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user