Clock service: taunus-clockd
Keeps the alarms, one timer and one stopwatch, and rings when one is due, also with the Clock app closed and the device locked or off: it plays the ringtone and asks the shell to wake the screen and show Snooze / Stop.
- Socket:
$XDG_RUNTIME_DIR/taunus-clockd.sock(taunus_clockd::socket()), JSON lines. - State:
~/.local/share/taunus/clock.json. - The model (
Clock,Alarm,Timer,Stopwatch) is the cratetaunus-clockd(session/clockd/src/lib.rs): depend on it to share the types.
State
Each client gets this on connecting and after every change:
{"clock": {
"alarms": [{"id": 3, "hour": 7, "minute": 30, "days": [true,true,true,true,true,false,false],
"label": "", "ringtone": "", "on": true}],
"timer": {"total_ms": 300000, "end_ms": 1764660000000, "left_ms": 0},
"timer_ringtone": "",
"stopwatch": {"since_ms": null, "acc_ms": 0, "laps": []},
"snoozed": [],
"ringing": null},
"now": 1764659700000}
days: Monday to Sunday; none set: rings once, then switches itself off.ringtone: a ringtone id; empty is the built-in one.timer.end_mswhile running,left_mswhile paused.ringing:{"kind": "alarm"|"timer", "label", "ringtone", "since_ms"}.now: the service's clock, to compute what is left without drift.
Requests
{"alarm": {"id": 0, "hour": 7, "minute": 30, "days": [...], "label": "", "ringtone": "", "on": true}}
{"delete": 3}
{"timer": "start", "ms": 300000}
{"timer": "pause"} // also "resume", "cancel", "add" (one more minute)
{"timer_ringtone": "id"}
{"stopwatch": "start"} // also "pause", "lap", "reset"
{"ring": "stop"} // or "snooze"
id: 0 adds an alarm; another id replaces that alarm.
Example (Rust)
use std::io::Write;
let mut s = std::os::unix::net::UnixStream::connect(taunus_clockd::socket())?;
writeln!(s, "{}", serde_json::json!({"timer": "start", "ms": 10 * 60_000}))?;
//2bi: any program can schedule its own wake-ups ({"schedule": {"at_ms": …, "notify": "org.taunus.Hello"}}): the
service starts or notifies that program at the time, so programs don't have to keep running to act later. Today
clockd only knows alarms and the timer.