Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AppsPlugin: add switch to ignore XDG OnlyShowIn Desktop Attr #29

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions catapult/plugins/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,37 @@
import re

from catapult.api import Plugin
from catapult.api import PreferencesItem
from catapult.api import get_desktop_environment
from catapult.api import SearchResult
from catapult.i18n import _
from gi.repository import Gio
from gi.repository import Gtk


class AppsPluginPrefs(PreferencesItem):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
desktop = get_desktop_environment() or _("native")
label = _("Show non-{} apps").format(desktop)
self.label = Gtk.Label(label=label)
self.widget = Gtk.Switch()

def dump(self, window):
value = self.conf.ignore_only_show_in
self.widget.set_active(value)

def load(self, window):
value = self.widget.get_active()
self.conf.ignore_only_show_in = value


class AppsPlugin(Plugin):

title = _("Apps")
conf_defaults = {"ignore_only_show_in": False}
preferences_items = [AppsPluginPrefs]

def __init__(self):
super().__init__()
Expand Down Expand Up @@ -54,7 +78,8 @@ def launch(self, window, id):
def _list_apps(self):
key = lambda x: x.get_filename().lower()
for app in sorted(Gio.AppInfo.get_all(), key=key):
if not app.should_show(): continue
if not self.conf.ignore_only_show_in:
if not app.should_show(): continue
id = app.get_id()
if id == "io.otsaloma.catapult.desktop": continue
yield id, app
Expand Down Expand Up @@ -84,4 +109,4 @@ def search(self, query):
def update(self):
self.debug("Updating index...")
self._index = dict(self._list_apps())
self.debug(f"{len(self._index)} items in index")
self.debug(f"{len(self._index)} items in index")
Loading