Fixed hotkey issues (#757)

* Fix an issue where some hotkeys reset when loading

* Fix the 'Clear' button in the hotkeys not working
This commit is contained in:
daobashun
2025-12-17 22:53:46 +08:00
committed by GitHub
parent 75d6a798e0
commit a401972223
3 changed files with 13 additions and 5 deletions
+10 -4
View File
@@ -142,11 +142,17 @@ namespace YimMenu
void HotkeySystem::SaveStateImpl(nlohmann::json& state)
{
for (auto& hotkey : m_CommandHotkeys)
for (const auto& hotkey : m_CommandHotkeys)
{
std::string key = std::to_string(hotkey.first);
if (!hotkey.second.m_Chain.empty())
{
state[std::to_string(hotkey.first).data()] = hotkey.second.m_Chain;
state[key] = hotkey.second.m_Chain;
}
else if (state.contains(key))
{
state.erase(key);
}
}
}
@@ -155,8 +161,8 @@ namespace YimMenu
{
for (auto& [key, value] : state.items())
{
if (m_CommandHotkeys.contains(std::atoi(key.data())))
m_CommandHotkeys[std::atoi(key.data())].m_Chain = value.get<std::vector<int>>();
if (m_CommandHotkeys.contains(static_cast<uint32_t>(std::stoul(key.data()))))
m_CommandHotkeys[static_cast<uint32_t>(std::stoul(key.data()))].m_Chain = value.get<std::vector<int>>();
}
}
+1 -1
View File
@@ -16,7 +16,7 @@ namespace YimMenu
public IStateSerializer
{
std::chrono::system_clock::time_point m_LastHotkeyTriggerTime;
bool m_BeingModified;
bool m_BeingModified = false;
public:
HotkeySystem();
+2
View File
@@ -35,6 +35,8 @@ namespace YimMenu::Submenus
for (auto& [name, link] : sortedCommands)
{
if (name.empty())
continue;
DrawHotkey(link, name);
}
};