Pass addon name to config edit hook (#2205)

* Pass addon name to config edit hook

* Deprecate old hook instead of replacing it
This commit is contained in:
Yoshi 2022-11-23 09:00:28 +01:00 committed by GitHub
parent 365c5e1fb2
commit 80598f12ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View file

@ -1601,7 +1601,13 @@ class ConfigEditor(QDialog):
def accept(self) -> None:
txt = self.form.editor.toPlainText()
txt = gui_hooks.addon_config_editor_will_save_json(txt)
txt = gui_hooks.addon_config_editor_will_update_json(txt, self.addon)
if gui_hooks.addon_config_editor_will_save_json.count() > 0:
print(
"The hook addon_config_editor_will_save_json is deprecated.\n"
"Use addon_config_editor_will_update_json instead."
)
txt = gui_hooks.addon_config_editor_will_save_json(txt)
try:
new_conf = json.loads(txt)
jsonschema.validate(new_conf, self.mgr._addon_schema(self.addon))

View file

@ -271,7 +271,7 @@ hooks = [
as possible, instead opting to append your own changes, e.g.:
def on_deck_browser_will_render_content(deck_browser, content):
content.stats += "\n<div>my html</div>"
content.stats += "\\n<div>my html</div>"
""",
),
# Deck options (legacy screen)
@ -1109,6 +1109,15 @@ gui_hooks.webview_did_inject_style_into_page.append(mytest)
name="addon_config_editor_will_save_json",
args=["text: str"],
return_type="str",
doc="""Deprecated. Use addon_config_editor_will_update_json instead.
Allows changing the text of the json configuration that was
received from the user before actually reading it. For
example, you can replace new line in strings by some "\\\\n".""",
),
Hook(
name="addon_config_editor_will_update_json",
args=["text: str", "addon: str"],
return_type="str",
doc="""Allows changing the text of the json configuration that was
received from the user before actually reading it. For
example, you can replace new line in strings by some "\\\\n".""",