Skip to content

Commit

Permalink
Add script action to refresh settings
Browse files Browse the repository at this point in the history
- Will remove unused settings from settings.xml in Kodi 20+
  • Loading branch information
MoojMidge committed Aug 4, 2024
1 parent 076f038 commit fe9f480
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 2 deletions.
8 changes: 8 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -1572,3 +1572,11 @@ msgstr ""
msgctxt "#30816"
msgid "List is empty.[CR][CR]Refresh from context menu or try again later."
msgstr ""

msgctxt "#30817"
msgid "Refresh settings.xml"
msgstr ""

msgctxt "#30818"
msgid "Are you sure you want to refresh settings.xml?"
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class XbmcContext(AbstractContext):
'purchases': 30622,
'recommendations': 30551,
'refresh': 30543,
'refresh.settings.confirm': 30818,
'related_videos': 30514,
'remove': 30108,
'removed': 30666,
Expand Down
44 changes: 43 additions & 1 deletion resources/lib/youtube_plugin/kodion/script_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
from .context import XbmcContext
from .network import get_client_ip_address, httpd_status
from .utils import rm_dir, validate_ip_address
from .utils import current_system_version, rm_dir, validate_ip_address


def _config_actions(context, action, *_args):
Expand Down Expand Up @@ -150,6 +150,48 @@ def _maintenance_actions(context, action, params):
targets[target]().clear()
ui.show_notification(localize('succeeded'))

elif action == 'refresh':
targets = {
'settings_xml': 'settings.xml',
}
path = targets.get(target)
if not path:
return

if target == 'settings_xml' and ui.on_yes_no_input(
context.get_name(), localize('refresh.settings.confirm')
):
if not current_system_version.compatible(20, 0):
ui.show_notification(localize('failed'))
return

import xml.etree.ElementTree as ET

path = xbmcvfs.translatePath(os.path.join(DATA_PATH, path))
xml = ET.parse(path)
settings = xml.getroot()

marker = settings.find('setting[@id="|end_settings_marker|"]')
if marker is None:
ui.show_notification(localize('failed'))
return

removed = 0
for setting in reversed(settings.findall('setting')):
if setting == marker:
break
settings.remove(setting)
removed += 1
else:
ui.show_notification(localize('failed'))
return

if removed:
xml.write(path)
ui.show_notification(localize('succeeded'))
else:
return

elif action == 'delete':
path = params.get('path')
targets = {
Expand Down
11 changes: 10 additions & 1 deletion resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,6 @@
<control format="action" type="button"/>
</setting>
</group>

<group id="3">
<setting id="kodion.maintain.reset.accessmanager" type="action" label="30580" help="">
<level>0</level>
Expand All @@ -1137,6 +1136,16 @@
<close>true</close>
</control>
</setting>
<setting id="kodion.maintain.refresh.settings" type="action" label="30817" help="">
<level>0</level>
<constraints>
<allowempty>true</allowempty>
</constraints>
<data>RunScript($ID,maintenance/refresh?target=settings_xml)</data>
<control format="action" type="button">
<close>true</close>
</control>
</setting>
</group>
<group id="4">
<setting id="kodion.maintain.delete.settings" type="action" label="30559" help="">
Expand Down

0 comments on commit fe9f480

Please sign in to comment.