364 std::unique_lock<std::mutex> lock(impl_->mutex_);
366 auto& s = impl_->appSettings_;
367 const std::string configPath = impl_->getSettingsFilePath();
368 const std::string statePath = impl_->getStateFilePath();
369 const std::string legacyJsonPath = impl_->getLegacySettingsFilePath();
370 const std::string legacyConfPath = impl_->getLegacyConfFilePath();
372 bool loadedAny =
false;
384 impl_->rawConfigJson_ = *cfg;
389 Logger::info(
"Settings (config) loaded from: {}", configPath);
398 impl_->rawStateJson_ = *st;
400 Logger::info(
"Settings (state) loaded from: {}", statePath);
406 impl_->dirty_ =
false;
427 Logger::info(
"Settings: migrating from legacy single-file location {} "
428 "to XDG split (config={}, state={}). Legacy file preserved "
429 "in case manual rollback is needed.",
430 legacyJsonPath, configPath, statePath);
442 impl_->rawConfigJson_ = *legacy;
443 impl_->rawStateJson_ = *legacy;
447 static constexpr const char* kConfigPanelStateKeys[] = {
448 "enableHomeAssistant",
451 static constexpr const char* kStatePanelStateKeys[] = {
452 "panelSidebarVisible",
"panelGamesVisible",
"panelDetailsVisible",
453 "panelMonitorVisible",
"panelHAVisible",
"splitterSizes",
454 "rememberWindowLayout",
"windowGeometry",
"windowState",
455 "lastViewMode",
"lastSidebarCategory",
"defaultLibraryView",
457 auto retainOnly = [](nlohmann::json& parent,
const char* objKey,
458 const char*
const* keepKeys,
size_t keepCount)
460 if (!parent.contains(objKey) || !parent[objKey].is_object())
462 nlohmann::json filtered = nlohmann::json::object();
463 for (
size_t i = 0; i < keepCount; ++i)
465 const char* k = keepKeys[i];
466 if (parent[objKey].contains(k))
467 filtered[k] = parent[objKey][k];
469 parent[objKey] = std::move(filtered);
471 retainOnly(impl_->rawConfigJson_,
"panelState", kConfigPanelStateKeys,
472 sizeof(kConfigPanelStateKeys) /
sizeof(kConfigPanelStateKeys[0]));
473 retainOnly(impl_->rawStateJson_,
"panelState", kStatePanelStateKeys,
474 sizeof(kStatePanelStateKeys) /
sizeof(kStatePanelStateKeys[0]));
476 for (
const char* k : {
"application",
"theme",
"gamingLayout"})
478 impl_->rawStateJson_.erase(k);
487 impl_->dirty_ =
true;
496 std::ifstream legacyFile(legacyConfPath);
497 if (!legacyFile.is_open())
503 Logger::info(
"Found legacy settings.conf, migrating to JSON format");
506 while (std::getline(legacyFile, line))
508 if (line.empty() || line[0] ==
'#' || line[0] ==
'[')
512 if (line.size() > 4096)
514 Logger::warn(
"Settings: Legacy config line too long ({}), skipping", line.size());
518 size_t pos = line.find(
'=');
519 if (pos == std::string::npos)
522 std::string key = line.substr(0, pos);
523 std::string value = line.substr(pos + 1);
526 if (key ==
"autoScan")
527 impl_->appSettings_.autoScan = (value ==
"1");
528 else if (key ==
"notifications")
529 impl_->appSettings_.notifications = (value ==
"1");
530 else if (key ==
"startMinimized")
531 impl_->appSettings_.startMinimized = (value ==
"1");
532 else if (key ==
"minimizeToTray")
533 impl_->appSettings_.minimizeToTray = (value ==
"1");
534 else if (key ==
"confirmDelete")
535 impl_->appSettings_.confirmDelete = (value ==
"1");
536 else if (key ==
"steamMinimized")
537 impl_->appSettings_.steamMinimized = (value ==
"1");
538 else if (key ==
"autoApplyDefaults")
539 impl_->appSettings_.autoApplyDefaults = (value ==
"1");
540 else if (key ==
"useSteamLaunchByDefault")
541 impl_->appSettings_.useSteamLaunchByDefault = (value ==
"1");
542 else if (key ==
"isolateMangoHudLogs")
543 impl_->appSettings_.isolateMangoHudLogs = (value ==
"1");
544 else if (key ==
"silentSteamSync")
545 impl_->appSettings_.silentSteamSync = (value ==
"1");
546 else if (key ==
"showToolbarGameStatus")
547 impl_->appSettings_.showToolbarGameStatus = (value ==
"1");
548 else if (key ==
"toolbarLocked")
549 impl_->appSettings_.toolbarLocked = (value ==
"1");
550 else if (key ==
"toolbarSearchWidth")
554 impl_->appSettings_.toolbarSearchWidth = std::clamp(std::stoi(value), 80, 300);
560 else if (key ==
"toolbarZoomWidth")
564 impl_->appSettings_.toolbarZoomWidth = std::clamp(std::stoi(value), 30, 100);
570 else if (key ==
"toolbarSectionOrder")
571 impl_->appSettings_.toolbarSectionOrder = value;
572 else if (key ==
"defaultRunner")
573 impl_->appSettings_.defaultRunner = value;
574 else if (key ==
"custom_scan_directories")
575 impl_->appSettings_.customScanDirectories = value;
576 else if (key ==
"game_launch_timeout_seconds")
580 impl_->appSettings_.gameLaunchTimeoutSeconds = std::clamp(std::stoi(value), 1, 300);
586 else if (key ==
"themeId")
587 impl_->appSettings_.themeId = value;
588 else if (key ==
"customAccentColor")
589 impl_->appSettings_.customAccentColor = value;
590 else if (key ==
"uiZoom")
594 impl_->appSettings_.uiZoom = std::clamp(std::stoi(value), 75, 150);
600 else if (key ==
"fontFamily")
601 impl_->appSettings_.fontFamily = value;
602 else if (key ==
"autoSwitchToRunningGame")
603 impl_->appSettings_.autoSwitchToRunningGame = (value ==
"1");
604 else if (key ==
"autoGamingLayout")
605 impl_->appSettings_.autoGamingLayout = (value ==
"1");
606 else if (key ==
"gamingLayoutWidthPercent")
610 impl_->appSettings_.gamingLayoutWidthPercent = std::clamp(std::stoi(value), 10, 50);
616 else if (key ==
"gamingLayoutEdge")
620 impl_->appSettings_.gamingLayoutEdge = std::clamp(std::stoi(value), 0, 2);
626 else if (key ==
"gamingLayoutFullHeight")
627 impl_->appSettings_.gamingLayoutFullHeight = (value ==
"1");
628 else if (key ==
"restoreLayoutOnExit")
629 impl_->appSettings_.restoreLayoutOnExit = (value ==
"1");
630 else if (key ==
"panelSidebarVisible")
631 impl_->appSettings_.panelSidebarVisible = (value ==
"1");
632 else if (key ==
"panelGamesVisible")
633 impl_->appSettings_.panelGamesVisible = (value ==
"1");
634 else if (key ==
"panelDetailsVisible")
635 impl_->appSettings_.panelDetailsVisible = (value ==
"1");
636 else if (key ==
"panelMonitorVisible")
637 impl_->appSettings_.panelMonitorVisible = (value ==
"1");
638 else if (key ==
"panelHAVisible")
639 impl_->appSettings_.panelHAVisible = (value ==
"1");
640 else if (key ==
"enableHomeAssistant")
641 impl_->appSettings_.enableHomeAssistant = (value ==
"1");
642 else if (key ==
"homeAssistantUrl")
644 if (value.size() > 7 &&
645 (value.compare(0, 7,
"http://") == 0 || value.compare(0, 8,
"https://") == 0))
646 impl_->appSettings_.homeAssistantUrl = value;
648 else if (key ==
"splitterSizes")
649 impl_->appSettings_.splitterSizes = value;
650 else if (key ==
"rememberWindowLayout")
651 impl_->appSettings_.rememberWindowLayout = (value ==
"1");
652 else if (key ==
"windowGeometry")
653 impl_->appSettings_.windowGeometry = value;
654 else if (key ==
"windowState")
655 impl_->appSettings_.windowState = value;
656 else if (key ==
"lastViewMode")
660 impl_->appSettings_.lastViewMode = std::clamp(std::stoi(value), 0, 2);
666 else if (key ==
"lastSidebarCategory")
670 impl_->appSettings_.lastSidebarCategory = std::max(0, std::stoi(value));
676 else if (key ==
"defaultLibraryView")
680 impl_->appSettings_.defaultLibraryView = std::clamp(std::stoi(value), -1, 6);
691 impl_->dirty_ =
true;
693 Logger::info(
"Legacy settings migrated from: {}", legacyConfPath);
704 std::unique_lock<std::mutex> lock(impl_->mutex_);
706 const std::string configPath = impl_->getSettingsFilePath();
707 const std::string statePath = impl_->getStateFilePath();
712 auto ensureDir = [](
const std::string& dir)
714 fs::path p = fs::path(dir).parent_path();
718 fs::create_directories(p, ec);
721 std::error_code permEc;
722 fs::permissions(p, fs::perms::owner_all, fs::perm_options::replace, permEc);
724 Logger::warn(
"Settings: could not chmod 0700 on {}: {}", p.string(),
728 ensureDir(configPath);
729 ensureDir(statePath);
731 const auto& s = impl_->appSettings_;
740 nlohmann::json cfg = impl_->rawConfigJson_;
741 if (!cfg.is_object())
742 cfg = nlohmann::json::object();
745 cfg[
"application"] = {{
"autoScan", s.autoScan},
746 {
"notifications", s.notifications},
747 {
"startMinimized", s.startMinimized},
748 {
"minimizeToTray", s.minimizeToTray},
749 {
"confirmDelete", s.confirmDelete},
750 {
"steamMinimized", s.steamMinimized},
751 {
"autoApplyDefaults", s.autoApplyDefaults},
752 {
"useSteamLaunchByDefault", s.useSteamLaunchByDefault},
753 {
"isolateMangoHudLogs", s.isolateMangoHudLogs},
754 {
"silentSteamSync", s.silentSteamSync},
755 {
"showToolbarGameStatus", s.showToolbarGameStatus},
756 {
"toolbarLocked", s.toolbarLocked},
757 {
"toolbarSearchWidth", s.toolbarSearchWidth},
758 {
"toolbarZoomWidth", s.toolbarZoomWidth},
759 {
"toolbarSectionOrder", s.toolbarSectionOrder},
760 {
"defaultRunner", s.defaultRunner},
761 {
"customScanDirectories", s.customScanDirectories},
762 {
"gameLaunchTimeoutSeconds", s.gameLaunchTimeoutSeconds}};
763 cfg[
"theme"] = {{
"themeId", s.themeId},
764 {
"customAccentColor", s.customAccentColor},
765 {
"uiZoom", s.uiZoom},
766 {
"fontFamily", s.fontFamily}};
767 cfg[
"gamingLayout"] = {{
"autoSwitchToRunningGame", s.autoSwitchToRunningGame},
768 {
"autoGamingLayout", s.autoGamingLayout},
769 {
"gamingLayoutWidthPercent", s.gamingLayoutWidthPercent},
770 {
"gamingLayoutEdge", s.gamingLayoutEdge},
771 {
"gamingLayoutFullHeight", s.gamingLayoutFullHeight},
772 {
"restoreLayoutOnExit", s.restoreLayoutOnExit}};
776 nlohmann::json haState = nlohmann::json::object();
777 if (cfg.contains(
"panelState") && cfg[
"panelState"].is_object())
778 haState = cfg[
"panelState"];
779 haState[
"enableHomeAssistant"] = s.enableHomeAssistant;
780 haState[
"homeAssistantUrl"] = s.homeAssistantUrl;
781 cfg[
"panelState"] = haState;
784 nlohmann::json st = impl_->rawStateJson_;
786 st = nlohmann::json::object();
789 nlohmann::json psState = nlohmann::json::object();
790 if (st.contains(
"panelState") && st[
"panelState"].is_object())
791 psState = st[
"panelState"];
792 psState[
"panelSidebarVisible"] = s.panelSidebarVisible;
793 psState[
"panelGamesVisible"] = s.panelGamesVisible;
794 psState[
"panelDetailsVisible"] = s.panelDetailsVisible;
795 psState[
"panelMonitorVisible"] = s.panelMonitorVisible;
796 psState[
"panelHAVisible"] = s.panelHAVisible;
797 psState[
"splitterSizes"] = s.splitterSizes;
798 psState[
"rememberWindowLayout"] = s.rememberWindowLayout;
799 psState[
"windowGeometry"] = s.windowGeometry;
800 psState[
"windowState"] = s.windowState;
801 psState[
"lastViewMode"] = s.lastViewMode;
802 psState[
"lastSidebarCategory"] = s.lastSidebarCategory;
803 psState[
"defaultLibraryView"] = s.defaultLibraryView;
804 st[
"panelState"] = psState;
812 auto serializedCfg = cfg.dump(2);
813 serializedCfg.push_back(
'\n');
814 auto serializedSt = st.dump(2);
815 serializedSt.push_back(
'\n');
820 Logger::error(
"Failed to save config to {}: {}", configPath, err);
825 Logger::error(
"Failed to save state to {}: {}", statePath, err);
831 impl_->rawConfigJson_ = cfg;
832 impl_->rawStateJson_ = st;
833 impl_->dirty_ =
false;
835 Logger::info(
"Settings saved (config={}, state={})", configPath, statePath);
1211 std::vector<std::string> versions;
1214 const char* home = std::getenv(
"HOME");
1218 std::vector<std::string> searchPaths = {
1219 std::string(home) +
"/.steam/steam/compatibilitytools.d",
1220 std::string(home) +
"/.local/share/Steam/compatibilitytools.d",
1221 "/usr/share/steam/compatibilitytools.d"};
1223 for (
const auto& searchPath : searchPaths)
1225 if (!fs::exists(searchPath))
1228 for (
const auto& entry : fs::directory_iterator(searchPath))
1230 if (entry.is_directory())
1232 std::string name = entry.path().filename().string();
1234 if (name.find(
"Proton") != std::string::npos ||
1235 name.find(
"proton") != std::string::npos ||
1236 name.find(
"GE-Proton") != std::string::npos)
1238 versions.push_back(name);
1245 std::vector<std::string> steamProtonPaths = {
1246 std::string(home) +
"/.steam/steam/steamapps/common",
1247 std::string(home) +
"/.local/share/Steam/steamapps/common"};
1249 for (
const auto& steamPath : steamProtonPaths)
1251 if (!fs::exists(steamPath))
1254 for (
const auto& entry : fs::directory_iterator(steamPath))
1256 if (entry.is_directory())
1258 std::string name = entry.path().filename().string();
1259 if (name.find(
"Proton") != std::string::npos)
1261 versions.push_back(name);
1268 std::sort(versions.begin(), versions.end());
1269 versions.erase(std::unique(versions.begin(), versions.end()), versions.end());