repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

launcher: use native Quickshell DesktopEntries, drop python scanner

758f72fa220b8207234cee269350a863893e39d6

Oliver Jan Krylow <oliver@bugabinga.net> ·

unsigned

Browse filesCompare with HEAD

Replace the embedded python3 .desktop walker/parser with Quickshell's
DesktopEntries singleton (parses XDG entries, filters Hidden/NoDisplay,
dedupes by id natively). buildApps() maps DesktopEntry -> launcher rows;
apps becomes a reactive binding. Removes the only python dependency and
the Process/StdioCollector machinery.

Verified: appCount populates, search returns Firefox, launch fields map
to uwsm desktop-id form.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Changed files (1)

quickshell/nuguland/Launcher.qml

Modified
1 1 import QtQuick
2 2 import Quickshell
3 -import Quickshell.Io
5 4 Item {
6 5 id: root
32 31 "subtitle": "Use native niri color picker",
33 32 "route": "service"
35 - property var apps: []
36 - property bool appScanDone: false
37 - property string appScanError: ""
34 + // Apps come straight from Quickshell's native DesktopEntries singleton, which
35 + // already parses XDG desktop files, drops Hidden/NoDisplay, and dedupes by id.
36 + // The binding re-evaluates when the entry set changes.
37 + readonly property var apps: root.buildApps(DesktopEntries.applications ? DesktopEntries.applications.values : [])
38 + readonly property bool appScanDone: true
39 + readonly property string appScanError: ""
39 41 function normalize(text) {
40 42 return String(text || "").trim().toLowerCase();
503 - function desktopScanCode() {
504 - return `import json, os, re, shlex\n\ndef truth(value):\n return str(value or '').strip().lower() == 'true'\n\ndef clean_exec(value):\n return re.sub(r' ?%[fFuUdDnNickvm]', '', value or '').strip()\n\ndef parse_desktop(path):\n data = {}\n section = ''\n try:\n text = open(path, 'r', encoding='utf-8', errors='replace').read().splitlines()\n except OSError:\n return None\n for line in text:\n line = line.strip()\n if not line or line.startswith(('#', ';')):\n continue\n if line.startswith('[') and line.endswith(']'):\n section = line[1:-1]\n continue\n if section != 'Desktop Entry' or '=' not in line:\n continue\n key, value = line.split('=', 1)\n if '[' not in key and key not in data:\n data[key] = value\n if data.get('Type', 'Application') != 'Application':\n return None\n if truth(data.get('NoDisplay')) or truth(data.get('Hidden')):\n return None\n name = data.get('Name') or data.get('GenericName')\n if not name:\n return None\n base = os.path.basename(path)\n command = clean_exec(data.get('Exec', ''))\n try:\n argv = shlex.split(command)\n except ValueError:\n argv = []\n return {\n 'id': 'app:' + base,\n 'title': name,\n 'subtitle': data.get('Comment') or data.get('GenericName') or base,\n 'desktopId': base,\n 'desktopPath': path,\n 'exec': command,\n 'execArgv': argv,\n 'icon': data.get('Icon', ''),\n 'terminal': truth(data.get('Terminal')),\n 'route': 'desktop-entry'\n }\n\nroots = []\nhome = os.environ.get('XDG_DATA_HOME') or os.path.expanduser('~/.local/share')\nroots.append(home)\nroots.extend([p for p in os.environ.get('XDG_DATA_DIRS', '/usr/local/share:/usr/share').split(':') if p])\nseen = set()\napps = []\nfor root in roots:\n appdir = os.path.join(root, 'applications')\n if not os.path.isdir(appdir):\n continue\n for current, _, files in os.walk(appdir):\n for name in files:\n if not name.endswith('.desktop'):\n continue\n path = os.path.join(current, name)\n rel = os.path.relpath(path, appdir).replace(os.sep, '-')\n if rel in seen:\n continue\n row = parse_desktop(path)\n if not row:\n continue\n row['desktopId'] = rel\n row['id'] = 'app:' + rel\n seen.add(rel)\n apps.append(row)\napps.sort(key=lambda item: item['title'].casefold())\nprint(json.dumps(apps[:400], ensure_ascii=False))\n`;
505 - }
505 + // Map Quickshell DesktopEntry objects to the row shape the launcher consumes.
506 + // Exec field codes (%f, %u, …) are already stripped from `command` by Quickshell.
507 + function buildApps(entries) {
508 + const list = entries || [];
509 + const rows = [];
510 + for (let i = 0; i < list.length; i++) {
511 + const e = list[i];
512 + if (!e || !e.name)
513 + continue;
507 - function loadDesktopEntries() {
508 - if (appScan.running)
509 - return ;
511 - appScan.exec(["python3", "-c", desktopScanCode()]);
512 - }
514 - function applyDesktopEntries(text) {
515 - try {
516 - apps = JSON.parse(String(text || "[]"));
517 - appScanDone = true;
518 - appScanError = "";
519 - } catch (error) {
520 - appScanDone = true;
521 - appScanError = String(error);
522 - apps = [];
515 + const id = String(e.id || e.name);
516 + const argv = [];
517 + const command = e.command || [];
518 + for (let j = 0; j < command.length; j++) argv.push(String(command[j]));
519 + rows.push({
520 + "id": "app:" + id,
521 + "title": String(e.name),
522 + "subtitle": String(e.comment || e.genericName || id),
523 + "desktopId": id,
524 + // uwsm resolves the desktop id (with .desktop suffix) for proper
525 + // startup/env integration; argv is the fallback launch path.
526 + "desktopPath": id + ".desktop",
527 + "exec": String(e.execString || ""),
528 + "execArgv": argv,
529 + "icon": String(e.icon || ""),
530 + "terminal": !!e.runInTerminal,
531 + "route": "desktop-entry"
532 + });
534 + rows.sort((a, b) => String(a.title).localeCompare(String(b.title)));
535 + return rows;
526 538 function search(raw) {
575 - Component.onCompleted: loadDesktopEntries()
577 - Process {
578 - id: appScan
580 - running: false
582 - stdout: StdioCollector {
583 - waitForEnd: true
584 - onStreamFinished: root.applyDesktopEntries(this.text)
585 - }
587 - stderr: StdioCollector {
588 - waitForEnd: true
589 - onStreamFinished: root.appScanError = this.text.trim()
590 - }
592 - }