#!/usr/bin/env python3 """Plugin marketplace browser. Prints one JSON object. search [QUERY] [CATEGORY] [SORT] [OFFSET] [LIMIT] [VERIFIED_ONLY] [SOURCE] page of listings; SORT is popular | recent | name; SOURCE is omarchy (plugins.omarchy.org) or noctalia (noctalia-plugins registry) refresh download the catalog again The catalog and the registry's automated security review are cached in $XDG_CACHE_HOME/glassMxrph and refreshed every six hours. Installs use the commit the marketplace last validated, not the repository's current HEAD. """ import json, os, sys, time, urllib.request from pathlib import Path CATALOG_URL = 'https://plugins.omarchy.org/catalog.json' REGISTRY_URL = 'https://raw.githubusercontent.com/omacom/omarchy-plugin-marketplace/main/registry.json' SITE = 'https://plugins.omarchy.org/' CACHE = Path(os.environ.get('XDG_CACHE_HOME') or Path.home() / '.cache') / 'glassMxrph' INDEX = CACHE / 'omarchy-marketplace.json' NOCTALIA_REGISTRY = 'https://raw.githubusercontent.com/noctalia-dev/noctalia-plugins/main/registry.json' NOCTALIA_REPO = 'https://github.com/noctalia-dev/noctalia-plugins' NOCTALIA_INDEX = CACHE / 'noctalia-marketplace.json' MAX_AGE = 6 * 3600 # What glassMxrph can host today (see compat/omarchy). SUPPORT = {'Bar widget': 'supported', 'Panel': 'supported', 'Service': 'supported', 'Plugin': 'supported', 'Overlay': 'partial', 'Menu': 'partial', 'Bar': 'unsupported', 'Suite': 'unsupported'} def download(url): request = urllib.request.Request(url, headers={'User-Agent': 'glassMxrph'}) with urllib.request.urlopen(request, timeout=60) as response: return json.load(response) def build_index(): catalog = download(CATALOG_URL) review = {} try: for source in download(REGISTRY_URL).get('sources', []): baseline = source.get('automatedSecurityBaseline') or {} review[source.get('repo', '').rstrip('/').removesuffix('.git').lower()] = dict( outcome=baseline.get('outcome', ''), capabilities=baseline.get('capabilities', [])) except (OSError, ValueError): pass # The security review is extra detail; browsing works without it. items = [] for p in catalog.get('plugins', []): repo = p.get('repo', '') sec = review.get(repo.rstrip('/').removesuffix('.git').lower(), {}) kind = p.get('kind') or 'Plugin' builtin = p.get('id', '').startswith('omarchy.') items.append(dict( id=p.get('id', ''), name=p.get('name') or p.get('id', ''), description=p.get('description', ''), author=p.get('author', ''), version=p.get('version', ''), category=p.get('category', 'Other'), tags=p.get('tags', []), kind=kind, # Omarchy's own built-ins use the reserved omarchy.* ids and are not installable. support='unsupported' if builtin else SUPPORT.get(kind, 'partial'), stars=p.get('stars', 0) or 0, verified=p.get('verificationStatus') == 'verified', installable=bool(p.get('installAvailable')) and not builtin, note='Built into Omarchy' if builtin else p.get('installNote', ''), repo=repo, commit=p.get('upstreamValidatedCommit') or p.get('listingValidatedCommit') or '', manifestPath=p.get('manifestPath', ''), license=p.get('license', ''), accent=p.get('accent', ''), initials=p.get('initials', ''), updated=p.get('versionUpdatedAt') or p.get('repositoryUpdatedAt') or p.get('listedAt') or '', review=sec.get('outcome', ''), capabilities=sec.get('capabilities', []), page=SITE + '#' + p.get('id', ''))) CACHE.mkdir(parents=True, exist_ok=True) tmp = INDEX.with_suffix('.tmp') tmp.write_text(json.dumps(dict(fetchedAt=int(time.time()), items=items))) tmp.replace(INDEX) def build_noctalia_index(): """Noctalia v4's registry: one repository, a folder per plugin id.""" registry = download(NOCTALIA_REGISTRY) items = [] for p in registry.get('plugins', []): tags = p.get('tags') or [] items.append(dict( id=p.get('id', ''), name=p.get('name') or p.get('id', ''), description=p.get('description', ''), author=p.get('author', ''), version=p.get('version', ''), category=tags[0] if tags else 'Other', tags=tags, kind='Noctalia v4', support='partial', stars=0, verified=bool(p.get('official')), installable=True, note='Noctalia v4 plugin, run through the compatibility layer', repo=p.get('repository') or NOCTALIA_REPO, commit='', manifestPath=p.get('id', '') + '/manifest.json', license=p.get('license', ''), accent='', initials='', updated=p.get('lastUpdated', ''), review='', capabilities=[], official=bool(p.get('official')), page=NOCTALIA_REPO + '/tree/main/' + p.get('id', ''))) CACHE.mkdir(parents=True, exist_ok=True) tmp = NOCTALIA_INDEX.with_suffix('.tmp') tmp.write_text(json.dumps(dict(fetchedAt=int(time.time()), items=items))) tmp.replace(NOCTALIA_INDEX) def load(force=False, source='omarchy'): index, build = (NOCTALIA_INDEX, build_noctalia_index) if source == 'noctalia' else (INDEX, build_index) fresh = index.is_file() and time.time() - index.stat().st_mtime < MAX_AGE if force or not fresh: try: build() except (OSError, ValueError) as e: if not index.is_file(): raise stale = json.loads(index.read_text()) stale['warning'] = 'Showing the cached catalog: ' + str(e) return stale return json.loads(index.read_text()) def search(data, query, category, sort, offset, limit, verified_only): words = [w for w in query.lower().split() if w] items = data['items'] if category and category != 'all': items = [i for i in items if i['category'] == category] if verified_only: items = [i for i in items if i['verified']] if words: def score(i): hay = ' '.join([i['name'], i['id'], i['description'], i['author'], ' '.join(i['tags'])]).lower() if not all(w in hay for w in words): return -1 return sum(3 if w in i['name'].lower() else 1 for w in words) scored = [(score(i), i) for i in items] items = [i for s, i in sorted(scored, key=lambda x: (-x[0], -x[1]['stars'])) if s >= 0] elif sort == 'recent': items = sorted(items, key=lambda i: i['updated'], reverse=True) elif sort == 'name': items = sorted(items, key=lambda i: i['name'].lower()) else: items = sorted(items, key=lambda i: (i['verified'], i['stars']), reverse=True) categories = sorted({i['category'] for i in data['items']}) return dict(ok=True, total=len(items), offset=offset, items=items[offset:offset + limit], categories=categories, fetchedAt=data.get('fetchedAt', 0), warning=data.get('warning', '')) def main(): args = sys.argv[1:] or ['search'] try: if args[0] == 'refresh': data = load(force=True, source=args[1] if len(args) > 1 else 'omarchy') result = dict(ok=True, total=len(data['items']), fetchedAt=data.get('fetchedAt', 0)) else: get = lambda n, d: args[n] if len(args) > n and args[n] != '' else d result = search(load(source=get(7, 'omarchy')), get(1, ''), get(2, 'all'), get(3, 'popular'), int(get(4, '0')), min(100, int(get(5, '30'))), get(6, 'false') == 'true') except (OSError, ValueError) as e: result = dict(ok=False, error='Could not load the plugin catalog: ' + str(e), items=[], total=0, categories=[]) print(json.dumps(result)) if __name__ == '__main__': main()