Skip to content

Commit

Permalink
Update Actions module to show non-Spice Actions
Browse files Browse the repository at this point in the history
Manually installed Actions outside of the Spices structure will be
displayed with a lock icon and have the About and Uninstall buttons
disabled but have support for enabling/disabling from within the
module.
  • Loading branch information
rcalixte committed Dec 11, 2023
1 parent 21b8c3f commit 89e01ed
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 26 deletions.
21 changes: 12 additions & 9 deletions files/usr/bin/xlet-about-dialog
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class AboutDialog(Gtk.AboutDialog):
self.props.authors = self.metadata['contributors'].split(',')

xlet_name = self._(self.metadata.get('name'))
self.props.program_name = f"{xlet_name} ({self.metadata['uuid']})"
self.props.program_name = f"{xlet_name} ({self.metadata.get('uuid')})"

self.connect('response', self.close)
self.set_title(_("About %s") % self.props.program_name)
Expand All @@ -72,8 +72,8 @@ class AboutDialog(Gtk.AboutDialog):
self.set_default_icon_name(f"cs-{self.metadata['type']}")

def _(self, msg):
gettext.bindtextdomain(self.metadata['uuid'], home + '/.local/share/locale')
translation = gettext.dgettext(self.metadata['uuid'], msg)
gettext.bindtextdomain(self.metadata.get('uuid'), home + '/.local/share/locale')
translation = gettext.dgettext(self.metadata.get('uuid'), msg)
# try with cinnamon domain if the xlet domain doesn't work
if translation == msg:
return _(msg)
Expand Down Expand Up @@ -121,12 +121,15 @@ if __name__ == "__main__":
print(_('Unable to locate %s %s') % (xlet_type, uuid))
sys.exit(1)

with open(os.path.join(path, 'metadata.json'), encoding='utf-8') as meta:
_metadata = json.load(meta)
try:
with open(os.path.join(path, 'metadata.json'), encoding='utf-8') as meta:
_metadata = json.load(meta)

_metadata['path'] = path
_metadata['type'] = xlet_type
_metadata['path'] = path
_metadata['type'] = xlet_type

AboutDialog(_metadata, xlet_type)
AboutDialog(_metadata, xlet_type)

Gtk.main()
Gtk.main()
except FileNotFoundError:
pass
11 changes: 9 additions & 2 deletions files/usr/share/cinnamon/cinnamon-settings/bin/ExtensionCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def __init__(self, extension_type, metadata, size_groups):
except (KeyError, ValueError):
self.role = None

self.disabled_about = metadata.get('disable_about', False)

# Check for the right version subdir (if the spice is multi-versioned,
# it won't necessarily be in its root directory)
self.metadata['path'] = find_extension_subdir(self.metadata['path'])
Expand Down Expand Up @@ -307,6 +309,8 @@ def __init__(self, extension_type, metadata, size_groups):
self.add_status('locked', 'changes-prevent-symbolic', _("This is a system desklet. It cannot be removed."))
elif self.extension_type == "extension":
self.add_status('locked', 'changes-prevent-symbolic', _("This is a system extension. It cannot be removed."))
elif self.extension_type == "action":
self.add_status('locked', 'changes-prevent-symbolic', '')

if self.writable and self.extension_type != 'action':
self.scan_extension_for_danger(self.metadata['path'])
Expand Down Expand Up @@ -569,6 +573,9 @@ def update_button_states(self, *args):
self.uninstall_button.set_sensitive(row.writable)
self.about_button.set_sensitive(True)

if self.collection_type == 'action' and hasattr(row, 'disabled_about'):
self.about_button.set_sensitive(not row.disabled_about)

def add_instance(self, *args):
extension_row = self.list_box.get_selected_row()
self.enable_extension(extension_row.uuid, extension_row.name, extension_row.version_supported)
Expand Down Expand Up @@ -610,13 +617,13 @@ def restore_to_default(self, *args):

if show_prompt(msg, self.window):
gio_sett = 'org.nemo.plugins' if self.collection_type == 'action' else 'org.cinnamon'
sett = Gio.Settings.new(f'{gio_sett}')
sett = Gio.Settings.new(gio_sett)
if self.collection_type == 'action':
for uuid in self.spices.get_installed():
disableds = sett.get_strv('disabled-actions')
uuid_name = f'{uuid}.nemo_action'
if uuid_name in disableds:
disableds.remove(f'{uuid_name}')
disableds.remove(uuid_name)
sett.set_strv('disabled-actions', disableds)
self.spices.uninstall(uuid)
return
Expand Down
54 changes: 39 additions & 15 deletions files/usr/share/cinnamon/cinnamon-settings/bin/Spices.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/python3

import locale
import os
import sys

Expand Down Expand Up @@ -178,7 +179,7 @@ def __init__(self, collection_type, window=None):
self.spices_directories = (self.install_folder, old_install_folder)
elif self.actions:
self.install_folder = f'{home}/.local/share/nemo/actions/'
self.spices_directories = (self.install_folder, )
self.spices_directories = ('/usr/share/nemo/actions/', self.install_folder)
else:
self.install_folder = f'{home}/.local/share/cinnamon/{self.collection_type}s/'
self.spices_directories = (f'/usr/share/cinnamon/{self.collection_type}s/', self.install_folder)
Expand Down Expand Up @@ -209,7 +210,7 @@ def __init__(self, collection_type, window=None):
dbus_path = 'org.Nemo'
gsetting = '/org/Nemo'
Gio.DBusProxy.new_for_bus(Gio.BusType.SESSION, Gio.DBusProxyFlags.NONE, None,
f'{dbus_path}', f'{gsetting}', f'{dbus_path}', None, self._on_proxy_ready, None)
dbus_path, gsetting, dbus_path, None, self._on_proxy_ready, None)
except GLib.Error as e:
print(e)

Expand Down Expand Up @@ -436,23 +437,46 @@ def _load_metadata(self):
for file_path in self.spices_directories:
if os.path.exists(file_path):
extensions = os.listdir(file_path)
try:
language = locale.getlocale()[0].split("_")[0]
except:
language = ''

for uuid in extensions:
subdirectory = os.path.join(file_path, uuid)
if uuid.endswith('.nemo_action'):
if uuid == 'sample.nemo_action':
continue
full_path = os.path.join(file_path, uuid)
uuid_path = full_path.split('.nemo_action')[0]
if uuid.endswith('.nemo_action') and not os.path.exists(uuid_path):
# A singular .nemo_action file has been detected
metadata = dict()
keyfile = GLib.KeyFile.new()
keyfile.load_from_file(full_path, GLib.KeyFileFlags.KEEP_TRANSLATIONS)
metadata['name'] = keyfile.get_locale_string('Nemo Action', 'Name', language)
metadata['description'] = keyfile.get_locale_string('Nemo Action', 'Comment', language)
metadata['writable'] = False
metadata['disable_about'] = True
metadata['path'] = self.install_folder
_uuid = uuid.split('.nemo_action')[0]
metadata['uuid'] = _uuid
self.meta_map[_uuid] = metadata
elif os.path.isfile(full_path):
continue
# For actions, ignore any other normal files, an action may place other support scripts in here.
if self.actions and not os.path.isdir(subdirectory):
if self.actions and not os.path.isdir(full_path):
continue
try:
with open(f"{subdirectory}/metadata.json", encoding='utf-8') as json_data:
metadata = json.load(json_data)
metadata['path'] = subdirectory
metadata['writable'] = os.access(subdirectory, os.W_OK)
self.meta_map[uuid] = metadata
except Exception as error:
if not self.themes:
print(error)
print(f"Skipping {uuid}: there was a problem trying to read metadata.json")
else:
try:
# Process Actions installed via Spices
with open(f"{full_path}/metadata.json", encoding='utf-8') as json_data:
metadata = json.load(json_data)
metadata['path'] = full_path
metadata['writable'] = os.access(full_path, os.W_OK)
self.meta_map[uuid] = metadata
except Exception as error:
if not self.themes:
print(error)
print(f"Skipping {uuid}: there was a problem trying to read metadata.json")
else:
print(f"{file_path} does not exist! Skipping")

Expand Down

0 comments on commit 89e01ed

Please sign in to comment.