1a6308aba7
A test and code-analysis round of 0.2.72 to 0.2.76 (suites at every tag, sanitizers, ESP32 and GitHub builds, host harnesses on both boards, the editor in a browser, best practice checked against ESPHome, LVGL, Home Assistant and Vue) found these, fixed here with Max's choices for the product questions: - Firmware 0.2.65: the second hand of a single analog clock moves again; on a page that is one full on/off tile the waking push also switches it; on the Guition a flick is never a tap and a finger that slides off a tile doesn't tap it; Previous/Next react to a firm press; the same Go to page tile may sit on several pages; a layout the screen has no memory for is refused instead of crashing; 64-bit redraw mask for 48 tiles; Montserrat 14 no longer built. - App: Save refuses a layout too long for one message or too big for eight pages; an offline screen keeps its firmware version from the device registry; HA refusals reach the editor; 128 KB requests; changelog out of the live stream; cached hashed assets; tini as init and a clean stop; changelog parsing without asterisks or crashes. - Editor: clicking the open screen keeps unsaved edits, edits during a save stay unsaved, a Page row and phone dragging to other pages, repeated page tiles, limits from the server, HA's error messages, a type-checked build. - tools/check.sh + GitHub Actions + a CYD flash budget; docs match 48 tiles and the new editor. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
37 lines
1.6 KiB
TypeScript
37 lines
1.6 KiB
TypeScript
// Relative URLs on purpose: the page lives under Home Assistant's ingress path
|
|
// (/api/hassio_ingress/<token>/) and on http://127.0.0.1:8099 in SCREEN_DEV; `api/...`
|
|
// resolves against the page in both. Writes carry the CSRF token the inventory handed out.
|
|
let csrf = "";
|
|
export function setCsrf(token: string) {
|
|
csrf = token || "";
|
|
}
|
|
|
|
export async function api(path: string, options: RequestInit = {}): Promise<Response> {
|
|
const response = await fetch(`api/${path}`, {
|
|
...options,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
"X-Screen-CSRF": csrf,
|
|
...(options.headers as Record<string, string> | undefined),
|
|
},
|
|
});
|
|
if (!response.ok) {
|
|
// Any answer with a JSON {"error": "..."} says what went wrong, such as Home Assistant refusing an action (400) or
|
|
// not answering in time (503, app 0.2.78); anything else, like an error page of the ingress proxy, gets this one.
|
|
let message = "That didn't work. Refresh the page and try again.";
|
|
try {
|
|
const error = (await response.json())?.error;
|
|
if (typeof error === "string" && error.trim()) message = error;
|
|
} catch {}
|
|
throw new Error(message);
|
|
}
|
|
return response;
|
|
}
|
|
|
|
export const getJson = async <T = any>(path: string): Promise<T> => (await api(path)).json();
|
|
export const send = async <T = any>(path: string, method: string, body?: unknown, extra: RequestInit = {}): Promise<T> => {
|
|
const response = await api(path, { method, body: body === undefined ? undefined : JSON.stringify(body), ...extra });
|
|
const text = await response.text();
|
|
return (text ? JSON.parse(text) : null) as T;
|
|
};
|