🐛 Partial revert of always sending SettingsUpdated event
It was causing a ton of issues with backend code using `Settings.save` to persist changes outside of REST API calls, triggering configuration update dialogs in the frontend way too often and when not needed. Added a flag instead to cause the `save` method to trigger an event and setting that to False by default. Settings REST API uses it, other callees in e.g. plugin code will be able to as well in the future if necessary. It would be cleaner to always trigger this event and adjust calling code and frontend code to compensate, but with third party plugins out there this is not going to happen reliably so we go this route.
This commit is contained in:
1 parent
33eba705bf
commit
55ec8b1809
4 files changed
+37
-6
No files matched your search
+20
-1
@@ -80,6 +80,8 @@ Available Events
|
||||
|
||||
Plugins may add additional events via the :ref:`octoprint.events.register_custom_events hook <sec-plugins-hook-events-register_custom_events>`.
|
||||
|
||||
.. _sec-events-available_events-server:
|
||||
|
||||
Server
|
||||
------
|
||||
|
||||
@@ -113,6 +115,8 @@ ConnectivityChanged
|
||||
* ``old``: Old connectivity value (true for online, false for offline)
|
||||
* ``new``: New connectivity value (true for online, false for offline)
|
||||
|
||||
.. _sec-events-available_events-printer_commmunication:
|
||||
|
||||
Printer communication
|
||||
---------------------
|
||||
|
||||
@@ -152,6 +156,8 @@ PrinterStateChanged
|
||||
:func:`~octoprint.printer.PrinterInterface.get_state_id` for possible values.
|
||||
* ``state_string``: Text representation of the new state.
|
||||
|
||||
.. _sec-events-available_events-file_handling:
|
||||
|
||||
File handling
|
||||
-------------
|
||||
|
||||
@@ -299,6 +305,8 @@ TransferDone
|
||||
* ``local``: the file's name as stored locally
|
||||
* ``remote``: the file's name as stored on SD
|
||||
|
||||
.. _sec-events-available_events-printing:
|
||||
|
||||
Printing
|
||||
--------
|
||||
|
||||
@@ -443,6 +451,8 @@ PrintResumed
|
||||
* ``file``: the file's full path on disk (``local``) or within its storage (``sdcard``). To be removed in 1.4.0.
|
||||
* ``filename``: the file's name. To be removed in 1.4.0.
|
||||
|
||||
.. _sec-events-available_events-gcode_processing:
|
||||
|
||||
GCODE processing
|
||||
----------------
|
||||
|
||||
@@ -504,6 +514,8 @@ ToolChange
|
||||
* ``old``: old tool index
|
||||
* ``new``: new tool index
|
||||
|
||||
.. _sec-events-available_events-timelapses:
|
||||
|
||||
Timelapses
|
||||
----------
|
||||
|
||||
@@ -558,6 +570,8 @@ MovieFailed
|
||||
returned a non-0 return code, ``no_frames`` if no frames were captured that could be rendered
|
||||
to a timelapse, or ``unknown`` for any other reason of failure to render.
|
||||
|
||||
.. _sec-events-available_events-slicing:
|
||||
|
||||
Slicing
|
||||
-------
|
||||
|
||||
@@ -629,8 +643,13 @@ SlicingProfileDeleted
|
||||
* ``slicer``: the slicer for which the profile was deleted
|
||||
* ``profile``: the profile that was deleted
|
||||
|
||||
.. _sec-events-available_events-settings:
|
||||
|
||||
Settings
|
||||
--------
|
||||
|
||||
SettingsUpdated
|
||||
The internal settings were updated.
|
||||
The settings were updated via the REST API.
|
||||
|
||||
This event may also be triggered if calling code of :py:class:`octoprint.settings.Settings.save` or
|
||||
:py:class:`octoprint.plugin.PluginSettings.save` sets the ``trigger_event`` parameter to ``True``.
|
||||
@@ -297,6 +297,17 @@ class PluginSettings(object):
|
||||
.. method:: set_boolean(path, value, force=False)
|
||||
|
||||
Like :func:`set` but ensures the value is an ``boolean`` through attempted conversion before setting it.
|
||||
|
||||
.. method:: save(force=False, trigger_event=False)
|
||||
|
||||
Saves the settings to ``config.yaml`` if there are active changes. If ``force`` is set to ``True`` the settings
|
||||
will be saved even if there are no changes. Settings ``trigger_event`` to ``True`` will cause a ``SettingsUpdated``
|
||||
:ref:`event <sec-events-available_events-settings>` to get triggered.
|
||||
|
||||
:param force: Force saving to ``config.yaml`` even if there are no changes.
|
||||
:type force: boolean
|
||||
:param trigger_event: Trigger the ``SettingsUpdated`` :ref:`event <sec-events-available_events-settings>` on save.
|
||||
:type trigger_event: boolean
|
||||
"""
|
||||
|
||||
def __init__(self, settings, plugin_key, defaults=None, get_preprocessors=None, set_preprocessors=None):
|
||||
|
||||
@@ -553,4 +553,4 @@ def _saveSettings(data):
|
||||
except:
|
||||
logger.exception("Could not save settings for plugin {name} ({version})".format(version=plugin._plugin_version, name=plugin._plugin_name))
|
||||
|
||||
s.save()
|
||||
s.save(trigger_event=True)
|
||||
@@ -1355,7 +1355,7 @@ class Settings(object):
|
||||
shutil.copy(self._configfile, backup)
|
||||
return backup
|
||||
|
||||
def save(self, force=False):
|
||||
def save(self, force=False, trigger_event=False):
|
||||
if not self._dirty and not force:
|
||||
return False
|
||||
|
||||
@@ -1372,9 +1372,10 @@ class Settings(object):
|
||||
|
||||
self.load()
|
||||
|
||||
payload = dict(config_hash=self.config_hash,
|
||||
effective_hash=self.effective_hash)
|
||||
eventManager().fire(Events.SETTINGS_UPDATED, payload=payload)
|
||||
if trigger_event:
|
||||
payload = dict(config_hash=self.config_hash,
|
||||
effective_hash=self.effective_hash)
|
||||
eventManager().fire(Events.SETTINGS_UPDATED, payload=payload)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
Reference in new issue
Block a user