Skip to content

Commit

Permalink
⚙️ Improve settings parsing, add reload option (#10)
Browse files Browse the repository at this point in the history
This change makes settings parsing more resilient to errors and adds a
"reload" option to the system tray menu to allow for loading settings
changes without restarting the process.
  • Loading branch information
haydenmc authored Jul 21, 2024
1 parent fb87d97 commit 328d17e
Show file tree
Hide file tree
Showing 6 changed files with 279 additions and 72 deletions.
39 changes: 27 additions & 12 deletions src/FlashCom/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,31 @@
namespace
{
const std::unordered_set<uint32_t> c_hotkeyCombo{ VK_LWIN, VK_SPACE };

std::unique_ptr<FlashCom::Models::DataModel> CreateDataModel(
FlashCom::Settings::SettingsManager& settingsManager)
{

auto rootNode{ settingsManager.GetTree() };

return std::make_unique<FlashCom::Models::DataModel>(
std::move(rootNode));
}
}

namespace FlashCom
{
#pragma region Public
std::unique_ptr<App> App::CreateApp(const HINSTANCE& hInstance)
{
return std::unique_ptr<App>(new App(hInstance));
std::unique_ptr<App> app{ new App(hInstance) };
app->LoadDataModel();
return app;
}

void App::LoadDataModel()
{
auto result{ m_settingsManager.LoadSettings() };
m_dataModel->RootNode = m_settingsManager.GetCommandTreeRoot();
m_dataModel->CurrentNode = m_dataModel->RootNode.get();
if (!result.has_value())
{
m_dataModel->LoadErrorMessage = result.error();
}
else
{
m_dataModel->LoadErrorMessage = "";
}
}

int App::RunMessageLoop()
Expand Down Expand Up @@ -121,10 +128,11 @@ namespace FlashCom
#pragma endregion Public
#pragma region Private
App::App(const HINSTANCE& hInstance) :
m_dataModel{ std::move(CreateDataModel(m_settingsManager)) },
m_dataModel{ std::make_unique<FlashCom::Models::DataModel>() },
m_hostWindow{ hInstance, L"FlashCom", std::bind(&App::HandleFocusLost, this) },
m_trayIcon{ hInstance, {
std::make_pair(std::wstring{ L"Settings" }, std::bind(&App::OnSettingsCommand, this)),
std::make_pair(std::wstring{ L"Reload" }, std::bind(&App::OnReloadCommand, this)),
std::make_pair(std::wstring{ L"Exit" }, std::bind(&App::OnExitCommand, this))
} },
m_ui{ m_hostWindow, m_dataModel.get() }
Expand Down Expand Up @@ -189,6 +197,13 @@ namespace FlashCom
nullptr, nullptr, SW_SHOWNORMAL);
}

void App::OnReloadCommand()
{
SPDLOG_INFO("App::OnReloadCommand");
LoadDataModel();
m_ui.Update();
}

void App::OnExitCommand()
{
SPDLOG_INFO("App::OnExitCommand");
Expand Down
2 changes: 2 additions & 0 deletions src/FlashCom/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace FlashCom
struct App
{
static std::unique_ptr<App> CreateApp(const HINSTANCE& hInstance);
void LoadDataModel();
int RunMessageLoop();
FlashCom::Input::LowLevelCallbackReturnKind HandleLowLevelKeyboardInput(
WPARAM wParam, KBDLLHOOKSTRUCT* kb);
Expand All @@ -36,6 +37,7 @@ namespace FlashCom
void Show();
void Hide();
void OnSettingsCommand();
void OnReloadCommand();
void OnExitCommand();
};
}
7 changes: 1 addition & 6 deletions src/FlashCom/Models/DataModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@
#include "DataModel.h"

namespace FlashCom::Models
{
DataModel::DataModel(std::unique_ptr<TreeNode>&& rootNode) :
RootNode{ std::move(rootNode) },
CurrentNode{ RootNode.get() }
{ }
}
{ }
6 changes: 2 additions & 4 deletions src/FlashCom/Models/DataModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ namespace FlashCom::Models
{
struct DataModel
{
DataModel(std::unique_ptr<TreeNode>&& rootNode);
DataModel(DataModel&& other) = default;

const std::unique_ptr<TreeNode> RootNode;
std::string LoadErrorMessage;
std::shared_ptr<TreeNode> RootNode;
TreeNode* CurrentNode{ nullptr };
};
}
Loading

0 comments on commit 328d17e

Please sign in to comment.