Move the dashboard and setup pages to a Vue SPA
Test and publish / test (push) Successful in 1m28s
Test and publish / publish (push) Successful in 3m30s

The pages are now a Vue 3 + Vite + TypeScript app in web/, built into
internal/web/dist/app and embedded in the binary. Go still serves
index.html for / and /setup behind the admin gate, plus the hashed
/assets/* (public, cached forever). The router takes its base from the
current URL, so it works under nginx's /tracker/ prefix unchanged.

Only dist/.gitkeep is committed, so go build and go test need no Node;
an unbuilt binary shows a "run make web" page at /. The Dockerfile gains
a Node stage, CI typechecks and builds the app, and make build/run build
it first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-14 22:06:41 +01:00
co-authored by Claude Opus 5.5
parent 67638cdef0
commit 0be97384fa
26 changed files with 2326 additions and 461 deletions
+12
View File
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Activity Tracker</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
+1687
View File
File diff suppressed because it is too large Load Diff
+22
View File
@@ -0,0 +1,22 @@
{
"name": "activity-tracker-web",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc --noEmit && vite build",
"typecheck": "vue-tsc --noEmit"
},
"dependencies": {
"vue": "^3.5.44",
"vue-router": "^5.4.0"
},
"devDependencies": {
"@types/node": "^26.6.5",
"@vitejs/plugin-vue": "^6.0.10",
"@vue/tsconfig": "^0.9.1",
"typescript": "^6.0.3",
"vite": "^8.3.4",
"vue-tsc": "^3.3.13"
}
}
+12
View File
@@ -0,0 +1,12 @@
<template>
<main>
<nav class="topbar">
<span class="brand">Activity Tracker</span>
<div class="tabs">
<RouterLink to="/">Dashboard</RouterLink>
<RouterLink to="/setup">Setup</RouterLink>
</div>
</nav>
<RouterView />
</main>
</template>
+43
View File
@@ -0,0 +1,43 @@
// Calls /api/v1 with the main site's session cookies, which the browser sends.
export async function api<T>(method: string, path: string, body?: unknown): Promise<T> {
const r = await fetch("api/v1/" + path, {
method,
headers: body ? { "Content-Type": "application/json" } : {},
body: body ? JSON.stringify(body) : undefined,
});
const out = await r.json().catch(() => ({}));
// The server serves the login redirect instead of the app, so a reload signs in again.
if (r.status === 401) { location.reload(); throw new Error("session expired"); }
if (!r.ok) throw new Error(out.error || r.statusText);
return out as T;
}
export interface Goal {
kind: string; label: string; op: string;
target_s: number; actual_s: number; met: boolean;
}
export interface Total { kind: string; label: string; seconds: number }
export interface Summary {
date: string; from: string; to: string;
totals: Total[]; by_kind: Record<string, number>; goals: Goal[];
}
export interface Activity {
kind: string; label: string;
started_at: string; ended_at: string; duration_s: number;
attrs?: Record<string, unknown>;
}
export interface Device {
name: string; kind: string;
last_seen_at?: string | null; revoked_at?: string | null;
}
export function dur(s: number): string {
s = Math.round(s);
const h = Math.floor(s / 3600), m = Math.floor(s % 3600 / 60);
if (h) return `${h}h ${String(m).padStart(2, "0")}m`;
return m ? `${m}m` : `${s}s`;
}
// Friendlier names for the kinds collectors send; anything else shows as is.
const KINDS: Record<string, string> = { app_focus: "desktop", tab_focus: "browser", at_desk: "at desk", in_bed: "in bed" };
export const kindName = (k: string) => KINDS[k] || k;
+15
View File
@@ -0,0 +1,15 @@
<script setup lang="ts">
import { ref } from "vue";
import { copy } from "../copy";
// A command block with a Copy button, which copies the text as rendered.
const pre = ref<HTMLPreElement>();
const label = ref("Copy");
</script>
<template>
<div class="codeblock">
<pre ref="pre"><slot /></pre>
<button class="small copy" type="button" @click="copy(pre!.innerText, s => label = s)">{{ label }}</button>
</div>
</template>
+12
View File
@@ -0,0 +1,12 @@
<script setup lang="ts">
// One collector's collapsible section on the setup page.
defineProps<{ id: string; title: string; hint: string }>();
const open = defineModel<boolean>("open", { default: false });
</script>
<template>
<details class="collector" :id="id" :open="open" @toggle="open = ($event.target as HTMLDetailsElement).open">
<summary><b>{{ title }}</b><span class="muted">{{ hint }}</span></summary>
<div class="body"><slot /></div>
</details>
</template>
+20
View File
@@ -0,0 +1,20 @@
<script setup lang="ts">
import { onMounted, ref } from "vue";
import type { Device } from "../api";
import { copy } from "../copy";
// A freshly created key, copied to the clipboard as soon as it's shown.
const props = defineProps<{ device: Device; apiKey: string }>();
const label = ref("Copy");
onMounted(() => copy(props.apiKey, s => label.value = s));
</script>
<template>
<div class="keybox">
<div>Key for <b>{{ device.name }}</b> <span class="badge">{{ device.kind }}</span>. Copy it now; it won't be shown again.</div>
<div class="codeblock">
<pre>{{ apiKey }}</pre>
<button class="small copy" type="button" @click="copy(apiKey, s => label = s)">{{ label }}</button>
</div>
</div>
</template>
+6
View File
@@ -0,0 +1,6 @@
// Copies text to the clipboard and reports the result through a button label.
export async function copy(text: string, setLabel: (s: string) => void) {
try { await navigator.clipboard.writeText(text); setLabel("Copied"); }
catch { setLabel("Copy failed"); }
setTimeout(() => setLabel("Copy"), 1500);
}
+22
View File
@@ -0,0 +1,22 @@
import { createApp } from "vue";
import { createRouter, createWebHistory } from "vue-router";
import App from "./App.vue";
import Dashboard from "./views/Dashboard.vue";
import Setup from "./views/Setup.vue";
import "./style.css";
const router = createRouter({
// The tracker is served under a prefix only the browser knows (nginx strips
// /tracker/), and every route is one segment deep, so the directory of the
// current URL is the app's base.
history: createWebHistory(new URL(".", location.href).pathname),
routes: [
{ path: "/", component: Dashboard, meta: { title: "Activity Tracker" } },
{ path: "/setup", component: Setup, meta: { title: "Activity Tracker Setup" } },
{ path: "/:rest(.*)", redirect: "/" },
],
scrollBehavior: to => (to.hash ? { el: to.hash } : { top: 0 }),
});
router.afterEach(to => { document.title = String(to.meta.title); });
createApp(App).use(router).mount("#app");
+82
View File
@@ -0,0 +1,82 @@
/* Shared by every view. */
:root {
--bg:#f6f6f4; --card:#ffffff; --fg:#1b1b1b; --muted:#6b6b6b; --line:#e4e4e0;
--accent:#3d6fc4; --accent-soft:#e8eefa; --ok:#2e8b57; --bad:#c0392b; --code:#f2f2ef;
}
@media (prefers-color-scheme: dark) {
:root {
--bg:#121212; --card:#1b1b1b; --fg:#e8e8e8; --muted:#9a9a9a; --line:#2c2c2c;
--accent:#7aa2ea; --accent-soft:#1e2a40; --ok:#5cc28a; --bad:#e2685a; --code:#232323;
}
}
* { box-sizing:border-box; }
body { margin:0; background:var(--bg); color:var(--fg); font:15px/1.5 system-ui, sans-serif; }
main { max-width:800px; margin:0 auto; padding:0 16px 56px; }
a { color:var(--accent); }
/* ---- top bar ---- */
.topbar { display:flex; align-items:center; gap:20px; padding:16px 0; margin-bottom:8px; border-bottom:1px solid var(--line); }
.brand { font-weight:650; font-size:17px; }
.tabs { display:flex; gap:4px; }
.tabs a { color:var(--muted); text-decoration:none; padding:5px 10px; border-radius:6px; }
.tabs a:hover { color:var(--fg); }
.tabs a[aria-current="page"] { color:var(--fg); background:var(--accent-soft); }
/* ---- controls ---- */
input, select, button { font:inherit; color:inherit; background:var(--card); border:1px solid var(--line); border-radius:6px; padding:5px 10px; }
button { cursor:pointer; }
button:hover { border-color:var(--muted); }
button.primary { background:var(--accent); border-color:var(--accent); color:#fff; }
button.primary:hover { filter:brightness(1.08); }
button.small { padding:2px 8px; font-size:13px; }
button:disabled { opacity:.6; cursor:default; }
:focus-visible { outline:2px solid var(--accent); outline-offset:1px; }
/* ---- layout pieces ---- */
.row { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.spread { justify-content:space-between; }
.card { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:16px; margin-top:16px; }
.card > h2:first-child, .card > .row:first-child h2 { margin-top:0; }
h1 { font-size:20px; margin:16px 0 0; }
h2 { font-size:15px; margin:0 0 10px; }
h3 { font-size:14px; margin:16px 0 6px; }
.muted { color:var(--muted); }
.small-text { font-size:13px; }
.ok { color:var(--ok); } .bad, .err { color:var(--bad); }
.badge { display:inline-block; font-size:12px; padding:1px 7px; border-radius:999px; background:var(--accent-soft); color:var(--accent); white-space:nowrap; }
.tiles { display:grid; grid-template-columns:repeat(auto-fit, minmax(160px, 1fr)); gap:12px; margin-top:16px; }
.tile { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:12px 14px; }
.tile .k { font-size:13px; color:var(--muted); }
.tile .v { font-size:22px; font-weight:650; font-variant-numeric:tabular-nums; overflow-wrap:anywhere; }
/* ---- tables ---- */
.tablewrap { overflow-x:auto; }
table { width:100%; border-collapse:collapse; }
th, td { padding:7px 8px 7px 0; border-bottom:1px solid var(--line); text-align:left; vertical-align:top; }
tr:last-child td { border-bottom:0; }
th { font-weight:600; font-size:13px; color:var(--muted); }
td.num { text-align:right; white-space:nowrap; font-variant-numeric:tabular-nums; padding-left:12px; padding-right:0; }
td.label { overflow-wrap:anywhere; width:100%; }
td.time { white-space:nowrap; color:var(--muted); font-variant-numeric:tabular-nums; }
.bar { height:4px; background:var(--accent); border-radius:2px; margin-top:4px; opacity:.85; }
/* ---- code ---- */
code, pre { font:13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; background:var(--code); border-radius:6px; }
code { padding:1px 5px; overflow-wrap:anywhere; }
pre { padding:10px 12px; overflow-x:auto; margin:0; }
.codeblock { position:relative; margin:8px 0; }
.codeblock .copy { position:absolute; top:6px; right:6px; }
ol, ul { padding-left:22px; margin:8px 0; }
li { margin:6px 0; }
/* ---- setup ---- */
.keybox { margin-top:12px; padding:12px; border:1px solid var(--ok); border-radius:8px; }
.keybox pre { margin:8px 0; }
details.collector { background:var(--card); border:1px solid var(--line); border-radius:10px; margin-top:12px; }
details.collector > summary { cursor:pointer; padding:14px 16px; list-style:none; display:flex; gap:10px; align-items:baseline; }
details.collector > summary::-webkit-details-marker { display:none; }
details.collector > summary::before { content:"▸"; color:var(--muted); }
details.collector[open] > summary::before { content:"▾"; }
details.collector > summary b { font-size:15px; }
details.collector > .body { padding:0 16px 16px; }
+124
View File
@@ -0,0 +1,124 @@
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { api, dur, kindName, type Activity, type Summary } from "../api";
const LIMIT = 500;
const today = () => new Date().toLocaleDateString("en-CA"); // YYYY-MM-DD in local time
const noon = (d: string) => new Date(d + "T12:00:00");
const date = ref(today());
const sum = ref<Summary | null>(null);
const activities = ref<Activity[]>([]);
const loading = ref(false);
const error = ref("");
const daysAgo = computed(() => Math.round((+noon(today()) - +noon(date.value)) / 864e5));
const title = computed(() => daysAgo.value === 0 ? "Today" : daysAgo.value === 1 ? "Yesterday"
: noon(date.value).toLocaleDateString([], { weekday: "long", day: "numeric", month: "long" }));
// Ignore a response for a day that's no longer selected.
let seq = 0;
async function load() {
const n = ++seq;
loading.value = true;
error.value = "";
try {
const s = await api<Summary>("GET", "summary/daily?date=" + date.value);
const q = new URLSearchParams({ from: s.from, to: s.to, limit: String(LIMIT) });
const { activities: acts } = await api<{ activities: Activity[] }>("GET", "activities?" + q);
if (n !== seq) return;
sum.value = s;
activities.value = acts;
} catch (e) {
if (n === seq) error.value = (e as Error).message;
} finally {
if (n === seq) loading.value = false;
}
}
watch(date, load, { immediate: true });
function shift(days: number) {
const d = noon(date.value);
d.setDate(d.getDate() + days);
date.value = d.toLocaleDateString("en-CA");
}
const top = computed(() => sum.value?.totals
.filter(t => t.kind === "app_focus" || t.kind === "tab_focus")
.sort((a, b) => b.seconds - a.seconds)[0]);
const goalsMet = computed(() => {
const g = sum.value?.goals ?? [];
return g.length ? `${g.filter(x => x.met).length} / ${g.length}` : "–";
});
const kinds = computed(() => Object.entries(sum.value?.by_kind ?? {}).sort((a, b) => b[1] - a[1]));
const labels = computed(() => [...sum.value?.totals ?? []].sort((a, b) => b.seconds - a.seconds).slice(0, 15));
const timeline = computed(() => activities.value.filter(a => a.duration_s >= 60)
.sort((a, b) => +new Date(b.started_at) - +new Date(a.started_at)));
const time = (t: string) => new Date(t).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
const pct = (v: number, max: number) => `${v / (max || 1) * 100}%`;
</script>
<template>
<div class="row spread">
<h1>{{ title }}</h1>
<div class="row">
<button aria-label="Previous day" @click="shift(-1)">‹</button>
<input type="date" v-model="date" aria-label="Day">
<button aria-label="Next day" @click="shift(1)">›</button>
<button :disabled="daysAgo === 0" @click="date = today()">Today</button>
</div>
</div>
<p class="muted">
<span v-if="error" class="err">{{ error }}</span>
<template v-else-if="loading">Loading…</template>
<template v-else-if="activities.length >= LIMIT">Timeline shows the first {{ LIMIT }} activities.</template>
</p>
<div v-if="sum">
<div class="tiles">
<div class="tile"><div class="k">Desktop time</div><div class="v">{{ dur(sum.by_kind.app_focus || 0) }}</div></div>
<div class="tile"><div class="k">Browser time</div><div class="v">{{ dur(sum.by_kind.tab_focus || 0) }}</div></div>
<div class="tile"><div class="k">Top site or app</div><div class="v">{{ top ? top.label || "—" : "–" }}</div></div>
<div class="tile"><div class="k">Goals met</div><div class="v">{{ goalsMet }}</div></div>
</div>
<section class="card"><h2>Goals</h2><div class="tablewrap"><table>
<tr v-for="(g, i) in sum.goals" :key="i">
<td class="label">{{ kindName(g.kind) }}{{ g.label ? " · " + g.label : "" }}
<span class="muted">{{ g.op }} {{ dur(g.target_s) }}</span></td>
<td class="num">{{ dur(g.actual_s) }}</td>
<td class="num" :class="g.met ? 'ok' : 'bad'">{{ g.met ? "✓ met" : "✗ missed" }}</td>
</tr>
<tr v-if="!sum.goals.length"><td class="muted">No goals yet. See <RouterLink to="/setup#goals">Setup</RouterLink>.</td></tr>
</table></div></section>
<section class="card"><h2>By kind</h2><div class="tablewrap"><table>
<tr v-for="[k, s] in kinds" :key="k">
<td class="label">{{ kindName(k) }}<div class="bar" :style="{ width: pct(s, kinds[0][1]) }"></div></td>
<td class="num">{{ dur(s) }}</td>
</tr>
<tr v-if="!kinds.length"><td class="muted">Nothing recorded.</td></tr>
</table></div></section>
<section class="card"><h2>Top labels</h2><div class="tablewrap"><table>
<tr v-for="t in labels" :key="t.kind + '\0' + t.label">
<td class="label">{{ t.label || "—" }} <span class="badge">{{ kindName(t.kind) }}</span>
<div class="bar" :style="{ width: pct(t.seconds, labels[0].seconds) }"></div></td>
<td class="num">{{ dur(t.seconds) }}</td>
</tr>
<tr v-if="!labels.length"><td class="muted">Nothing recorded.</td></tr>
</table></div></section>
<section class="card"><h2>Timeline</h2><div class="tablewrap"><table>
<tr v-for="(a, i) in timeline" :key="i">
<td class="time">{{ time(a.started_at) }}–{{ time(a.ended_at) }}</td>
<td class="label">{{ a.label || a.kind }} <span class="badge">{{ kindName(a.kind) }}</span>
<div v-if="a.attrs?.title" class="muted small-text">{{ a.attrs.title }}</div></td>
<td class="num">{{ dur(a.duration_s) }}</td>
</tr>
<tr v-if="!timeline.length"><td class="muted">No activities of a minute or longer.</td></tr>
</table></div></section>
</div>
</template>
+232
View File
@@ -0,0 +1,232 @@
<script setup lang="ts">
import { computed, onMounted, reactive, ref } from "vue";
import { useRoute } from "vue-router";
import { api, type Device } from "../api";
import CodeBlock from "../components/CodeBlock.vue";
import Collector from "../components/Collector.vue";
import KeyBox from "../components/KeyBox.vue";
// The tracker's public URL, e.g. https://www.adam-french.co.uk/tracker
const base = new URL(".", location.href).href.replace(/\/$/, "");
const devices = ref<Device[]>([]);
const loaded = ref(false);
const status = ref<{ msg: string; cls?: string }>({ msg: "" });
const active = computed(() => devices.value.filter(d => !d.revoked_at));
const revoked = computed(() => devices.value.filter(d => d.revoked_at));
// Which collector sections are open: the browser's by default, and the one a
// #section in the URL names.
const open = reactive<Record<string, boolean>>({ browser: true });
const route = useRoute();
if (route.hash) open[route.hash.slice(1)] = true;
// The last key generated, shown under the button that made it ("create" is
// the form), and the keys filled into each collector's steps.
const issued = ref<{ slot: string; device: Device; key: string } | null>(null);
const keys = reactive<Record<string, string>>({});
const keyFor = (kind: string) => keys[kind] || "trk_…";
const busy = ref("");
// The place a pair of Shortcuts automations reports. It ends up in a URL
// path, so spaces become hyphens rather than relying on Shortcuts to encode.
const place = ref("home");
const placeName = computed(() => place.value.trim().toLowerCase().replace(/[\s/?#]+/g, "-") || "home");
const kindSel = ref("browser");
const nameIn = ref("");
function ago(t?: string | null) {
if (!t) return "never";
const s = (Date.now() - +new Date(t)) / 1000;
if (s < 90) return "just now";
if (s < 3600) return Math.round(s / 60) + " min ago";
if (s < 86400) return Math.round(s / 3600) + " h ago";
return new Date(t).toLocaleDateString([], { day: "numeric", month: "short", year: "numeric" });
}
async function loadDevices() {
try {
({ devices: devices.value } = await api<{ devices: Device[] }>("GET", "devices"));
loaded.value = true;
} catch (e) {
status.value = { msg: (e as Error).message, cls: "err" };
}
}
onMounted(loadDevices);
// A readable name that isn't taken yet (names stay taken after revoking).
function suggestName(kind: string) {
let stem = ({ location: "iphone", manual: "script" } as Record<string, string>)[kind] || kind;
if (kind === "browser") {
const ua = navigator.userAgent;
stem = /Firefox\//.test(ua) ? "firefox" : /Edg\//.test(ua) ? "edge" : /Chrome\//.test(ua) ? "chrome" : "browser";
}
const taken = new Set(devices.value.map(d => d.name));
let name = stem;
for (let i = 2; taken.has(name); i++) name = `${stem}-${i}`;
return name;
}
async function generate(kind: string, name: string, slot: string) {
busy.value = slot;
try {
if (!loaded.value) await loadDevices();
const { device, key } = await api<{ device: Device; key: string }>("POST", "devices", { kind, name: name || suggestName(kind) });
issued.value = { slot, device, key };
// Fill the key into this collector's steps so they can be copied as-is.
keys[kind] = key;
open[kind] = true;
status.value = { msg: "" };
loadDevices();
return true;
} catch (e) {
status.value = { msg: (e as Error).message, cls: "err" };
return false;
} finally {
busy.value = "";
}
}
async function create() {
if (await generate(kindSel.value, nameIn.value.trim(), "create")) nameIn.value = "";
}
async function revoke(name: string) {
if (!confirm(`Revoke ${name}? Its collector will stop being able to upload.`)) return;
try {
await api("DELETE", "devices/" + encodeURIComponent(name));
status.value = { msg: `Revoked ${name}.`, cls: "ok" };
loadDevices();
} catch (e) {
status.value = { msg: (e as Error).message, cls: "err" };
}
}
</script>
<template>
<h1>Setup</h1>
<p class="muted">Each collector uploads to <code>{{ base }}</code> with its own API key. Open a collector below and click <b>Generate key</b>; the key is filled into its steps. A key is shown only once.</p>
<section class="card">
<div class="row spread"><h2>Devices</h2></div>
<div class="tablewrap"><table>
<tr v-if="!loaded"><td class="muted">Loading…</td></tr>
<template v-else>
<tr><th>Name</th><th>Kind</th><th>Last upload</th><th></th></tr>
<tr v-for="d in active" :key="d.name">
<td class="label">{{ d.name }}</td>
<td><span class="badge">{{ d.kind }}</span></td>
<td class="time">{{ ago(d.last_seen_at) }}</td>
<td class="num"><button class="small" @click="revoke(d.name)">Revoke</button></td>
</tr>
<tr v-if="!active.length"><td colspan="4" class="muted">No devices yet.</td></tr>
<tr v-if="revoked.length"><td colspan="4" class="muted small-text">{{ revoked.length }} revoked: {{ revoked.map(d => d.name).join(", ") }}</td></tr>
</template>
</table></div>
<form class="row" style="margin-top:12px" @submit.prevent="create">
<select v-model="kindSel" aria-label="Kind">
<option value="browser">Browser</option>
<option value="hyprland">Hyprland</option>
<option value="location">iPhone location</option>
<option value="manual">Script / manual</option>
<option value="presence">Presence</option>
</select>
<input v-model="nameIn" placeholder="Name (optional)" aria-label="Name" style="flex:1; min-width:140px">
<button class="primary" :disabled="busy === 'create'">Generate key</button>
</form>
<KeyBox v-if="issued?.slot === 'create'" :key="issued.key" :device="issued.device" :api-key="issued.key" />
<p class="small-text" :class="status.cls">{{ status.msg }}</p>
</section>
<Collector id="browser" title="Browser" hint="Violentmonkey userscript · time per site" v-model:open="open.browser">
<p>Records <code>tab_focus</code> intervals labelled by hostname. A tab counts only while it's the selected tab of the focused window, and stops after 5 minutes without input unless video or audio is playing.</p>
<button class="primary" :disabled="busy === 'browser'" @click="generate('browser', '', 'browser')">Generate key for this browser</button>
<KeyBox v-if="issued?.slot === 'browser'" :key="issued.key" :device="issued.device" :api-key="issued.key" />
<ol>
<li>Install Violentmonkey: <a href="https://addons.mozilla.org/firefox/addon/violentmonkey/" target="_blank" rel="noopener">Firefox</a> · <a href="https://chromewebstore.google.com/detail/violentmonkey/jinjaccalgkegednnccohejagnlnfdag" target="_blank" rel="noopener">Chrome / Chromium</a></li>
<li>Open <a :href="base + '/tracker.user.js'">{{ base }}/tracker.user.js</a> and click <b>Install</b>. Violentmonkey checks this URL for updates.</li>
<li>Click the Violentmonkey toolbar icon, then <b>Activity Tracker → Set server and API key</b>. Enter the server and key:
<CodeBlock>{{ base }}</CodeBlock>
<CodeBlock>{{ keys.browser || "trk_… (generate a key above)" }}</CodeBlock></li>
<li>Check it with <b>Status / upload now</b> in the same menu. Uploads happen every minute.</li>
</ol>
<p class="muted small-text">The menu also turns full URLs and page titles on or off (both off by default), sets hosts to ignore, and changes the idle timeout. It runs on every web page and on local <code>file://</code> pages (labelled <code>file</code>; in Chrome, turn on <b>Allow access to file URLs</b> in Violentmonkey's extension details). Browsers block all extensions on <code>about:</code> pages, the new tab page, extension stores and the PDF viewer, so those aren't recorded; Hyprland still counts them as browser time.</p>
</Collector>
<Collector id="hyprland" title="Hyprland desktop" hint="focused window, idle and locked time" v-model:open="open.hyprland">
<p>Records <code>app_focus</code> intervals labelled by window class, with the title.</p>
<button class="primary" :disabled="busy === 'hyprland'" @click="generate('hyprland', '', 'hyprland')">Generate key for this machine</button>
<KeyBox v-if="issued?.slot === 'hyprland'" :key="issued.key" :device="issued.device" :api-key="issued.key" />
<h3>1. Install the agent</h3>
<CodeBlock>git clone ssh://[email protected]:2222/adamf/ccp.git && cd ccp
make install-agent # ~/.local/bin/hypr-agent and the systemd user unit</CodeBlock>
<h3>2. Configure and start it</h3>
<CodeBlock>mkdir -p ~/.config/hypr-agent
cat > ~/.config/hypr-agent/env &lt;&lt;EOF
TRACKER_URL={{ base }}
TRACKER_API_KEY={{ keyFor("hyprland") }}
# HYPR_AGENT_TITLES=false # don't send window titles at all
# HYPR_AGENT_REDACT=(?i)bank|private # replace matching titles with [redacted]
EOF
chmod 600 ~/.config/hypr-agent/env
systemctl --user enable --now hypr-agent</CodeBlock>
<h3>3. Idle and lock (optional)</h3>
<p>Add to <code>~/.config/hypr/hypridle.conf</code>:</p>
<CodeBlock>general {
lock_cmd = hypr-agent lock; pidof hyprlock || hyprlock
unlock_cmd = hypr-agent unlock
}
listener {
timeout = 300
on-timeout = hypr-agent idle
on-resume = hypr-agent resume
}</CodeBlock>
<p class="muted small-text">Check it with <code>journalctl --user -u hypr-agent -f</code>. Events upload every minute and wait in <code>~/.local/state/hypr-agent/buffer.jsonl</code> while the server can't be reached.</p>
</Collector>
<Collector id="location" title="iPhone location" hint="Shortcuts automations · time at home and away" v-model:open="open.location">
<p>Records <code>place</code> intervals labelled by place (<code>home</code>, <code>gym</code>, …) and <code>away</code> in between. Each arrive or leave closes the current interval and opens the next; the current one counts up to now.</p>
<button class="primary" :disabled="busy === 'location'" @click="generate('location', '', 'location')">Generate key for this phone</button>
<KeyBox v-if="issued?.slot === 'location'" :key="issued.key" :device="issued.device" :api-key="issued.key" />
<h3>1. Make the Tracker shortcut (once)</h3>
<ol>
<li>In the Shortcuts app, on the <b>Shortcuts</b> tab, tap <b>+</b> and name the shortcut <code>Tracker</code>.</li>
<li>Add the action <b>Get Contents of URL</b>. In the URL, type the text below, then insert the <b>Shortcut Input</b> variable right after the last slash:
<CodeBlock>{{ base }}/api/v1/location/</CodeBlock></li>
<li>Tap <b>Show More</b>. Set Method to <code>POST</code> and add a header <code>Authorization</code> = <code>Bearer {{ keyFor("location") }}</code></li>
</ol>
<p class="muted small-text">The shortcut holds your key, so don't share it.</p>
<h3>2. Add two automations per place</h3>
<p>Type the place's name to fill in the steps:</p>
<div class="row"><input v-model="place" placeholder="home" aria-label="Place name" style="flex:1; min-width:140px"></div>
<ol>
<li>On the <b>Automation</b> tab, tap <b>+</b>, choose <b>Arrive</b>, set Location to your {{ placeName }}'s address and pick <b>Run Immediately</b> (turn off <b>Notify When Run</b> if you like). Then tap <b>New Blank Automation</b>.</li>
<li>Add a <b>Text</b> action containing:
<CodeBlock>arrive/{{ placeName }}</CodeBlock>
then a <b>Run Shortcut</b> action set to <b>Tracker</b>. The Text becomes its input.</li>
<li>Repeat with <b>Leave</b> for the same address, with the Text:
<CodeBlock>leave/{{ placeName }}</CodeBlock></li>
</ol>
<p class="muted small-text">Any name works except <code>away</code>. Names are lower-cased, and spaces become hyphens. Repeated triggers are ignored, and a late "leave home" after "arrive gym" doesn't undo the arrival. Goal examples: <code>--kind place --label away --op '&gt;=' --target 1h</code>, <code>--kind place --label gym --op '&gt;=' --target 45m</code>.</p>
</Collector>
<Collector id="manual" title="Scripts" hint="post any interval with curl" v-model:open="open.manual">
<button class="primary" :disabled="busy === 'manual'" @click="generate('manual', '', 'manual')">Generate key for scripts</button>
<KeyBox v-if="issued?.slot === 'manual'" :key="issued.key" :device="issued.device" :api-key="issued.key" />
<CodeBlock>curl -X POST {{ base }}/api/v1/manual/events \
-H 'Authorization: Bearer {{ keyFor("manual") }}' -H 'Content-Type: application/json' \
-d '{"events":[{"id":"reading-2026-10-14","kind":"reading","label":"book",
"started_at":"2026-10-14T20:00:00Z","ended_at":"2026-10-14T20:45:00Z"}]}'</CodeBlock>
<p class="muted small-text">The <code>id</code> makes re-sending safe: a duplicate is ignored. Webcam presence (<code>/api/v1/presence/events</code>) has an endpoint but no agent yet.</p>
</Collector>
<Collector id="goals" title="Goals" hint="daily targets on the dashboard" v-model:open="open.goals">
<p>Managed on the Pi. An empty label matches every label of that kind.</p>
<CodeBlock>docker exec activity-tracker tracker goal add --kind tab_focus --label youtube.com --op '&lt;=' --target 1h
docker exec activity-tracker tracker goal add --kind walk --op '&gt;=' --target 30m
docker exec activity-tracker tracker goal list
docker exec activity-tracker tracker goal rm --id 2</CodeBlock>
</Collector>
</template>
+9
View File
@@ -0,0 +1,9 @@
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"compilerOptions": {
"types": ["vite/client"],
"noUnusedLocals": true,
"noUnusedParameters": true
},
"include": ["src/**/*.ts", "src/**/*.vue", "vite.config.ts"]
}
+22
View File
@@ -0,0 +1,22 @@
import { fileURLToPath } from "node:url";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// The build is embedded in the Go binary (internal/web/dist/app) and served under
// whatever prefix the proxy gives it (/tracker/ in production), so every asset
// URL is relative.
export default defineConfig({
plugins: [vue()],
base: "./",
build: {
outDir: fileURLToPath(new URL("../internal/web/dist/app", import.meta.url)),
emptyOutDir: true,
},
server: {
// `make run` serves the API on :8080 with AUTH_MODE=dev.
proxy: {
"/api": "http://localhost:8080",
"/tracker.user.js": "http://localhost:8080",
},
},
});