Files
ai-agent/frontend/scripts/push-icons.mjs
gabrielvidalandClaude Opus 5.5 c80c9e2323 feat(notifications): notification channels a plugin contributes; Home Assistant delivery leaves the core
A plugin declaring provides: {"notify.channel": "<action>"} gets every
push, ask and clear of the person who installed it (notifications/channels.py),
the payload the HA webhook always got. Tried once, no retry; with no channel
a push is still in the app (an in_app record, ok) and on the browsers, which
stay core. Guests' own channel installs get their wording and guest link.

Removed: the webhook list (Settings → Webhooks, /api/webhooks*, forward(),
the seeded HA webhook) and integrations/home-assistant, now in the
home-assistant-push plugin (ai-agent-plugins). The old webhook's URL and PWA
package are carried over once into the plugin's data. /settings/webhooks
redirects to the plugin. Forms ha-push-as-a-plugin_yjj2n0,
browser-push-as-a-plugin_7id9we.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 17:50:55 +01:00

92 lines
3.8 KiB
JavaScript

// Render the per-kind push notification icons into public/push/ — the Web Push
// twin of the Home Assistant integration's per-type icon + colour
// (ai-agent-plugins: home-assistant-push/integration/.../const.py TYPE_STYLES). Each style gets:
// <style>.png 192 px, the glyph in white on a disc of its colour —
// the notification's large icon
// <style>-badge.png 96 px, the glyph alone in white — Android's status-bar
// badge (only its alpha is drawn)
// Browsers can't draw an SVG notification icon, hence PNGs, rendered by a real
// Chromium. The PNGs are committed; re-run after changing STYLES:
//
// PW=~/homelab/.claude/skills/page-scrape/node_modules/playwright \
// node scripts/push-icons.mjs
//
// The backend's type → style map (backend/users/push_style.py) must name the
// same styles.
import { readFileSync, mkdirSync } from "node:fs";
import { createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath } from "node:url";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const OUT = path.join(HERE, "..", "public", "push");
const ICONS = path.join(HERE, "..", "node_modules", "lucide-react", "dist", "esm", "icons");
// style → [lucide icon, colour] — the colours are the HA integration's.
export const STYLES = {
deploy: ["rocket", "#7c3aed"],
code: ["code", "#2563eb"],
build: ["hammer", "#d97706"],
git: ["git-branch", "#ea580c"],
service: ["container", "#0ea5e9"],
ai: ["bot", "#9333ea"],
music: ["music", "#16a34a"],
media: ["clapperboard", "#db2777"],
research: ["file-search", "#0d9488"],
logs: ["chart-line", "#65a30d"],
dns: ["network", "#0891b2"],
security: ["shield", "#dc2626"],
mail: ["mail", "#4f46e5"],
success: ["circle-check", "#16a34a"],
backup: ["cloud-upload", "#0d9488"],
error: ["circle-alert", "#dc2626"],
warn: ["triangle-alert", "#d97706"],
ask: ["message-circle-question", "#7c3aed"],
form: ["clipboard-list", "#7c3aed"],
default: ["bell", "#6b7280"],
};
/** A lucide icon's SVG children, read off its ESM module (no React needed). */
function glyph(name) {
const src = readFileSync(path.join(ICONS, `${name}.js`), "utf8");
const start = src.indexOf("[", src.indexOf("createLucideIcon("));
const end = src.lastIndexOf("]);");
const nodes = new Function(`return ${src.slice(start, end + 1)}`)();
return nodes
.map(([tag, attrs]) => {
const a = Object.entries(attrs)
.filter(([k]) => k !== "key")
.map(([k, v]) => `${k}="${v}"`)
.join(" ");
return `<${tag} ${a}/>`;
})
.join("");
}
const svg = (inner, size, bg) =>
`<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24">` +
(bg ? `<circle cx="12" cy="12" r="12" fill="${bg}"/>` : "") +
`<g transform="${bg ? "translate(5.4 5.4) scale(0.55)" : "translate(1.5 1.5) scale(0.875)"}" fill="none" ` +
`stroke="#fff" stroke-width="${bg ? 2 : 2.4}" stroke-linecap="round" stroke-linejoin="round">${inner}</g></svg>`;
const require = createRequire(import.meta.url);
const { chromium } = require(process.env.PW || "playwright");
mkdirSync(OUT, { recursive: true });
const browser = await chromium.launch();
const page = await browser.newPage();
for (const [style, [icon, colour]] of Object.entries(STYLES)) {
const g = glyph(icon);
for (const [file, size, bg] of [
[`${style}.png`, 192, colour],
[`${style}-badge.png`, 96, null],
]) {
await page.setViewportSize({ width: size, height: size });
await page.setContent(
`<html><body style="margin:0;background:transparent">${svg(g, size, bg)}</body></html>`,
);
await page.locator("svg").screenshot({ path: path.join(OUT, file), omitBackground: true });
}
}
await browser.close();
console.log(`${Object.keys(STYLES).length} styles → ${OUT}`);