Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(
SkipCompilationKey,
EffectToggleKey,
OverlayToggleKey,
FirstTimeSetupCompleted,
Theme)

bool IsEnabled = false;
Expand Down
1 change: 1 addition & 0 deletions src/Menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
80 changes: 10 additions & 70 deletions src/Menu/HomePageRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
#include "HomePageRenderer.h"
#include "PCH.h"

#include <filesystem>
#include <format>
#include <fstream>
#include <imgui.h>
#include <nlohmann/json.hpp>
#include <ranges>
#include <sstream>

#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;

Expand Down Expand Up @@ -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
Expand All @@ -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
}
1 change: 0 additions & 1 deletion src/Menu/HomePageRenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <functional>
#include <string>

class HomePageRenderer
Expand Down
5 changes: 0 additions & 5 deletions src/Utils/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
6 changes: 0 additions & 6 deletions src/Utils/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down