From ad7328cec176cfdab0d2b2acd0294bd87728e8ff Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Mon, 11 Dec 2023 23:42:23 -0500 Subject: [PATCH] Spices.py: catch some possible exceptions when loading legacy actions. - Ignore invalid keyfiles. - The Comment (tooltip) is optional for actions. - Use the action's icon if there is one. - Remove mnemonic underscores for display. --- .../cinnamon/cinnamon-settings/bin/Spices.py | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py b/files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py index 7d5a295558..10d99bd93f 100644 --- a/files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py +++ b/files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py @@ -449,7 +449,12 @@ def _load_metadata(self): # A singular .nemo_action file has been detected metadata = dict() keyfile = GLib.KeyFile.new() - keyfile.load_from_file(full_path, GLib.KeyFileFlags.KEEP_TRANSLATIONS) + + try: + keyfile.load_from_file(full_path, GLib.KeyFileFlags.KEEP_TRANSLATIONS) + except GLib.Error as e: + print("Could not read action file '%s': %s" % (full_path,e.message)) + continue try: # The Active key is not typically used, but there are some inactive actions @@ -460,8 +465,21 @@ def _load_metadata(self): if e.code == GLib.KeyFileError.NOT_FOUND: pass - metadata['name'] = keyfile.get_locale_string('Nemo Action', 'Name') - metadata['description'] = keyfile.get_locale_string('Nemo Action', 'Comment') + name = keyfile.get_locale_string('Nemo Action', 'Name') + metadata['name'] = name.replace("_", "") + + try: + metadata['description'] = keyfile.get_locale_string('Nemo Action', 'Comment') + except GLib.Error as e: + if e.code == GLib.KeyFileError.NOT_FOUND: + pass + + try: + metadata['icon'] = keyfile.get_string('Nemo Action', 'Icon-Name') + except GLib.Error as e: + if e.code == GLib.KeyFileError.NOT_FOUND: + pass + metadata['writable'] = False metadata['disable_about'] = True metadata['path'] = self.install_folder