Skip to content

Commit 0312d80

Browse files
feat: refactor app launching logic to use runDetachedWithFallback function
- Introduced shellQuote and runDetachedWithFallback functions to streamline command execution. - Updated launch function to utilize the new fallback mechanism for running applications in terminal or non-terminal modes. - Improved code readability and maintainability by reducing duplication in command execution logic.
1 parent 4f53f3e commit 0312d80

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

  • home/dot_config/quickshell/modules/launcher/services

home/dot_config/quickshell/modules/launcher/services/Apps.qml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,31 @@ import Quickshell
88
Searcher {
99
id: root
1010

11+
function shellQuote(arg: var): string {
12+
return `'${String(arg).replace(/'/g, `'"'"'`)}'`;
13+
}
14+
15+
function runDetachedWithFallback(commandArgs: list<string>, workingDirectory: string): void {
16+
const quoted = commandArgs.map(a => shellQuote(a)).join(" ");
17+
const script = `if command -v app2unit >/dev/null 2>&1; then exec app2unit -- ${quoted}; else exec ${quoted}; fi`;
18+
Quickshell.execDetached({
19+
command: ["sh", "-lc", script],
20+
workingDirectory: workingDirectory
21+
});
22+
}
23+
1124
function launch(entry: DesktopEntry): void {
1225
appDb.incrementFrequency(entry.id);
1326

14-
if (entry.runInTerminal)
15-
Quickshell.execDetached({
16-
command: ["app2unit", "--", ...Config.general.apps.terminal, `${Quickshell.shellDir}/assets/wrap_term_launch.sh`, ...entry.command],
17-
workingDirectory: entry.workingDirectory
18-
});
19-
else
20-
Quickshell.execDetached({
21-
command: ["app2unit", "--", ...entry.command],
22-
workingDirectory: entry.workingDirectory
23-
});
27+
if (entry.runInTerminal) {
28+
runDetachedWithFallback([
29+
...Config.general.apps.terminal,
30+
`${Quickshell.shellDir}/assets/wrap_term_launch.sh`,
31+
...entry.command
32+
], entry.workingDirectory);
33+
} else {
34+
runDetachedWithFallback([...entry.command], entry.workingDirectory);
35+
}
2436
}
2537

2638
function search(search: string): list<var> {

0 commit comments

Comments
 (0)