diff --git a/src/Menu.cpp b/src/Menu.cpp index e05cb2f342..0f93d51913 100644 --- a/src/Menu.cpp +++ b/src/Menu.cpp @@ -112,6 +112,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT( SkipCompilationKey, EffectToggleKey, OverlayToggleKey, + FirstTimeSetupCompleted, Theme) bool IsEnabled = false; diff --git a/src/Menu.h b/src/Menu.h index 2715a5383d..ca9c31e6a5 100644 --- a/src/Menu.h +++ b/src/Menu.h @@ -208,6 +208,7 @@ class Menu uint32_t SkipCompilationKey = VK_ESCAPE; uint32_t EffectToggleKey = VK_MULTIPLY; // toggle all effects uint32_t OverlayToggleKey = VK_F10; // Global overlay toggle key for all overlays + bool FirstTimeSetupCompleted = false; // Track if first-time setup has been completed ThemeSettings Theme; }; const ThemeSettings& GetTheme() const { return settings.Theme; } // Provide read-only access to the Theme. diff --git a/src/Menu/HomePageRenderer.cpp b/src/Menu/HomePageRenderer.cpp index a5825db925..e3d63bfac9 100644 --- a/src/Menu/HomePageRenderer.cpp +++ b/src/Menu/HomePageRenderer.cpp @@ -1,25 +1,15 @@ #include "HomePageRenderer.h" #include "PCH.h" -#include -#include -#include #include -#include -#include -#include -#include "Feature.h" #include "Globals.h" #include "Menu.h" #include "Menu/ThemeManager.h" #include "Plugin.h" -#include "SettingsOverrideManager.h" #include "State.h" #include "Util.h" -using json = nlohmann::json; - // Static member definitions bool HomePageRenderer::isFirstTimeSetupShown = false; @@ -427,8 +417,8 @@ void HomePageRenderer::RenderFirstTimeSetupDialog() bool shouldClose = ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_Escape); if (ImGui::Button("Continue", ImVec2(continueButtonWidth, 30)) || shouldClose) { - // No need to apply any hotkey - user has already set it or it defaults to VK_END MarkFirstTimeSetupComplete(); + // Note: Settings are automatically saved to ensure welcome screen won't show again } // Center the help text @@ -453,70 +443,20 @@ bool HomePageRenderer::ShouldShowFirstTimeSetup() return false; } - // Check if first-time setup has been completed by looking at SettingsUser.json - std::filesystem::path userSettingsPath = Util::PathHelpers::GetUserSettingsPath(); - - // If SettingsUser.json doesn't exist at all, this is definitely a first-time launch - if (!std::filesystem::exists(userSettingsPath)) { - return true; - } - - // If SettingsUser.json exists, check if FirstTimeSetupCompleted flag is set - try { - std::ifstream file(userSettingsPath); - if (!file.is_open()) { - return true; // If we can't read the file, assume first time - } - - nlohmann::json settings; - file >> settings; - file.close(); - - // Check if FirstTimeSetupCompleted exists and is true - if (settings.contains("FirstTimeSetupCompleted") && - settings["FirstTimeSetupCompleted"].is_boolean() && - settings["FirstTimeSetupCompleted"] == true) { - return false; // Setup already completed - } - - return true; // Field doesn't exist or is false, show setup - - } catch (const std::exception&) { - // If there's any error reading the file, assume first time - return true; - } + // Check if first-time setup has been completed using the Menu settings + auto menu = Menu::GetSingleton(); + return !menu->GetSettings().FirstTimeSetupCompleted; } void HomePageRenderer::MarkFirstTimeSetupComplete() { - std::filesystem::path userSettingsPath = Util::PathHelpers::GetUserSettingsPath(); - - try { - nlohmann::json settings; - - // Read existing settings if file exists - if (std::filesystem::exists(userSettingsPath)) { - std::ifstream file(userSettingsPath); - if (file.is_open()) { - file >> settings; - file.close(); - } - } - - // Set the FirstTimeSetupCompleted flag - settings["FirstTimeSetupCompleted"] = true; - - // Write back to file - std::filesystem::create_directories(userSettingsPath.parent_path()); - std::ofstream outFile(userSettingsPath); - if (outFile.is_open()) { - outFile << settings.dump(2); - outFile.close(); - } + // Set the flag in the Menu settings + auto menu = Menu::GetSingleton(); + menu->GetSettings().FirstTimeSetupCompleted = true; - } catch (const std::exception&) { - // If we can't write the file, just mark as shown this session to avoid repeated popups - } + // Immediately save settings to ensure the flag is persisted + // This prevents the welcome screen from showing again even if user doesn't manually save + globals::state->Save(); isFirstTimeSetupShown = true; // Mark as shown this session } diff --git a/src/Menu/HomePageRenderer.h b/src/Menu/HomePageRenderer.h index aec34b4696..051e995095 100644 --- a/src/Menu/HomePageRenderer.h +++ b/src/Menu/HomePageRenderer.h @@ -1,6 +1,5 @@ #pragma once -#include #include class HomePageRenderer diff --git a/src/Utils/FileSystem.cpp b/src/Utils/FileSystem.cpp index 8db3322b15..247aa88a73 100644 --- a/src/Utils/FileSystem.cpp +++ b/src/Utils/FileSystem.cpp @@ -38,11 +38,6 @@ namespace Util return GetDataPath() / "SKSE" / "Plugins" / "CommunityShaders_ImGui.ini"; } - std::filesystem::path GetUserSettingsPath() - { - return GetCommunityShaderPath() / "SettingsUser.json"; - } - std::filesystem::path GetInterfacePath() { return GetDataPath() / "Interface" / "CommunityShaders"; diff --git a/src/Utils/FileSystem.h b/src/Utils/FileSystem.h index d9635307b8..f66e421097 100644 --- a/src/Utils/FileSystem.h +++ b/src/Utils/FileSystem.h @@ -44,12 +44,6 @@ namespace Util */ std::filesystem::path GetImGuiIniPath(); - /** - * Gets the SettingsUser.json file path - * @return CommunityShaderPath / "SettingsUser.json" - */ - std::filesystem::path GetUserSettingsPath(); - /** * Gets the CommunityShaders Interface directory path * @return Data / "Interface" / "CommunityShaders"