pragma Singleton import QtQuick import Quickshell import "AppMatching.js" as Matching Singleton { id: root readonly property var entries: DesktopEntries.applications.values readonly property var launchable: entries.filter(e => !e.noDisplay).slice().sort((a, b) => a.name.localeCompare(b.name)) property string error: "" function byId(id) { return entries.find(e => Matching.canonical(e.id) === Matching.canonical(id)) || null; } function icon(entry) { return entry && entry.icon ? Quickshell.iconPath(entry.icon, true) : ""; } function launch(entry, action) { if (!entry) { error = "This desktop entry is no longer installed."; return false; } let command = action ? action.command : entry.command; if (entry.runInTerminal) { const terminal = ConfigService.data.dock.terminalCommand; if (!terminal.length) { error = "Set dock.terminalCommand to a terminal command argument array before launching terminal applications."; return false; } command = terminal.concat(command); } Quickshell.execDetached({ command: scoped(command), workingDirectory: entry.workingDirectory }); error = ""; return true; } // Run the app in its own transient systemd scope. Launched directly, it would // join the shell's cgroup and be killed whenever the shell service restarts. // Falls back to a plain launch where systemd-run is unavailable. function scoped(command) { return ["sh", "-c", 'if command -v systemd-run >/dev/null 2>&1; then exec systemd-run --user --scope --collect --quiet -- "$@"; fi; exec "$@"', "sh"].concat(command); } }