feat(app): Tauri window and the Windows build
M5 step 5, first part. app/shell is a Tauri 2 crate (jarvis.exe): one
window over app/ui whose invoke("admin") goes to AdminApi::call. Its
WebView2 data sits next to the location file; closing the window stops
the services and waits for a cancelled start (AdminApi::shutdown).
app/shell/package.sh cross-builds it on Linux (x86_64-pc-windows-gnu)
and lays out Jarvis/ with WebView2Loader.dll and python-src/
(voice_worker, jarvis). The worker's default sources are python-src next
to the executable when present, else the repository's src/.
The bot screen now shows the masked token right after saving.
Checked on the win-ci VM: the window and wizard, PC check, uv and worker
venv installed, a cancel leaving no uv/Python process, the token stored
DPAPI-encrypted, a start failing with its reason, logs, error copy, zip
export, closing the window ending the process, nothing under %APPDATA% or
%LOCALAPPDATA%; the core's unit tests on Windows (156/157, the one
Linux-path assumption fixed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -255,6 +255,20 @@ Plain HTML, CSS and an ES module, no build step, dark theme after `DESIGN.md`. A
|
||||
the commands on 127.0.0.1; every command needs the random token it prints (`#token=` in the page
|
||||
URL), so other local programs cannot drive it.
|
||||
|
||||
## Window and Windows build (`app/shell/`)
|
||||
|
||||
- `jarvis.exe` (crate `jarvis-shell`, Tauri 2 on the WebView2 Windows already has) opens one window
|
||||
with the screens (`app/ui`) and passes `invoke("admin", {command, args})` to `AdminApi::call`.
|
||||
`--location FILE` replaces the default location file (`%APPDATA%\JarvisBot\location.json`).
|
||||
The window's own browser data goes next to the location file (`webview/`), nothing under
|
||||
`%LOCALAPPDATA%`. Closing the window stops the services and waits until a start in progress is
|
||||
cancelled (`AdminApi::shutdown`), so nothing the app started keeps running.
|
||||
- `app/shell/package.sh <folder>` builds it on Linux (`x86_64-pc-windows-gnu`, mingw-w64) and lays
|
||||
out `Jarvis/`: `jarvis.exe`, `WebView2Loader.dll` and `python-src/` (the `voice_worker` and
|
||||
`jarvis` packages, no caches or specs). The worker's default sources are `python-src` next to the
|
||||
executable when it is there, else the repository's `src/`; the install reads its requirement
|
||||
files from the same place. The installer (NSIS) comes later; the folder runs as it is.
|
||||
|
||||
## Tests
|
||||
|
||||
`cargo test`: data folder layout, location file and the environment override, a refused relative
|
||||
@@ -278,5 +292,9 @@ commands (first run: folder then token, the token never returned whole, the wiza
|
||||
step until finished, log files and the zip from the folder choice on, settings and logs through
|
||||
their modules, the dashboard before anything runs), the invite link's permissions and the Message
|
||||
Content flags. The screens are checked in a browser against the development server with the real
|
||||
services (wizard, dashboard start, restart and stop, settings save, chat channels, logs, export). Windows-only paths (DPAPI, `%APPDATA%`) are
|
||||
checked on the Windows VM in the Windows build step.
|
||||
services (wizard, dashboard start, restart and stop, settings save, chat channels, logs, export). On Windows (the win-ci VM, `x86_64-pc-windows-gnu` build): the unit tests (DPAPI, data folder,
|
||||
downloads, install steps, logs; the Unix-only process tests excepted), and the window by hand: the
|
||||
wizard's folder, PC check and install (`uv` and the worker venv installed, a cancel leaving no
|
||||
`uv` or Python process), the token stored DPAPI-encrypted, a start failing with its reason, the
|
||||
log screen, error copy, zip export, and closing the window ending the process with nothing written
|
||||
to `%APPDATA%` or `%LOCALAPPDATA%`.
|
||||
|
||||
@@ -92,6 +92,23 @@ impl AdminApi {
|
||||
Ok(c.get_or_insert_with(|| Controller::new(ServicesHost::new(dir.path().to_path_buf()))).clone())
|
||||
}
|
||||
|
||||
/// Stop the services (and cancel a start) when the app closes, so nothing it started (the
|
||||
/// worker, Strata) keeps running.
|
||||
pub async fn shutdown(&self) {
|
||||
let controller = self.controller.lock().unwrap().clone();
|
||||
if let Some(c) = controller {
|
||||
if matches!(c.state(), State::Running | State::Starting) {
|
||||
let _ = c.stop().await;
|
||||
}
|
||||
// A cancelled start finishes in the background: wait for it (Strata's stop takes up to
|
||||
// two minutes) before the app exits.
|
||||
let until = std::time::Instant::now() + std::time::Duration::from_secs(150);
|
||||
while matches!(c.state(), State::Starting | State::Stopping) && std::time::Instant::now() < until {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn call(&self, command: &str, args: Value) -> Result<Value, String> {
|
||||
crate::debug_log!("admin", "command {command}");
|
||||
match command {
|
||||
@@ -306,6 +323,16 @@ mod tests {
|
||||
assert!(a.call("service_stop", json!({})).await.is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn closing_the_app_while_starting_waits_until_everything_is_stopped() {
|
||||
let (a, base) = api("api5");
|
||||
a.shutdown().await; // nothing chosen or started yet
|
||||
a.call("folder_choose", json!({"path": base.join("d").to_string_lossy()})).await.unwrap();
|
||||
a.call("service_start", json!({})).await.unwrap();
|
||||
a.shutdown().await;
|
||||
assert_eq!(a.call("dashboard", json!({})).await.unwrap()["state"], json!("stopped"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_start_is_starting_when_it_answers_so_a_stop_right_after_it_is_not_refused() {
|
||||
let (a, base) = api("api4");
|
||||
|
||||
@@ -71,7 +71,7 @@ strings (numbers would lose precision).
|
||||
| `voice.stt` | `{}` | Other worker STT settings (`partials`, `end_silence_ms`, `final_beam`, `language`, ...); the worker validates them. |
|
||||
| `chatChannels` | `[]` | `{id, name, description, read (true), send (true), edit (true), react (true), delete (false), pin (false), answer ("wakeWord")}` per channel; `answer` is in `conversation.spec.md`. |
|
||||
| `voiceWorker.python` | `python3` (`python.exe` on Windows) | Python of the worker venv. |
|
||||
| `voiceWorker.cwd` | the repo's `src/` (development builds) | Folder holding the `voice_worker` package. |
|
||||
| `voiceWorker.cwd` | `python-src` next to the app's executable when it is there (the Windows build), else the repo's `src/` | Folder holding the `voice_worker` package. |
|
||||
| `voiceWorker.args` | `[]` | Extra worker arguments, e.g. `["--melo-python", "<MeloTTS venv python>"]`. |
|
||||
| `memory` | `{}` | The worker's memory settings (`voice_worker.spec.md`, "Memory settings"), sent in its `hello`; the settings screens check them (`admin.spec.md`). |
|
||||
|
||||
|
||||
@@ -129,8 +129,7 @@ impl Default for Settings {
|
||||
chat_channels: vec![],
|
||||
voice_worker: WorkerSettings {
|
||||
python: if cfg!(windows) { "python.exe".into() } else { "python3".into() },
|
||||
// The repo's src/, next to this crate.
|
||||
cwd: Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join("src"),
|
||||
cwd: worker_cwd_for(std::env::current_exe().ok().as_deref()),
|
||||
args: vec![],
|
||||
},
|
||||
call: CallSettings::default(),
|
||||
@@ -142,6 +141,18 @@ impl Default for Settings {
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the worker's Python sources (`voice_worker`, `jarvis`) are by default: `python-src` next to
|
||||
/// the app's executable (the Windows build ships them there), else the repository's `src/` next to
|
||||
/// this crate (development and tests).
|
||||
pub fn worker_cwd_for(exe: Option<&Path>) -> PathBuf {
|
||||
if let Some(shipped) = exe.and_then(Path::parent).map(|d| d.join("python-src")) {
|
||||
if shipped.join("voice_worker").is_dir() {
|
||||
return shipped;
|
||||
}
|
||||
}
|
||||
Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join("src")
|
||||
}
|
||||
|
||||
fn err<T>(msg: impl Into<String>) -> Result<T, SettingsError> {
|
||||
Err(SettingsError(msg.into()))
|
||||
}
|
||||
@@ -456,6 +467,16 @@ mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
#[test]
|
||||
fn the_python_sources_shipped_next_to_the_app_win_over_the_repository() {
|
||||
let dir = crate::datadir::temp_dir("pysrc");
|
||||
let exe = dir.join("jarvis.exe");
|
||||
assert!(worker_cwd_for(Some(&exe)).ends_with("src"), "nothing shipped: the repository's src/");
|
||||
std::fs::create_dir_all(dir.join("python-src").join("voice_worker")).unwrap();
|
||||
assert_eq!(worker_cwd_for(Some(&exe)), dir.join("python-src"));
|
||||
assert_eq!(worker_cwd_for(None), Path::new(env!("CARGO_MANIFEST_DIR")).join("..").join("src"));
|
||||
}
|
||||
|
||||
const ID: &str = "123456789012345678";
|
||||
const IDN: u64 = 123456789012345678;
|
||||
|
||||
|
||||
@@ -364,6 +364,7 @@ mod tests {
|
||||
assert!(Path::new(v["db_path"].as_str().unwrap()).starts_with(&l.data));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
/// Default settings on a port nothing listens on (8080 may be taken on a developer's PC).
|
||||
fn unused_port_settings() -> Settings {
|
||||
let port = std::net::TcpListener::bind("127.0.0.1:0").unwrap().local_addr().unwrap().port();
|
||||
@@ -375,6 +376,7 @@ mod tests {
|
||||
serve(id, delay, None, Arc::new(Mutex::new("list"))).await
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
/// The same; once the file `gone` exists (a fake Strata's `--stop` makes it) it stops listening,
|
||||
/// so a connection is refused.
|
||||
async fn models_server_until(id: &'static str, delay: Duration, gone: Option<std::path::PathBuf>) -> u16 {
|
||||
@@ -606,12 +608,15 @@ mod tests {
|
||||
c.stop().await.unwrap();
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
/// The services as the controller sees them, reduced to the LLM.
|
||||
struct LlmHost {
|
||||
llm: Arc<Llm>,
|
||||
settings: Settings,
|
||||
}
|
||||
#[cfg(unix)]
|
||||
struct LlmRunning(Arc<Llm>);
|
||||
#[cfg(unix)]
|
||||
#[async_trait::async_trait]
|
||||
impl crate::control::Running for LlmRunning {
|
||||
async fn stop(&self) -> Result<(), String> {
|
||||
@@ -621,6 +626,7 @@ mod tests {
|
||||
json!({"worker": null, "voiceMembers": [], "missed": []})
|
||||
}
|
||||
}
|
||||
#[cfg(unix)]
|
||||
#[async_trait::async_trait]
|
||||
impl crate::control::Host for LlmHost {
|
||||
async fn start(&self) -> Result<(Arc<dyn crate::control::Running>, tokio::sync::mpsc::UnboundedReceiver<crate::discord::CoreEvent>), String> {
|
||||
|
||||
Reference in New Issue
Block a user