[FindMyMouse]Do not activate on game mode (#13990)

* [FindMyMouse] Do not activate on game mode

* Add settings scaffolding

* fix spellchecker

* Address PR comments

* Adress UI feedback
This commit is contained in:
Jaime Bernardo
2021-10-25 19:39:48 +01:00
committed by GitHub
parent db90802e6e
commit af8366f0fe
14 changed files with 248 additions and 12 deletions

View File

@@ -6,6 +6,14 @@
#include <thread>
#include <common/utils/logger_helper.h>
namespace
{
const wchar_t JSON_KEY_PROPERTIES[] = L"properties";
const wchar_t JSON_KEY_VALUE[] = L"value";
const wchar_t JSON_KEY_DO_NOT_ACTIVATE_ON_GAME_MODE[] = L"do_not_activate_on_game_mode";
}
extern "C" IMAGE_DOS_HEADER __ImageBase;
HMODULE m_hModule;
@@ -43,6 +51,9 @@ private:
// Load initial settings from the persisted values.
void init_settings();
// Helper function to extract the settings
void parse_settings(PowerToysSettings::PowerToyValues& settings);
public:
// Constructor
FindMyMouse()
@@ -96,6 +107,8 @@ public:
PowerToysSettings::PowerToyValues values =
PowerToysSettings::PowerToyValues::from_json_string(config, get_key());
parse_settings(values);
values.save_to_settings_file();
}
catch (std::exception&)
@@ -135,6 +148,7 @@ void FindMyMouse::init_settings()
// Load and parse the settings file for this PowerToy.
PowerToysSettings::PowerToyValues settings =
PowerToysSettings::PowerToyValues::load_from_settings_file(FindMyMouse::get_key());
parse_settings(settings);
}
catch (std::exception&)
{
@@ -142,6 +156,30 @@ void FindMyMouse::init_settings()
}
}
void FindMyMouse::parse_settings(PowerToysSettings::PowerToyValues& settings)
{
FindMyMouseSetDoNotActivateOnGameMode(true);
auto settingsObject = settings.get_raw_json();
if (settingsObject.GetView().Size())
{
try
{
auto jsonPropertiesObject = settingsObject.GetNamedObject(JSON_KEY_PROPERTIES).GetNamedObject(JSON_KEY_DO_NOT_ACTIVATE_ON_GAME_MODE);
FindMyMouseSetDoNotActivateOnGameMode((bool)jsonPropertiesObject.GetNamedBoolean(JSON_KEY_VALUE));
}
catch (...)
{
Logger::warn("Failed to get 'do not activate on game mode' setting");
}
}
else
{
Logger::info("Find My Mouse settings are empty");
}
}
extern "C" __declspec(dllexport) PowertoyModuleIface* __cdecl powertoy_create()
{
return new FindMyMouse();