Centralize retained preference keys
This commit is contained in:
@@ -298,6 +298,9 @@ agent or engineer to remove them without reconstructing context from chat.
|
|||||||
- 2026-06-12: DEBT-0045/0046/0052/0058 were narrowed again. The retained
|
- 2026-06-12: DEBT-0045/0046/0052/0058 were narrowed again. The retained
|
||||||
preference storage header now exposes only named snapshots/operations; generic
|
preference storage header now exposes only named snapshots/operations; generic
|
||||||
key/value helpers are local to `src/legacy_preference_storage.cpp`.
|
key/value helpers are local to `src/legacy_preference_storage.cpp`.
|
||||||
|
- 2026-06-12: DEBT-0045/0046/0052/0058 were narrowed again. Retained preference
|
||||||
|
keys are centralized as local constants inside `src/legacy_preference_storage.cpp`,
|
||||||
|
with all typed legacy `Settings` calls routed through local helper functions.
|
||||||
- 2026-06-05: DEBT-0056 was narrowed. `src/asset.h` no longer exposes Android
|
- 2026-06-05: DEBT-0056 was narrowed. `src/asset.h` no longer exposes Android
|
||||||
SDK types or forward declarations; retained Android asset-manager and asset
|
SDK types or forward declarations; retained Android asset-manager and asset
|
||||||
handles are stored as opaque pointers and cast only inside `src/asset.cpp`,
|
handles are stored as opaque pointers and cast only inside `src/asset.cpp`,
|
||||||
|
|||||||
@@ -8,11 +8,83 @@
|
|||||||
namespace pp::panopainter {
|
namespace pp::panopainter {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr const char* kRunCounterKey = "run_counter";
|
||||||
|
constexpr const char* kAutoTimelapseKey = "auto-timelapse";
|
||||||
|
constexpr const char* kVrControllersEnabledKey = "vr-controllers-enabled";
|
||||||
|
constexpr const char* kViewportScaleKey = "vp-scale";
|
||||||
|
constexpr const char* kShowCursorKey = "show-cursor";
|
||||||
|
constexpr const char* kUiRightToLeftKey = "ui-rtl";
|
||||||
|
constexpr const char* kUiStateKey = "ui";
|
||||||
|
constexpr const char* kUiScaleKey = "ui-scale";
|
||||||
|
constexpr const char* kWindowShowCommandKey = "window-show-cmd";
|
||||||
|
constexpr const char* kWindowRectKey = "window-rect";
|
||||||
|
constexpr const char* kWhatsNewIdKey = "whatsnew-id";
|
||||||
|
|
||||||
|
bool has_legacy_preference_key(const char* key)
|
||||||
|
{
|
||||||
|
return Settings::has(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
int read_legacy_integer_preference(const char* key)
|
||||||
|
{
|
||||||
|
return Settings::value<Serializer::Integer>(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
int read_legacy_integer_preference_or(const char* key, int default_value)
|
||||||
|
{
|
||||||
|
return Settings::value_or<Serializer::Integer>(key, default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
float read_legacy_float_preference(const char* key)
|
||||||
|
{
|
||||||
|
return Settings::value<Serializer::Float>(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
float read_legacy_float_preference_or(const char* key, float default_value)
|
||||||
|
{
|
||||||
|
return Settings::value_or<Serializer::Float>(key, default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool read_legacy_boolean_preference_or(const char* key, bool default_value)
|
||||||
|
{
|
||||||
|
return Settings::value_or<Serializer::Boolean>(key, default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::ivec4 read_legacy_ivec4_preference(const char* key)
|
||||||
|
{
|
||||||
|
return Settings::value<Serializer::IVec4>(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Serializer::Descriptor> read_legacy_descriptor_preference(const char* key)
|
||||||
|
{
|
||||||
|
return Settings::get<Serializer::Descriptor>(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_legacy_integer_preference(const char* key, int value)
|
||||||
|
{
|
||||||
|
Settings::set(key, Serializer::Integer(value));
|
||||||
|
}
|
||||||
|
|
||||||
void set_legacy_boolean_preference(const char* key, bool value)
|
void set_legacy_boolean_preference(const char* key, bool value)
|
||||||
{
|
{
|
||||||
Settings::set(key, Serializer::Boolean(value));
|
Settings::set(key, Serializer::Boolean(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_legacy_float_preference(const char* key, float value)
|
||||||
|
{
|
||||||
|
Settings::set(key, Serializer::Float(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_legacy_ivec4_preference(const char* key, const glm::ivec4& value)
|
||||||
|
{
|
||||||
|
Settings::set(key, Serializer::IVec4(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_legacy_descriptor_preference(const char* key, const Serializer::Descriptor& value)
|
||||||
|
{
|
||||||
|
Settings::set(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
void save_legacy_boolean_preference(const char* key, bool value)
|
void save_legacy_boolean_preference(const char* key, bool value)
|
||||||
{
|
{
|
||||||
set_legacy_boolean_preference(key, value);
|
set_legacy_boolean_preference(key, value);
|
||||||
@@ -21,7 +93,7 @@ void save_legacy_boolean_preference(const char* key, bool value)
|
|||||||
|
|
||||||
void save_legacy_float_preference(const char* key, float value)
|
void save_legacy_float_preference(const char* key, float value)
|
||||||
{
|
{
|
||||||
Settings::set(key, Serializer::Float(value));
|
set_legacy_float_preference(key, value);
|
||||||
Settings::save();
|
Settings::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,100 +107,100 @@ bool load_legacy_preferences()
|
|||||||
LegacyStartupPreferenceSnapshot read_legacy_startup_preferences(bool default_vr_controllers_enabled)
|
LegacyStartupPreferenceSnapshot read_legacy_startup_preferences(bool default_vr_controllers_enabled)
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Settings::value<Serializer::Integer>("run_counter"),
|
read_legacy_integer_preference(kRunCounterKey),
|
||||||
Settings::value_or<Serializer::Boolean>("auto-timelapse", true),
|
read_legacy_boolean_preference_or(kAutoTimelapseKey, true),
|
||||||
Settings::value_or<Serializer::Boolean>("vr-controllers-enabled", default_vr_controllers_enabled),
|
read_legacy_boolean_preference_or(kVrControllersEnabledKey, default_vr_controllers_enabled),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
LegacyCanvasPreferenceSnapshot read_legacy_canvas_preferences()
|
LegacyCanvasPreferenceSnapshot read_legacy_canvas_preferences()
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
Settings::value_or<Serializer::Float>("vp-scale", 1.0F),
|
read_legacy_float_preference_or(kViewportScaleKey, 1.0F),
|
||||||
Settings::value_or<Serializer::Integer>("show-cursor", 0),
|
read_legacy_integer_preference_or(kShowCursorKey, 0),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
LegacyUiPreferenceSnapshot read_legacy_ui_preferences()
|
LegacyUiPreferenceSnapshot read_legacy_ui_preferences()
|
||||||
{
|
{
|
||||||
LegacyUiPreferenceSnapshot snapshot;
|
LegacyUiPreferenceSnapshot snapshot;
|
||||||
snapshot.has_rtl = Settings::has("ui-rtl");
|
snapshot.has_rtl = has_legacy_preference_key(kUiRightToLeftKey);
|
||||||
if (snapshot.has_rtl)
|
if (snapshot.has_rtl)
|
||||||
snapshot.rtl = Settings::value<Serializer::Integer>("ui-rtl");
|
snapshot.rtl = read_legacy_integer_preference(kUiRightToLeftKey);
|
||||||
if (Settings::has("ui"))
|
if (has_legacy_preference_key(kUiStateKey))
|
||||||
snapshot.state = Settings::get<Serializer::Descriptor>("ui");
|
snapshot.state = read_legacy_descriptor_preference(kUiStateKey);
|
||||||
return snapshot;
|
return snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
LegacyWindowPreferenceSnapshot read_legacy_window_preferences(int default_show_command)
|
LegacyWindowPreferenceSnapshot read_legacy_window_preferences(int default_show_command)
|
||||||
{
|
{
|
||||||
LegacyWindowPreferenceSnapshot snapshot;
|
LegacyWindowPreferenceSnapshot snapshot;
|
||||||
snapshot.has_ui_scale = Settings::has("ui-scale");
|
snapshot.has_ui_scale = has_legacy_preference_key(kUiScaleKey);
|
||||||
if (snapshot.has_ui_scale)
|
if (snapshot.has_ui_scale)
|
||||||
snapshot.ui_scale = Settings::value<Serializer::Float>("ui-scale");
|
snapshot.ui_scale = read_legacy_float_preference(kUiScaleKey);
|
||||||
snapshot.show_command = Settings::value_or<Serializer::Integer>("window-show-cmd", default_show_command);
|
snapshot.show_command = read_legacy_integer_preference_or(kWindowShowCommandKey, default_show_command);
|
||||||
snapshot.has_window_rect = Settings::has("window-rect");
|
snapshot.has_window_rect = has_legacy_preference_key(kWindowRectKey);
|
||||||
if (snapshot.has_window_rect)
|
if (snapshot.has_window_rect)
|
||||||
snapshot.window_rect = Settings::value<Serializer::IVec4>("window-rect");
|
snapshot.window_rect = read_legacy_ivec4_preference(kWindowRectKey);
|
||||||
return snapshot;
|
return snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_legacy_ui_scale_preference(float scale)
|
void save_legacy_ui_scale_preference(float scale)
|
||||||
{
|
{
|
||||||
Settings::set("ui-scale", Serializer::Float(scale));
|
set_legacy_float_preference(kUiScaleKey, scale);
|
||||||
Settings::save();
|
Settings::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_legacy_ui_state_preferences(const Serializer::Descriptor& state, bool right_to_left)
|
void set_legacy_ui_state_preferences(const Serializer::Descriptor& state, bool right_to_left)
|
||||||
{
|
{
|
||||||
Settings::set("ui", state);
|
set_legacy_descriptor_preference(kUiStateKey, state);
|
||||||
Settings::set("ui-rtl", Serializer::Boolean(right_to_left));
|
set_legacy_boolean_preference(kUiRightToLeftKey, right_to_left);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_legacy_window_preferences(int show_command, const glm::ivec4& window_rect)
|
void set_legacy_window_preferences(int show_command, const glm::ivec4& window_rect)
|
||||||
{
|
{
|
||||||
Settings::set("window-show-cmd", Serializer::Integer(show_command));
|
set_legacy_integer_preference(kWindowShowCommandKey, show_command);
|
||||||
Settings::set("window-rect", Serializer::IVec4(window_rect));
|
set_legacy_ivec4_preference(kWindowRectKey, window_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
int legacy_whatsnew_id_or(int default_value)
|
int legacy_whatsnew_id_or(int default_value)
|
||||||
{
|
{
|
||||||
return Settings::value_or<Serializer::Integer>("whatsnew-id", default_value);
|
return read_legacy_integer_preference_or(kWhatsNewIdKey, default_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_legacy_whatsnew_id()
|
void clear_legacy_whatsnew_id()
|
||||||
{
|
{
|
||||||
Settings::unset("whatsnew-id");
|
Settings::unset(kWhatsNewIdKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_legacy_whatsnew_id(int page_id)
|
void set_legacy_whatsnew_id(int page_id)
|
||||||
{
|
{
|
||||||
Settings::set("whatsnew-id", Serializer::Integer(page_id));
|
set_legacy_integer_preference(kWhatsNewIdKey, page_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_legacy_startup_run_counter(int value)
|
void set_legacy_startup_run_counter(int value)
|
||||||
{
|
{
|
||||||
Settings::set("run_counter", Serializer::Integer(value));
|
set_legacy_integer_preference(kRunCounterKey, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_legacy_vr_controllers_enabled(bool enabled)
|
void save_legacy_vr_controllers_enabled(bool enabled)
|
||||||
{
|
{
|
||||||
save_legacy_boolean_preference("vr-controllers-enabled", enabled);
|
save_legacy_boolean_preference(kVrControllersEnabledKey, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_legacy_auto_timelapse_enabled(bool enabled)
|
void save_legacy_auto_timelapse_enabled(bool enabled)
|
||||||
{
|
{
|
||||||
save_legacy_boolean_preference("auto-timelapse", enabled);
|
save_legacy_boolean_preference(kAutoTimelapseKey, enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_legacy_canvas_viewport_density(float density)
|
void save_legacy_canvas_viewport_density(float density)
|
||||||
{
|
{
|
||||||
save_legacy_float_preference("vp-scale", density);
|
save_legacy_float_preference(kViewportScaleKey, density);
|
||||||
}
|
}
|
||||||
|
|
||||||
void save_legacy_canvas_cursor_mode(int mode)
|
void save_legacy_canvas_cursor_mode(int mode)
|
||||||
{
|
{
|
||||||
Settings::set("show-cursor", Serializer::Integer(mode));
|
set_legacy_integer_preference(kShowCursorKey, mode);
|
||||||
Settings::save();
|
Settings::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user