From a57abb64488915521ac7cd9c569ed3a20fe2ece8 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 30 Oct 2022 14:11:33 +0100 Subject: [PATCH] AutoShiftConfig: Add a .disableAutoShiftIfUnconfigured() method The AutoShift plugin is enabled by default, but when using AutoShiftConfig, we may want to have it disabled by default, so that we can include it in firmware updates without turning optional, behaviour changing features on by default. The new method helps us accomplish this, in a way similar to how SpaceCadet accomplishes the same thing. Signed-off-by: Gergely Nagy --- .../src/kaleidoscope/plugin/AutoShift.h | 1 + .../src/kaleidoscope/plugin/AutoShiftConfig.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.h b/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.h index 99a1581fba..38d7c87911 100644 --- a/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.h +++ b/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShift.h @@ -276,6 +276,7 @@ class AutoShiftConfig : public Plugin { public: EventHandlerResult onSetup(); EventHandlerResult onFocusEvent(const char *input); + void disableAutoShiftIfUnconfigured(); private: // The base address in persistent storage for configuration data diff --git a/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShiftConfig.cpp b/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShiftConfig.cpp index bcc243dbb8..52cf851e0b 100644 --- a/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShiftConfig.cpp +++ b/plugins/Kaleidoscope-AutoShift/src/kaleidoscope/plugin/AutoShiftConfig.cpp @@ -45,6 +45,11 @@ EventHandlerResult AutoShiftConfig::onSetup() { return EventHandlerResult::OK; } +void AutoShiftConfig::disableAutoShiftIfUnconfigured() { + if (Runtime.storage().isSliceUninitialized(settings_base_, sizeof(AutoShift::settings_))) + ::AutoShift.disable(); +} + EventHandlerResult AutoShiftConfig::onFocusEvent(const char *input) { enum { ENABLED,