49 lines
1.6 KiB
QML
49 lines
1.6 KiB
QML
pragma Singleton
|
|
|
|
import Quickshell
|
|
// Required: execDetached's context overload takes a processContext value type
|
|
// from this module, and without the import the call fails to resolve.
|
|
import Quickshell.Io
|
|
import qs.config
|
|
|
|
// Quickshell's DesktopEntry.execute() deliberately ignores both Terminal=true
|
|
// and Exec field codes, so entries are launched here instead. Without this,
|
|
// entries like `firefox %U` are started with a literal "%U" argument.
|
|
Singleton {
|
|
id: root
|
|
|
|
function withoutFieldCodes(command: var): var {
|
|
const out = [];
|
|
|
|
for (const arg of command) {
|
|
// "%%" is an escaped percent and collapses to one. Every other
|
|
// %<char> is a field code the spec says to substitute with files,
|
|
// URLs or icons — launching from a menu has nothing to substitute,
|
|
// so they are removed.
|
|
const cleaned = arg.replace(/%(.)/g, (match, char) => char === "%" ? "%" : "");
|
|
|
|
// An argument that was nothing but a field code is dropped.
|
|
if (cleaned !== "")
|
|
out.push(cleaned);
|
|
}
|
|
|
|
return out;
|
|
}
|
|
|
|
function launch(entry: var): void {
|
|
const command = root.withoutFieldCodes(entry.command);
|
|
if (command.length === 0)
|
|
return;
|
|
|
|
const argv = entry.runInTerminal ? [...Config.terminal, ...command] : command;
|
|
const options = {
|
|
command: argv
|
|
};
|
|
|
|
if (entry.workingDirectory)
|
|
options.workingDirectory = entry.workingDirectory;
|
|
|
|
Quickshell.execDetached(options);
|
|
}
|
|
}
|