Skip to content

Commit

Permalink
Spices.py: catch some possible exceptions when loading legacy
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mtwebster committed Dec 12, 2023
1 parent 64e09e4 commit ad7328c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ad7328c

Please sign in to comment.