mirror of
https://github.com/saphid/frame-control.git
synced 2026-10-06 01:00:18 +02:00
Merge main into panel-workspaces (testing notes)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
commit
3ef7312654
18 files changed
+1028
-32
No files matched your search
@@ -0,0 +1,264 @@
|
||||
"""Opt-in session worker ON the Frame; no root, extra apps, or power actions.
|
||||
|
||||
One worker per user, shared by desktop and phone. State survives companion
|
||||
connections, not headset reboots. See docs/family-comfort.md for guarantees.
|
||||
"""
|
||||
import contextlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from frame_steam import Page
|
||||
from frame_status import battery, thermal_alerts, activity_level
|
||||
|
||||
ROOT = Path.home() / '.local/state/frame-control/comfort'
|
||||
VRCMD = '/opt/steamvr/bin/linuxarm64/vrcmd'
|
||||
HOME_JS = """(async () => {
|
||||
SteamUIStore.Navigate('/library/home');
|
||||
await SteamClient.OpenVR.VROverlay.ShowDashboard('valve.steam.gamepadui.main');
|
||||
if (!await SteamClient.OpenVR.VROverlay.IsDashboardVisible()) throw Error('Steam dashboard did not open');
|
||||
return {path: location.pathname};
|
||||
})()"""
|
||||
|
||||
|
||||
def clock():
|
||||
# CLOCK_BOOTTIME includes headset suspend; wall-clock corrections don't alter limits.
|
||||
return time.clock_gettime(time.CLOCK_BOOTTIME)
|
||||
|
||||
|
||||
def boot():
|
||||
return Path('/proc/sys/kernel/random/boot_id').read_text().strip()
|
||||
|
||||
|
||||
def validate(body):
|
||||
if not isinstance(body, dict) or body.get('action') not in ('status', 'start', 'cancel'):
|
||||
raise ValueError('Choose status, start or cancel')
|
||||
if body['action'] == 'start':
|
||||
for key, low, high in (('minutes', 1, 240), ('breakMinutes', 0, 120), ('stillMinutes', 0, 240)):
|
||||
n = body.get(key)
|
||||
if type(n) is not int or not low <= n <= high:
|
||||
raise ValueError(f'{key} must be a whole number from {low} to {high}')
|
||||
for key in ('batteryAlert', 'heatAlert'):
|
||||
if type(body.get(key)) is not bool:
|
||||
raise ValueError(f'{key} must be true or false')
|
||||
return body
|
||||
|
||||
|
||||
def new_session(body, now, boot_id):
|
||||
return {'id': uuid.uuid4().hex, 'boot': boot_id, 'active': True,
|
||||
'options': {k: body[k] for k in ('minutes', 'breakMinutes', 'stillMinutes', 'batteryAlert', 'heatAlert')},
|
||||
'started': now, 'deadline': now + body['minutes'] * 60, 'lastSample': now,
|
||||
'used': 0, 'nextBreak': body['breakMinutes'] * 60, 'stillSent': False,
|
||||
'warned': None, 'events': [], 'seq': 0, 'latched': [], 'error': None}
|
||||
|
||||
|
||||
def event(s, kind, message):
|
||||
s['seq'] += 1
|
||||
s['events'].append({'id': s['id'] + ':' + str(s['seq']), 'kind': kind,
|
||||
'message': message, 'time': time.time()})
|
||||
s['events'] = s['events'][-40:]
|
||||
|
||||
|
||||
def notify(message):
|
||||
r = subprocess.run([VRCMD, '--notify', 'Frame Control: ' + message],
|
||||
capture_output=True, text=True, timeout=20)
|
||||
if r.returncode or 'succeeded' not in r.stdout:
|
||||
raise RuntimeError('SteamVR could not show the reminder: ' + (r.stderr or r.stdout)[-300:])
|
||||
|
||||
|
||||
def home():
|
||||
# A total process deadline also bounds a CDP peer that keeps sending events
|
||||
# without completing the request. Keep cancellation ordered after this action.
|
||||
r = subprocess.run([sys.executable, str(Path(__file__).resolve()), '--home'],
|
||||
capture_output=True, text=True, timeout=15)
|
||||
if r.returncode:
|
||||
raise RuntimeError('Steam Home failed: ' + (r.stdout or r.stderr)[-300:])
|
||||
|
||||
|
||||
def open_home():
|
||||
page = Page()
|
||||
try:
|
||||
result = page.eval(HOME_JS)
|
||||
if result.get('path') != '/routes/library/home':
|
||||
raise RuntimeError('Steam did not navigate Home')
|
||||
finally:
|
||||
page.sock.close()
|
||||
|
||||
|
||||
def tick(s, now, sample, warn=notify, go_home=home, read_clock=clock):
|
||||
"""One deterministic step; injected actions/samples also exercise a fake Frame."""
|
||||
if not s.get('active'):
|
||||
return
|
||||
o = s['options']
|
||||
s['heartbeat'] = now
|
||||
delta = max(0, min(30, now - s['lastSample']))
|
||||
s['lastSample'] = now
|
||||
level = sample.get('activity')
|
||||
b = sample.get('battery') or {}
|
||||
s['unavailable'] = []
|
||||
if o['batteryAlert'] and b.get('percent') is None:
|
||||
s['unavailable'].append('battery')
|
||||
if o['heatAlert'] and sample.get('thermal') is None:
|
||||
s['unavailable'].append('temperature')
|
||||
if (o['breakMinutes'] or o['stillMinutes']) and level is None:
|
||||
s['unavailable'].append('activity')
|
||||
s['activity'] = level
|
||||
if level in (1, 2):
|
||||
s['used'] += delta
|
||||
elif level is not None:
|
||||
s['used'] = 0
|
||||
s['nextBreak'] = o['breakMinutes'] * 60
|
||||
s['stillSent'] = False
|
||||
# Missing samples never count as time worn. No catch-up burst after a disconnect.
|
||||
if now >= s['deadline'] - 60 and s['warned'] is None:
|
||||
warn('One minute left. Save your progress; Steam Home will open.')
|
||||
s['warned'] = max(now, read_clock())
|
||||
event(s, 'warning', 'One minute left. Save your progress; Steam Home will open.')
|
||||
if s['warned'] is not None and now >= max(s['deadline'], s['warned'] + 60):
|
||||
go_home()
|
||||
s['active'] = False
|
||||
event(s, 'finished', 'Session ended: Steam Home opened. Your game is still running.')
|
||||
return
|
||||
if o['breakMinutes'] and s['used'] >= s['nextBreak']:
|
||||
warn('Time for a break. Take off the headset and rest your eyes.')
|
||||
event(s, 'break', 'Time for a break. Take off the headset and rest your eyes.')
|
||||
s['nextBreak'] = s['used'] + o['breakMinutes'] * 60
|
||||
if o['stillMinutes'] and not s['stillSent'] and s['used'] >= o['stillMinutes'] * 60:
|
||||
event(s, 'still', f"Headset still active after {o['stillMinutes']} active minute(s). Check in with the wearer.")
|
||||
s['stillSent'] = True
|
||||
low = b.get('percent') is not None and b['percent'] <= 15 and b.get('status') == 'Discharging'
|
||||
hot = sample.get('thermal')
|
||||
for kind, enabled, value, message in (
|
||||
('battery', o['batteryAlert'], low if b else None, 'Frame battery is low (15% or less).'),
|
||||
('heat', o['heatAlert'], bool(hot) if hot is not None else None,
|
||||
'Frame reports a hot/critical thermal trip or battery overheat. Ask the wearer to take a break.')):
|
||||
if enabled and value and kind not in s['latched']:
|
||||
event(s, kind, message)
|
||||
s['latched'].append(kind)
|
||||
elif value is False and kind in s['latched']:
|
||||
# Battery hysteresis prevents repeated alerts around 15%.
|
||||
if kind != 'battery' or b.get('status') == 'Charging' or (b.get('percent') or 0) >= 20:
|
||||
s['latched'].remove(kind)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def locked(name='state.lock', nonblocking=False):
|
||||
import fcntl # only needed ON the Linux headset, not by desktop validation/tests
|
||||
ROOT.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||
with (ROOT / name).open('a') as f:
|
||||
fcntl.flock(f, fcntl.LOCK_EX | (fcntl.LOCK_NB if nonblocking else 0))
|
||||
yield f
|
||||
|
||||
|
||||
def read_state():
|
||||
try:
|
||||
state = json.loads((ROOT / 'session.json').read_text())
|
||||
if not isinstance(state, dict):
|
||||
raise ValueError('Saved session must be an object')
|
||||
return state
|
||||
except FileNotFoundError:
|
||||
return {'active': False, 'events': []}
|
||||
except (ValueError, UnicodeDecodeError):
|
||||
# Preserve the unreadable state for diagnosis, then allow a new session.
|
||||
(ROOT / 'session.json').replace(ROOT / ('session-unreadable-' + uuid.uuid4().hex + '.json'))
|
||||
return {'active': False, 'events': [],
|
||||
'error': 'Saved session was unreadable. Start a new session.'}
|
||||
|
||||
|
||||
def save(s):
|
||||
p = ROOT / 'session.tmp'
|
||||
p.write_text(json.dumps(s))
|
||||
p.chmod(0o600)
|
||||
p.replace(ROOT / 'session.json')
|
||||
|
||||
|
||||
def current(s, now):
|
||||
if s.get('active') and s.get('boot') != boot():
|
||||
s['active'] = False
|
||||
s['error'] = 'Headset restarted. Start a new session.'
|
||||
out = dict(s)
|
||||
out['time'] = time.time() # event age uses the Frame's clock, not the phone's
|
||||
out['remaining'] = max(0, max(s.get('deadline', now), (s.get('warned') or 0) + 60) - now) if s.get('active') else 0
|
||||
beat = s.get('heartbeat', s.get('started', now)) # a hand-edited state may lack either
|
||||
if s.get('active') and now - beat > 90:
|
||||
out['error'] = 'Session worker is not responding. Timer enforcement is unverified; cancel and start again.'
|
||||
return out
|
||||
|
||||
|
||||
def watch():
|
||||
try:
|
||||
with locked('worker.lock', nonblocking=True) as worker:
|
||||
while True:
|
||||
with locked():
|
||||
s = current(read_state(), clock())
|
||||
if not s.get('active'):
|
||||
save(s)
|
||||
# Release ownership before state.lock: a concurrent start
|
||||
# cannot miss the gap between an old worker and its exit.
|
||||
import fcntl
|
||||
fcntl.flock(worker, fcntl.LOCK_UN)
|
||||
return
|
||||
try:
|
||||
b = battery()
|
||||
hot = thermal_alerts()
|
||||
if b and b.get('health') == 'Overheat':
|
||||
hot = (hot or []) + ['battery']
|
||||
tick(s, clock(), {'battery': b, 'thermal': hot, 'activity': activity_level()})
|
||||
s['error'] = None
|
||||
except Exception as e:
|
||||
error = str(e)
|
||||
if s.get('error') != error:
|
||||
event(s, 'error', 'Session action failed: ' + error)
|
||||
s['error'] = error
|
||||
save(s)
|
||||
time.sleep(5)
|
||||
except BlockingIOError:
|
||||
pass # another connection already started the single worker
|
||||
|
||||
|
||||
def command(body):
|
||||
validate(body)
|
||||
with locked():
|
||||
s = current(read_state(), clock())
|
||||
if body['action'] == 'start':
|
||||
if s.get('active'):
|
||||
raise ValueError('A session is already running. Cancel it before starting another.')
|
||||
s = new_session(body, clock(), boot())
|
||||
event(s, 'started', 'Session started. Steam Home opens at the limit; games are not closed.')
|
||||
elif body['action'] == 'cancel':
|
||||
s['active'] = False
|
||||
s['error'] = None
|
||||
if s.get('id'):
|
||||
event(s, 'cancelled', 'Session timer and monitoring cancelled.')
|
||||
save(s)
|
||||
if body['action'] == 'start':
|
||||
try:
|
||||
subprocess.Popen([sys.executable, str(Path(__file__).resolve()), '--watch'],
|
||||
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
|
||||
start_new_session=True, close_fds=True)
|
||||
except OSError as e:
|
||||
s['active'] = False
|
||||
s['error'] = 'Could not start session worker: ' + str(e)
|
||||
event(s, 'error', s['error'])
|
||||
save(s)
|
||||
raise
|
||||
return current(s, clock())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[1:] == ['--watch']:
|
||||
watch()
|
||||
else:
|
||||
try:
|
||||
if sys.argv[1:] == ['--home']:
|
||||
open_home()
|
||||
print(json.dumps({'home': True}))
|
||||
else:
|
||||
print(json.dumps(command(json.loads(sys.argv[1]))))
|
||||
except Exception as e:
|
||||
print(json.dumps({'error': str(e)}))
|
||||
sys.exit(1)
|
||||
+56
-24
@@ -156,27 +156,59 @@ def flatpaks():
|
||||
return out
|
||||
|
||||
|
||||
uptime = read("/proc/uptime")
|
||||
procs = process_names()
|
||||
print(json.dumps({
|
||||
"time": time.time(),
|
||||
"hostname": socket.gethostname(),
|
||||
"os": os_release(),
|
||||
"uptime": float(uptime.split()[0]) if uptime else None,
|
||||
"battery": battery(),
|
||||
"power": power_source(),
|
||||
"disk": {"root": disk("/"), "home": disk("/home")},
|
||||
"memory": memory(),
|
||||
"temp": max_temp(),
|
||||
"wifi": wifi(),
|
||||
"ip": ip_addr(),
|
||||
"volume": volume(),
|
||||
"services": {
|
||||
"steamvr": "vrserver" in procs,
|
||||
"desktop": "plasmashell" in procs,
|
||||
"lepton": port_listening(5555),
|
||||
"rdp": "xrdp" in procs,
|
||||
},
|
||||
"games": games(),
|
||||
"flatpaks": flatpaks(),
|
||||
}))
|
||||
def thermal_alerts():
|
||||
"""Use the kernel's per-zone hot/critical trips, never a guessed chip limit."""
|
||||
alerts, known = [], False
|
||||
for z in glob.glob("/sys/class/thermal/thermal_zone*"):
|
||||
t = num(z + "/temp", 0.001)
|
||||
for trip in glob.glob(z + "/trip_point_*_type"):
|
||||
if read(trip) not in ("hot", "critical"):
|
||||
continue
|
||||
limit = num(trip[:-4] + "temp", 0.001)
|
||||
if t is not None and limit is not None and limit > 0:
|
||||
known = True
|
||||
if t >= limit:
|
||||
alerts.append({"zone": read(z + "/type"), "tempC": t, "limitC": limit})
|
||||
return alerts if known else None
|
||||
|
||||
|
||||
def activity_level():
|
||||
try:
|
||||
rows = json.loads(run("/opt/steamvr/bin/linuxarm64/vrcmd", "--stats"))
|
||||
if not isinstance(rows, list):
|
||||
return None
|
||||
return next((r.get("activity_level") for r in rows
|
||||
if isinstance(r, dict) and r.get("operation") == "status"), None)
|
||||
except (ValueError, TypeError):
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
uptime = read("/proc/uptime")
|
||||
procs = process_names()
|
||||
print(json.dumps({
|
||||
"time": time.time(),
|
||||
"hostname": socket.gethostname(),
|
||||
"os": os_release(),
|
||||
"uptime": float(uptime.split()[0]) if uptime else None,
|
||||
"battery": battery(),
|
||||
"power": power_source(),
|
||||
"disk": {"root": disk("/"), "home": disk("/home")},
|
||||
"memory": memory(),
|
||||
"temp": max_temp(),
|
||||
"wifi": wifi(),
|
||||
"ip": ip_addr(),
|
||||
"volume": volume(),
|
||||
"services": {
|
||||
"steamvr": "vrserver" in procs,
|
||||
"desktop": "plasmashell" in procs,
|
||||
"lepton": port_listening(5555),
|
||||
"rdp": "xrdp" in procs,
|
||||
},
|
||||
"games": games(),
|
||||
"flatpaks": flatpaks(),
|
||||
}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
+127
-1
@@ -102,6 +102,7 @@
|
||||
.shelf-head .count { color: var(--muted); font-size: 13px; }
|
||||
.shelf-head .spacer { flex: 1; }
|
||||
.sub { color: var(--muted); font-size: 12.5px; }
|
||||
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
||||
.hint { color: var(--muted); font-size: 12.5px; margin-top: 11px; line-height: 1.5; }
|
||||
|
||||
/* ---- buttons ---- */
|
||||
@@ -360,7 +361,7 @@
|
||||
.disp .k2 { color: var(--muted); font-size: 11px; letter-spacing: 1px; text-transform: uppercase; margin: 12px 0 5px; }
|
||||
.disp .seg { flex-wrap: wrap; }
|
||||
.disp .seg button { padding: 0 10px; }
|
||||
.disp input[type=number] { width: 72px; background: rgba(0,0,0,.28); color: var(--text); border: 1px solid transparent;
|
||||
.disp input[type=number], #comfort input[type=number] { width: 72px; background: rgba(0,0,0,.28); color: var(--text); border: 1px solid transparent;
|
||||
border-radius: 3px; height: 32px; padding: 0 8px; font: inherit; font-size: 13px; }
|
||||
/* Touch screens can't hover: keep the library's name and Play button showing. */
|
||||
@media (hover: none) { .capsule .over { opacity: 1; } .capsule:hover { transform: none; } }
|
||||
@@ -575,6 +576,36 @@
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<section class="panel" id="comfort" style="margin:20px 0;padding:16px">
|
||||
<div class="shelf-head"><h2>Family and comfort</h2><span class="spacer"></span>
|
||||
<button class="action small" id="castBtn">Cast headset view</button>
|
||||
</div>
|
||||
<p class="hint">Share this screen with people in the room. Casting shows everything the wearer sees, including private content.</p>
|
||||
<form id="comfortForm">
|
||||
<div class="row" style="flex-wrap:wrap;gap:12px">
|
||||
<label>Session limit (minutes) <input id="sessionMinutes" type="number" min="1" max="240" value="30" required style="width:75px"></label>
|
||||
<label>Break every <input id="breakMinutes" type="number" min="0" max="120" value="20" required style="width:75px"> minutes</label>
|
||||
<label>Check in after <input id="stillMinutes" type="number" min="0" max="240" value="30" required style="width:75px"> active minutes</label>
|
||||
</div>
|
||||
<div class="row" style="flex-wrap:wrap;margin:14px 0;gap:14px">
|
||||
<label><input id="batteryAlert" type="checkbox" checked> Alert on low battery</label>
|
||||
<label><input id="heatAlert" type="checkbox" checked> Alert on overheating</label>
|
||||
<button class="action small" id="sessionStart" type="submit">Start session</button>
|
||||
<button class="small" id="sessionCancel" type="button" disabled>Cancel session</button>
|
||||
<button class="small" id="testNotification" type="button">Enable / test notifications</button>
|
||||
</div>
|
||||
</form>
|
||||
<p id="comfortStatus" role="status">Checking session…</p>
|
||||
<p id="comfortNotificationStatus" class="hint" role="status" hidden></p>
|
||||
<p class="hint">A one-minute warning, then Steam Home. Games stay running: save and pause first. Keep this app open and connected for notifications.</p>
|
||||
<details class="hint"><summary>How sessions and alerts work</summary>
|
||||
<p>This is a reminder, not a parental lock. The timer continues on the Frame if you disconnect; a headset restart cancels it. Cancel before changing settings. Set break/check-in to 0 to turn them off.</p>
|
||||
<p>Battery, heat and check-in alerts appear on connected companions during a session. Headset warnings and break reminders continue without a companion. iOS may suspend phone notifications in the background. Breaks and check-ins count SteamVR activity, not confirmed wear time.</p>
|
||||
</details>
|
||||
<div id="comfortEvents" class="hint"></div>
|
||||
<span id="comfortAnnouncement" class="sr-only" aria-live="polite"></span>
|
||||
</section>
|
||||
|
||||
<section class="panel" id="pad">
|
||||
<div class="shelf-head"><h2>Keyboard and trackpad</h2><span class="sub" id="padState"></span><span class="spacer"></span>
|
||||
<button class="small" id="padOn">Turn on</button>
|
||||
@@ -1144,6 +1175,101 @@ function refresh() {
|
||||
return refreshing;
|
||||
}
|
||||
|
||||
// The Frame owns the clock. Poll independently of status and the selected tab.
|
||||
let comfortBusy = false, comfortSeen = new Set(), comfortSession = null, comfortHydrated = false;
|
||||
async function localNotification(message, request = false) {
|
||||
try {
|
||||
if (window.frameApp?.notify) await window.frameApp.notify(message, request);
|
||||
else {
|
||||
if (!("Notification" in window)) throw new Error("This browser has no notifications; use the Frame Control app.");
|
||||
const permission = request ? await Notification.requestPermission() : Notification.permission;
|
||||
if (permission !== "granted") throw new Error("Notifications are off. Enable them in system settings.");
|
||||
new Notification("Frame Control", {body: message});
|
||||
}
|
||||
$("comfortNotificationStatus").hidden = true;
|
||||
} catch (e) {
|
||||
$("comfortNotificationStatus").hidden = false;
|
||||
$("comfortNotificationStatus").textContent = "Notifications aren't available on this device. Check system notification settings, then use Enable / test notifications. Headset reminders continue during an active session.";
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
function renderComfort(s) {
|
||||
const firstSnapshot = !comfortHydrated;
|
||||
comfortHydrated = true;
|
||||
$("sessionStart").disabled = !!s.active;
|
||||
for (const id of ["sessionMinutes", "breakMinutes", "stillMinutes", "batteryAlert", "heatAlert"])
|
||||
$(id).disabled = !!s.active;
|
||||
$("sessionCancel").disabled = !s.active;
|
||||
if (s.id !== comfortSession) {
|
||||
comfortSession = s.id;
|
||||
comfortSeen.clear();
|
||||
if (s.options) for (const [key, value] of Object.entries(s.options)) {
|
||||
const el = $(key === "minutes" ? "sessionMinutes" : key);
|
||||
if (!el) continue;
|
||||
if (el.type === "checkbox") el.checked = value; else el.value = value;
|
||||
}
|
||||
}
|
||||
let statusText = s.error || (s.active
|
||||
? `${Math.ceil(s.remaining / 60)} min until Steam Home · ${s.activity == null ? "activity unknown" : s.activity === 3 ? "headset in standby" : "monitoring"}`
|
||||
: "No session running.");
|
||||
if (s.active && s.unavailable?.length)
|
||||
statusText += " · No readings: " + s.unavailable.join(", ");
|
||||
if ($("comfortStatus").textContent !== statusText) $("comfortStatus").textContent = statusText;
|
||||
let latest = null;
|
||||
for (const e of s.events || []) {
|
||||
if (comfortSeen.has(e.id)) continue;
|
||||
comfortSeen.add(e.id);
|
||||
// Historical events remain visible but never produce a burst on reconnect.
|
||||
if (!firstSnapshot && s.time - e.time >= 0 && s.time - e.time < 30 && !["started", "cancelled"].includes(e.kind)) {
|
||||
latest = e.message;
|
||||
log(e.message); toast(e.message, e.kind === "error");
|
||||
localNotification(e.message).catch(() => {}); // the notification status keeps the failure visible
|
||||
}
|
||||
}
|
||||
// Keep only the server's bounded history; a new page seeds it without replay.
|
||||
comfortSeen = new Set((s.events || []).map(e => e.id));
|
||||
if (latest !== null) $("comfortAnnouncement").textContent = latest;
|
||||
const history = (s.events || []).slice(-3).map(e => e.message).join(" · ");
|
||||
if ($("comfortEvents").textContent !== history) $("comfortEvents").textContent = history;
|
||||
}
|
||||
async function pollComfort() {
|
||||
if (!comfortBusy) {
|
||||
comfortBusy = true;
|
||||
try { renderComfort(await api("/api/comfort", {action: "status"})); }
|
||||
catch (e) {
|
||||
const message = "Session status unavailable: " + e.message;
|
||||
if ($("comfortStatus").textContent !== message) $("comfortStatus").textContent = message;
|
||||
}
|
||||
finally { comfortBusy = false; }
|
||||
}
|
||||
setTimeout(pollComfort, 5000);
|
||||
}
|
||||
$("comfortForm").onsubmit = async e => {
|
||||
e.preventDefault();
|
||||
const result = await act("Start session", () => api("/api/comfort", {
|
||||
action: "start", minutes: Number($("sessionMinutes").value), breakMinutes: Number($("breakMinutes").value),
|
||||
stillMinutes: Number($("stillMinutes").value), batteryAlert: $("batteryAlert").checked, heatAlert: $("heatAlert").checked,
|
||||
}), $("sessionStart"));
|
||||
if (result) renderComfort(result);
|
||||
};
|
||||
$("sessionCancel").onclick = async () => {
|
||||
const result = await act("Cancel session", () => api("/api/comfort", {action: "cancel"}), $("sessionCancel"));
|
||||
if (result) renderComfort(result);
|
||||
};
|
||||
$("testNotification").onclick = () => act("Test notification", async () => {
|
||||
await localNotification("Comfort notifications are enabled on this device.", true);
|
||||
return {message: "Test notification sent. Check your device's notification settings if it didn't appear."};
|
||||
});
|
||||
$("castBtn").onclick = () => {
|
||||
setView("headset");
|
||||
if (!live) toggleLive(true);
|
||||
$("viewer").scrollIntoView({behavior: "smooth", block: "center"});
|
||||
// Fullscreen is a direct user gesture; iPhone falls back to its inline viewer.
|
||||
$("viewer").requestFullscreen?.().catch(() => {});
|
||||
};
|
||||
pollComfort();
|
||||
|
||||
// ---- battery ----
|
||||
function battery(b, power) {
|
||||
const pct = b?.percent;
|
||||
|
||||
+33
-1
@@ -44,6 +44,7 @@ import frame_assistant # noqa: E402
|
||||
import frame_android # noqa: E402
|
||||
import frame_apk_versions # noqa: E402
|
||||
import frame_catalog # noqa: E402
|
||||
import frame_comfort # noqa: E402
|
||||
import frame_host # noqa: E402
|
||||
import frame_macview # noqa: E402
|
||||
import frame_media # noqa: E402
|
||||
@@ -271,6 +272,37 @@ def status(_body):
|
||||
return s
|
||||
|
||||
|
||||
def comfort(body):
|
||||
try:
|
||||
frame_comfort.validate(body)
|
||||
except ValueError as e:
|
||||
raise Failure(str(e), 400)
|
||||
# Content-addressed, user-only helper bundle. Desktop and phone use the same
|
||||
# on-headset state/lock; no listener, service registration or third-party app.
|
||||
import hashlib
|
||||
files = {name: (HERE / name).read_text() for name in
|
||||
("frame_comfort.py", "frame_status.py", "frame_steam.py")}
|
||||
version = hashlib.sha256(json.dumps(files, sort_keys=True).encode()).hexdigest()[:16]
|
||||
script = """import json, os, pathlib, subprocess, sys
|
||||
os.umask(0o077)
|
||||
files = %r
|
||||
root = pathlib.Path.home() / '.cache/frame-control/comfort' / %r
|
||||
root.mkdir(parents=True, exist_ok=True)
|
||||
for name, source in files.items():
|
||||
path = root / name
|
||||
if not path.exists():
|
||||
tmp = root / (name + '.' + str(os.getpid()))
|
||||
tmp.write_text(source)
|
||||
tmp.replace(path)
|
||||
r = subprocess.run([sys.executable, str(root / 'frame_comfort.py'), %r], capture_output=True, text=True)
|
||||
print(r.stdout, end='')
|
||||
""" % (files, version, json.dumps(body))
|
||||
out = json.loads(ssh("python3 -", stdin=script, timeout=65))
|
||||
if out.get("error") and "active" not in out:
|
||||
raise Failure(out["error"], 409)
|
||||
return out
|
||||
|
||||
|
||||
def headset_view():
|
||||
"""Both eyes as SteamVR composites them (see frame_vrshot.py); PNG bytes."""
|
||||
# `timeout`: VR_Init can block if SteamVR is restarting.
|
||||
@@ -1894,7 +1926,7 @@ def agent_approval(body):
|
||||
return frame_agent.approvals.decide(body.get("confirmation"), body.get("accept"))
|
||||
|
||||
|
||||
POST = {"/api/media": media, "/api/agent/call": agent_call, "/api/agent/approval": agent_approval,
|
||||
POST = {"/api/comfort": comfort, "/api/media": media, "/api/agent/call": agent_call, "/api/agent/approval": agent_approval,
|
||||
"/api/assistant/chat": assistant_chat, "/api/android/display": android_display, "/api/android": android, "/api/titles": titles, "/api/launch": launch, "/api/steam": steam, "/api/volume": set_volume, "/api/clipboard": clipboard,
|
||||
"/api/input": remote_input, "/api/touch": remote_touch,
|
||||
"/api/flatpak": flatpak, "/api/open": open_thing, "/api/shots/save": save_shots,
|
||||
|
||||
Reference in new issue
Block a user