App lifecycle
Memory is small, so the shell ends apps that have been in the background for a while: SIGTERM, then
SIGKILL a few seconds later. They stay in Recents; opening one there starts it again with TAUNUS_RESTORE=1.
The voice assistant ends all apps when it needs the memory for its model.
So an app:
- keeps what matters on disk as it goes (it can be killed at any time);
- on
SIGTERMsaves its state and exits; - when restored, comes back as it was.
use taunus_core::lifecycle;
lifecycle::on_terminate(|| {
// runs on its own thread: hop to the UI thread to read the UI
let _ = slint::invoke_from_event_loop(|| {
lifecycle::save_state("hello", &serde_json::json!({ "page": current_page() }));
lifecycle::exit();
});
});
if lifecycle::restoring() {
if let Some(v) = lifecycle::load_state("hello") { /* open that page */ }
}
| Function | Does |
|---|---|
restoring() | Started again from Recents (TAUNUS_RESTORE=1) |
save_state(app, &json) / load_state(app) | ~/.local/state/taunus/<app>.json, written atomically |
on_terminate(f) | Calls f once on SIGTERM |
block_terminate() | Hold SIGTERM off during a critical write |
exit() | Exit now (after saving) |
Apps that must keep running (an alarm, a download) don't: they hand the work to a service (taunus-clockd
rings alarms with the Clock app closed). See Platform APIs.
//2bi: apps declare in their manifest whether they may be ended in the background, and the shell sends them a "trim memory" notice before it ends them.
Files
Use taunus_core::paths:
| Function | Path |
|---|---|
config_dir() | ~/.config/taunus (settings and accounts) |
data_dir() | ~/.local/share/taunus |
cache_dir() | ~/.cache/taunus |
runtime_dir() | $XDG_RUNTIME_DIR (sockets; gone after a restart) |
pictures_dir() | ~/Pictures |
write_atomic(path, bytes, mode) | Write via a temp file and rename |
only_instance(name) | Make this the only running instance |
/home lives on the user-data partition: it survives system updates, and a reset clears it.