allow reset to defaults by changing version attribute

develop
Myk Taylor 2023-09-08 20:25:20 -07:00
parent 0bd0a82a3d
commit a061a418a1
No known key found for this signature in database
2 changed files with 8 additions and 0 deletions

@ -90,6 +90,10 @@ The ``overlay.OverlayWidget`` superclass defines the following class attributes:
This will be filled in with the display name of your widget, in case you
have multiple widgets with the same implementation but different
configurations.
- ``version``
You can set this to any string. If the version string of a loaded widget
does not match the saved settings for that widget, then the configuration
for the widget (position, enabled status) will be reset to defaults.
- ``default_pos`` (default: ``{x=-2, y=-2}``)
Override this attribute with your desired default widget position. See
the `overlay` docs for information on what positive and negative numbers

@ -261,7 +261,11 @@ local function load_widget(name, widget_class)
next_update_ms=widget.overlay_onupdate and 0 or math.huge,
}
if not overlay_config[name] then overlay_config[name] = {} end
if widget.version ~= overlay_config[name].version then
overlay_config[name] = {}
end
local config = overlay_config[name]
config.version = widget.version
if config.enabled == nil then
config.enabled = widget.default_enabled
end