Files
glassMxrph/quickshell/launcher/CommandRegistry.qml
T

38 lines
1.3 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import "../core"
Singleton {
id: root
property var extensions: []
readonly property var commands: SettingsRegistry.pages.map(page => ({
id: page.command,
title: page.title,
description: page.description,
page: page.id,
available: page.available,
run: page.launcherAction ? () => ShellState[page.launcherAction]() : undefined
})).concat(extensions)
// Extensions are registered by trusted QML code, never interpreted from search text.
function registerCommand(command) {
if (!command || !/^[a-z][a-z0-9-]*$/.test(command.id) || !command.title || typeof command.run !== "function" || commands.some(c => c.id === command.id))
return false;
extensions = extensions.concat([command]);
return true;
}
function unregisterCommand(id) {
extensions = extensions.filter(c => c.id !== id);
}
function execute(id) {
const command = commands.find(c => c.id === id);
if (!command)
return false;
if (command.run)
command.run();
else
ShellState.openSettings(command.page);
return true;
}
}