From 10bee0184488ffe18b5621578811092ccfb6a405 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Fri, 23 Oct 2026 09:28:33 +0200 Subject: ai: Restart for the desktop assistant and local chat A Restart button sits before Stop on a running app that has a restart control. The assistant uses assistant.sh restart. llamachat has none, and its --quit answers before the app has exited, so a --daemon sent straight after finds an instance still running and does nothing: the restart quits, waits for --ping to fail (5s at most), then starts it. Co-Authored-By: Claude Opus 5.5 --- desktop/modules/ai/AiModule.qml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'desktop/modules/ai/AiModule.qml') diff --git a/desktop/modules/ai/AiModule.qml b/desktop/modules/ai/AiModule.qml index a96f484..6df3d6b 100644 --- a/desktop/modules/ai/AiModule.qml +++ b/desktop/modules/ai/AiModule.qml @@ -49,10 +49,16 @@ Module { Quickshell.env("HOME") + "/Programming/GIT/desktop-assistant/assistant.sh" // Each project's own control. Fanfictioner has no start, a run needs a - // story file, and its stop needs the pid, see stop(). + // story file, and its stop needs the pid, see stop(). llamachat has no + // restart, and --quit answers before the app is gone, so a --daemon + // straight after would find it still running and do nothing: wait for + // --ping to fail first, up to 5s. readonly property var controls: ({ - assistant: { start: [assistantSh, "start"], stop: [assistantSh, "stop"] }, - chat: { start: ["llamachat", "--daemon"], stop: ["llamachat", "--quit"] }, + assistant: { start: [assistantSh, "start"], stop: [assistantSh, "stop"], + restart: [assistantSh, "restart"] }, + chat: { start: ["llamachat", "--daemon"], stop: ["llamachat", "--quit"], + restart: ["sh", "-c", "llamachat --quit; for _ in $(seq 50); do " + + "llamachat --ping || break; sleep 0.1; done; exec llamachat --daemon"] }, imggen: { start: ["imggen", "start"], stop: ["imggen", "stop"] }, }) @@ -62,6 +68,12 @@ Module { if (canStart(app)) exec(controls[app.name].start); } + function canRestart(app) { return controls[app.name]?.restart !== undefined; } + + function restart(app) { + if (canRestart(app)) exec(controls[app.name].restart); + } + function stop(app) { if (app.name !== "fanfic") { exec(controls[app.name].stop); -- cgit v1.2.3