| index e79a27b..5a40541 100644 | ||
| --- a/Makefile | ||
| +++ b/Makefile | ||
| @@ -1,4 +1,4 @@ | ||
| 1 | -# plugin_hello — ScorpioX Bot open-source starter plugin | |
| 1 | +# plugin_hello — SCORPIOX BOT open-source starter plugin | |
| 2 | 2 | # |
| 3 | 3 | # Targets: |
| 4 | 4 | # make native build -> ./plugin_hello |
| index 567a5b7..764def0 100644 | ||
| --- a/README.md | ||
| +++ b/README.md | ||
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | # scorpiox-bot-plugin-hello |
| 2 | 2 | |
| 3 | -**The canonical clean-room starter plugin for [ScorpioX Bot](https://bot.scorpiox.net).** | |
| 3 | +**The canonical clean-room starter plugin for [SCORPIOX BOT](https://bot.scorpiox.net).** | |
| 4 | 4 | |
| 5 | 5 | One C file. Zero dependencies. Three modes. Fork it, change a string, rebuild in one |
| 6 | 6 | command, and you have your own plugin running on your node — no server restart, no SDK, |
| @@ -13,14 +13,14 @@ make | ||
| 13 | 13 | cp plugin_hello ~/.scorpiox/plugins/ |
| 14 | 14 | ``` |
| 15 | 15 | |
| 16 | -Open ScorpioX Bot → the **hello** plugin appears in Settings → Menus → Plugins, the | |
| 16 | +Open SCORPIOX BOT → the **hello** plugin appears in Settings → Menus → Plugins, the | |
| 17 | 17 | Sessions Hub `⋯` menu, and the Chat floating window. |
| 18 | 18 | |
| 19 | 19 | --- |
| 20 | 20 | |
| 21 | 21 | ## What it does |
| 22 | 22 | |
| 23 | -A ScorpioX Bot dynamic plugin is a single native executable named `plugin_<id>` that | |
| 23 | +A SCORPIOX BOT dynamic plugin is a single native executable named `plugin_<id>` that | |
| 24 | 24 | lives in the node's plugin directory (`~/.scorpiox/plugins/`, `/workspace/.scorpiox/plugins/`, |
| 25 | 25 | or `%LOCALAPPDATA%\scorpiox\plugins\` on Windows). The node discovers it live — drop the |
| 26 | 26 | file in, and it is available. Nothing is recompiled, no daemon is restarted. |
| @@ -202,4 +202,4 @@ scorpiox-bot-plugin-hello/ | ||
| 202 | 202 | |
| 203 | 203 | MIT — see [LICENSE](LICENSE). Fork it, ship it, rename it, sell it. Just keep the notice. |
| 204 | 204 | |
| 205 | -Published as part of the [ScorpioX Bot plugin marketplace](https://plugingit.scorpiox.net). | |
| 205 | +Published as part of the [SCORPIOX BOT plugin marketplace](https://plugingit.scorpiox.net). |
| index b64bc2b..ecb2c1c 100644 | ||
| --- a/plugin.json | ||
| +++ b/plugin.json | ||
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | { |
| 2 | 2 | "slug": "hello", |
| 3 | 3 | "id": "plugin_hello", |
| 4 | - "title": "ScorpioX Bot Starter Plugin", | |
| 4 | + "title": "SCORPIOX BOT Starter Plugin", | |
| 5 | 5 | "summary": "Clean-room C99 reference plugin demonstrating the single-binary three-mode contract: metadata, JSON node API and a responsive dark/light HTML bench.", |
| 6 | 6 | "category": "utilities", |
| 7 | 7 | "license": "MIT", |
| index 8ee873d..a6308de 100755 | ||
| --- a/release-dist.sh | ||
| +++ b/release-dist.sh | ||
| @@ -28,7 +28,7 @@ set -euo pipefail | ||
| 28 | 28 | |
| 29 | 29 | SLUG="hello" |
| 30 | 30 | ID="plugin_hello" |
| 31 | -VERSION="1.1.1" | |
| 31 | +VERSION="1.1.2" | |
| 32 | 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" |
| 33 | 33 | |
| 34 | 34 | ROOT="$(cd "$(dirname "$0")" && pwd)" |
| @@ -226,7 +226,7 @@ target_meta() { # target_meta <key> <file> <format> <relpath> <name> | ||
| 226 | 226 | printf ' "id": "%s",\n' "$ID" |
| 227 | 227 | printf ' "name": "hello",\n' |
| 228 | 228 | printf ' "desc": "Starter demo",\n' |
| 229 | - printf ' "title": "ScorpioX Bot Starter Plugin",\n' | |
| 229 | + printf ' "title": "SCORPIOX BOT Starter Plugin",\n' | |
| 230 | 230 | printf ' "summary": "Clean-room C99 reference plugin demonstrating the single-binary three-mode contract: metadata, JSON node API and a responsive dark/light HTML bench.",\n' |
| 231 | 231 | printf ' "category": "utilities",\n' |
| 232 | 232 | printf ' "version": "%s",\n' "$VERSION" |
| 1 | 1 | new file mode 100644 |
| index 0000000..0dd243b | ||
| --- /dev/null | ||
| +++ b/src/bot_theme_plugin.h | ||
| @@ -0,0 +1,129 @@ | ||
| 1 | +/* | |
| 2 | + * bot_theme_plugin.h -- SCORPIOX BOT theme tokens for node plugins. | |
| 3 | + * | |
| 4 | + * A trimmed copy of scorpiox-bot-web/bot_theme.h (the bot's single source of | |
| 5 | + * truth for its dual theme). A plugin runs inside the bot (Hub modal, Session | |
| 6 | + * Card modal, Chat floating window) or in its own tab, and in every case it | |
| 7 | + * must look like part of the bot: same tokens, same dark/light pair, same | |
| 8 | + * localStorage key, same prepaint order. | |
| 9 | + * | |
| 10 | + * Three rules, and nothing else: | |
| 11 | + * | |
| 12 | + * 1. Colours come from these tokens only. No plugin-private palette. | |
| 13 | + * 2. The theme is decided BEFORE first paint, in this order: | |
| 14 | + * ?theme=light|dark -> localStorage.bot_theme -> prefers-color-scheme | |
| 15 | + * so a plugin opened from the bot paints in the bot's theme from frame 0. | |
| 16 | + * 3. When the bot's theme changes it posts {type:'sx-theme',theme:'...'} into | |
| 17 | + * this window; the plugin follows without a reload. The plugin asks once | |
| 18 | + * with {type:'sx-theme-request'} at startup, which covers the case where | |
| 19 | + * it was already open when the bot changed theme. | |
| 20 | + * | |
| 21 | + * The bottom of :root carries aliases for the names older plugin CSS already | |
| 22 | + * uses (--surface, --surface2, --muted, --accent, --accent2, --danger, --warn, | |
| 23 | + * --ok), so adopting the bot palette is a swap, not a redesign. Because they | |
| 24 | + * are var() references, one definition covers both themes. | |
| 25 | + * | |
| 26 | + * MIT License. Copyright (c) 2026 SCORPIOX INC. | |
| 27 | + */ | |
| 28 | +#ifndef SX_BOT_THEME_PLUGIN_H | |
| 29 | +#define SX_BOT_THEME_PLUGIN_H | |
| 30 | + | |
| 31 | +/* Dark is the default; light is applied by html[data-theme=light] (chosen by | |
| 32 | + * ?theme= or the bot) or by prefers-color-scheme when nothing chose. */ | |
| 33 | +#define SX_BOT_THEME_TOKENS \ | |
| 34 | +":root{color-scheme:dark;" \ | |
| 35 | + "--bg:#000000;--bg-2:#08080a;--bg-card:#1c1c1e;" \ | |
| 36 | + "--surface-2:rgba(255,255,255,.06);--surface-hover:rgba(255,255,255,.05);" \ | |
| 37 | + "--line:rgba(255,255,255,.08);--line-2:rgba(255,255,255,.16);--border:rgba(255,255,255,.08);" \ | |
| 38 | + "--text:#f5f5f7;--text-2:#86868b;--dim:#86868b;" \ | |
| 39 | + "--blue:#0a84ff;--green:#30d158;--orange:#ff9f0a;--red:#ff453a;--gray:#8e8e93;" \ | |
| 40 | + "--indigo:#5e5ce6;--teal:#64d2ff;--purple:#bf5af2;--yellow:#ffd60a;" \ | |
| 41 | + "--input-bg:rgba(255,255,255,.04);--modal-bg:#1c1c1e;--menu-bg:#1c1c1e;--code-bg:rgba(255,255,255,.06);" \ | |
| 42 | + "--mono:'SF Mono',ui-monospace,Menlo,Consolas,'DejaVu Sans Mono',monospace;" \ | |
| 43 | + "--font:-apple-system,BlinkMacSystemFont,'SF Pro Display','SF Pro Text','Inter','Segoe UI',Roboto,Helvetica,Arial,sans-serif;" \ | |
| 44 | + "--shadow:0 1px 2px rgba(0,0,0,.35);" \ | |
| 45 | + "--shadow-lg:0 30px 80px rgba(0,0,0,.65),0 0 0 1px rgba(255,255,255,.04);" \ | |
| 46 | + "--ease:cubic-bezier(.16,1,.3,1);" \ | |
| 47 | + "--surface:var(--bg-card);--surface2:var(--surface-2);--muted:var(--text-2);" \ | |
| 48 | + "--accent:var(--blue);--accent2:var(--green);--accent-dim:#0071e3;" \ | |
| 49 | + "--danger:var(--red);--err:var(--red);--warn:var(--orange);--ok:var(--green);" \ | |
| 50 | +"}" \ | |
| 51 | +"@media (prefers-color-scheme:light){html:not([data-theme=dark]){" \ | |
| 52 | + "--bg:#f5f5f7;--bg-2:#ffffff;--bg-card:#ffffff;" \ | |
| 53 | + "--surface-2:rgba(0,0,0,.04);--surface-hover:#ffffff;" \ | |
| 54 | + "--line:rgba(0,0,0,.06);--line-2:rgba(0,0,0,.12);--border:rgba(0,0,0,.06);" \ | |
| 55 | + "--text:#1d1d1f;--text-2:#6e6e73;--dim:#6e6e73;" \ | |
| 56 | + "--blue:#007aff;--green:#34c759;--orange:#ff9500;--red:#ff3b30;--gray:#8e8e93;" \ | |
| 57 | + "--indigo:#5856d6;--teal:#32ade6;--purple:#af52de;--yellow:#b8860b;" \ | |
| 58 | + "--accent-dim:#0066d6;" \ | |
| 59 | + "--input-bg:#f5f5f7;--modal-bg:#ffffff;--menu-bg:#ffffff;--code-bg:rgba(0,0,0,.05);" \ | |
| 60 | + "--shadow:0 2px 10px rgba(0,0,0,.03);" \ | |
| 61 | + "--shadow-lg:0 30px 80px rgba(0,0,0,.18),0 0 0 1px rgba(0,0,0,.04);" \ | |
| 62 | + "color-scheme:light}}" \ | |
| 63 | +"html[data-theme=light]{" \ | |
| 64 | + "--bg:#f5f5f7;--bg-2:#ffffff;--bg-card:#ffffff;" \ | |
| 65 | + "--surface-2:rgba(0,0,0,.04);--surface-hover:#ffffff;" \ | |
| 66 | + "--line:rgba(0,0,0,.06);--line-2:rgba(0,0,0,.12);--border:rgba(0,0,0,.06);" \ | |
| 67 | + "--text:#1d1d1f;--text-2:#6e6e73;--dim:#6e6e73;" \ | |
| 68 | + "--blue:#007aff;--green:#34c759;--orange:#ff9500;--red:#ff3b30;--gray:#8e8e93;" \ | |
| 69 | + "--indigo:#5856d6;--teal:#32ade6;--purple:#af52de;--yellow:#b8860b;" \ | |
| 70 | + "--accent-dim:#0066d6;" \ | |
| 71 | + "--input-bg:#f5f5f7;--modal-bg:#ffffff;--menu-bg:#ffffff;--code-bg:rgba(0,0,0,.05);" \ | |
| 72 | + "--shadow:0 2px 10px rgba(0,0,0,.03);" \ | |
| 73 | + "--shadow-lg:0 30px 80px rgba(0,0,0,.18),0 0 0 1px rgba(0,0,0,.04);" \ | |
| 74 | + "color-scheme:light}" \ | |
| 75 | +"html{color-scheme:dark}html[data-theme=dark]{color-scheme:dark}" \ | |
| 76 | +"*{box-sizing:border-box}" \ | |
| 77 | +"body{margin:0;background:var(--bg);color:var(--text);font-family:var(--font);" \ | |
| 78 | + "-webkit-font-smoothing:antialiased}" \ | |
| 79 | +"button{font-family:inherit;letter-spacing:inherit}" \ | |
| 80 | +"button:active{transform:scale(.98)}" \ | |
| 81 | +"select option{background:var(--menu-bg);color:var(--text)}" \ | |
| 82 | +"a{color:var(--blue);text-decoration:none;font-weight:600}" \ | |
| 83 | +"/* Embed mode (?embed=1): the host owns the title and the theme, so the plugin" \ | |
| 84 | +" * hides its own back link and its own toggle. */" \ | |
| 85 | +"html.embedded .embed-hide,html.embedded #themeToggle{display:none!important}" \ | |
| 86 | +"@media(prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important}}" | |
| 87 | + | |
| 88 | +/* Pre-paint: decide the theme before the first frame. Must be the first thing | |
| 89 | + * in <head> so there is no flash of the wrong theme. Also flags embed mode as | |
| 90 | + * html.embedded so the embed rules apply before first paint. */ | |
| 91 | +#define SX_BOT_THEME_PREPAINT \ | |
| 92 | +"<script>(function(){var t='';" \ | |
| 93 | +"try{var m=/[?&]theme=(light|dark)/.exec(location.search);if(m)t=m[1];}catch(e){}" \ | |
| 94 | +"if(!t){try{var s=localStorage.getItem('bot_theme');if(s==='light'||s==='dark')t=s;}catch(e){}}" \ | |
| 95 | +"if(!t){try{t=(window.matchMedia&&window.matchMedia('(prefers-color-scheme: light)').matches)?'light':'dark';}catch(e){t='dark';}}" \ | |
| 96 | +"document.documentElement.setAttribute('data-theme',t);" \ | |
| 97 | +"try{if(/[?&]embed=(1|true)(&|$)/.test(location.search))document.documentElement.classList.add('embedded');}catch(e){}" \ | |
| 98 | +"try{localStorage.setItem('bot_theme',t);}catch(e){}" \ | |
| 99 | +"})();</script>\n" | |
| 100 | + | |
| 101 | +/* Handoff: follow the bot. The host posts {type:'sx-theme',theme}; we ask once | |
| 102 | + * at startup in case it changed while this page was already open. Fires the | |
| 103 | + * same 'bot-theme' CustomEvent the bot pages use, so canvas surfaces can | |
| 104 | + * re-skin themselves from one listener. */ | |
| 105 | +#define SX_BOT_THEME_HANDOFF \ | |
| 106 | +"<script>(function(){" \ | |
| 107 | +"function apply(t){if(t!=='light'&&t!=='dark')return;" \ | |
| 108 | +"if(document.documentElement.getAttribute('data-theme')===t)return;" \ | |
| 109 | +"document.documentElement.setAttribute('data-theme',t);" \ | |
| 110 | +"try{localStorage.setItem('bot_theme',t);}catch(e){}" \ | |
| 111 | +"try{window.dispatchEvent(new CustomEvent('bot-theme',{detail:t}));}catch(e){}}" \ | |
| 112 | +"window.sxApplyTheme=apply;" \ | |
| 113 | +"window.sxTheme=function(){var t=document.documentElement.getAttribute('data-theme');return (t==='light'||t==='dark')?t:'dark';};" \ | |
| 114 | +"window.addEventListener('message',function(e){var d=e&&e.data;if(d&&d.type==='sx-theme')apply(d.theme);});" \ | |
| 115 | +"try{if(window.parent&&window.parent!==window)window.parent.postMessage({type:'sx-theme-request'},'*');}catch(e){}" \ | |
| 116 | +"})();</script>\n" | |
| 117 | + | |
| 118 | +/* Standalone toggle (hidden in embed mode by the CSS above). Only useful when | |
| 119 | + * the plugin is opened in its own tab; inside the bot the host owns the theme. | |
| 120 | + * Give it class 'icon-btn'-free styling from the page, or use the helper JS. */ | |
| 121 | +#define SX_BOT_THEME_TOGGLE_BTN \ | |
| 122 | +"<button class='embed-hide' id='themeToggle' type='button' title='Toggle appearance'>Theme</button>" | |
| 123 | + | |
| 124 | +#define SX_BOT_THEME_TOGGLE_JS \ | |
| 125 | +"<script>(function(){var b=document.getElementById('themeToggle');if(!b)return;" \ | |
| 126 | +"b.onclick=function(){window.sxApplyTheme(window.sxTheme()==='dark'?'light':'dark');};" \ | |
| 127 | +"})();</script>\n" | |
| 128 | + | |
| 129 | +#endif /* SX_BOT_THEME_PLUGIN_H */ |
| index ad955ff..23f26e5 100644 | ||
| --- a/src/plugin_hello.c | ||
| +++ b/src/plugin_hello.c | ||
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /* |
| 2 | - * plugin_hello — ScorpioX Bot open-source starter plugin | |
| 2 | + * plugin_hello — SCORPIOX BOT open-source starter plugin | |
| 3 | 3 | * |
| 4 | 4 | * A single clean-room C99 binary that serves THREE modes: |
| 5 | 5 | * 1. --meta / SX_PLUGIN_META=1 -> JSON metadata for discovery |
| @@ -32,9 +32,11 @@ | ||
| 32 | 32 | # include <sys/utsname.h> |
| 33 | 33 | #endif |
| 34 | 34 | |
| 35 | +#include "bot_theme_plugin.h" | |
| 36 | + | |
| 35 | 37 | #define PLUGIN_SLUG "hello" |
| 36 | 38 | #define PLUGIN_ID "plugin_hello" |
| 37 | -#define PLUGIN_VER "1.1.1" | |
| 39 | +#define PLUGIN_VER "1.1.2" | |
| 38 | 40 | |
| 39 | 41 | /* ------------------------------------------------------------------ */ |
| 40 | 42 | /* Query string helpers */ |
| @@ -334,19 +336,12 @@ static int mode_html(int embed) | ||
| 334 | 336 | |
| 335 | 337 | fputs("<!DOCTYPE html>\n<html lang='en'><head><meta charset='utf-8'>" |
| 336 | 338 | "<meta name='viewport' content='width=device-width,initial-scale=1'>" |
| 337 | - "<title>hello</title><style>", stdout); | |
| 338 | - | |
| 339 | + "<title>hello</title>", stdout); | |
| 340 | + /* Theme tokens + prepaint come from src/bot_theme_plugin.h (the bot's own | |
| 341 | + * palette), so ?theme= / the bot's postMessage land before first paint. */ | |
| 342 | + fputs(SX_BOT_THEME_PREPAINT "<style>" SX_BOT_THEME_TOKENS, stdout); | |
| 339 | 343 | fputs( |
| 340 | -":root{color-scheme:dark light;" | |
| 341 | - "--bg:#0d0d10;--surface:#16161a;--surface2:#1e1e24;--text:#f5f5f7;" | |
| 342 | - "--muted:#8e8e96;--line:rgba(255,255,255,.11);--accent:#0a84ff;" | |
| 343 | - "--accent2:#30d158;--danger:#ff453a;--mono:ui-monospace,SFMono-Regular,Menlo,monospace}" | |
| 344 | -"html[data-theme=light]{--bg:#f4f4f7;--surface:#ffffff;--surface2:#f0f0f4;" | |
| 345 | - "--text:#1c1c1e;--muted:#6b6b73;--line:rgba(0,0,0,.10)}" | |
| 346 | -"*{box-sizing:border-box}" | |
| 347 | -"body{margin:0;padding:16px;background:var(--bg);color:var(--text);" | |
| 348 | - "font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;" | |
| 349 | - "font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased}" | |
| 344 | +"body{padding:16px;font-size:14px;line-height:1.5}" | |
| 350 | 345 | ".wrap{max-width:880px;margin:0 auto}" |
| 351 | 346 | ".top{display:flex;align-items:center;gap:10px;margin-bottom:16px;flex-wrap:wrap}" |
| 352 | 347 | ".title{font-size:20px;font-weight:700;margin:0}" |
| @@ -388,7 +383,7 @@ static int mode_html(int embed) | ||
| 388 | 383 | "<span class='pill'>" PLUGIN_VER "</span>" |
| 389 | 384 | "<span class='pill' id='badge'>connecting</span>" |
| 390 | 385 | "<span class='spacer'></span>" |
| 391 | - "<button class='ghost' id='themeBtn' type='button'>Theme</button>" | |
| 386 | + "<button class='ghost embed-hide' id='themeBtn' type='button'>Theme</button>" | |
| 392 | 387 | "<button class='ghost' id='reloadBtn' type='button'>Refresh</button></div>", stdout); |
| 393 | 388 | |
| 394 | 389 | /* ---- live node card ---- */ |
| @@ -474,23 +469,13 @@ static int mode_html(int embed) | ||
| 474 | 469 | " });\n" |
| 475 | 470 | " }\n" |
| 476 | 471 | "\n" |
| 477 | -" function applyTheme(t){\n" | |
| 478 | -" document.documentElement.setAttribute('data-theme', t === 'light' ? 'light' : 'dark');\n" | |
| 479 | -" }\n" | |
| 480 | -" var saved = localStorage.getItem('bot_theme');\n" | |
| 481 | -" applyTheme(saved || (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'));\n" | |
| 482 | -" $('themeBtn').addEventListener('click', function(){\n" | |
| 483 | -" var cur = document.documentElement.getAttribute('data-theme');\n" | |
| 484 | -" var next = cur === 'light' ? 'dark' : 'light';\n" | |
| 485 | -" applyTheme(next);\n" | |
| 486 | -" localStorage.setItem('bot_theme', next);\n" | |
| 487 | -" });\n" | |
| 488 | 472 | " $('reloadBtn').addEventListener('click', refresh);\n" |
| 489 | 473 | " $('echoBtn').addEventListener('click', sendEcho);\n" |
| 490 | 474 | " $('msg').addEventListener('keydown', function(e){ if (e.key === 'Enter') sendEcho(); });\n" |
| 491 | 475 | " refresh();\n" |
| 492 | 476 | "})();\n" |
| 493 | -"</script></body></html>\n", stdout); | |
| 477 | +SX_BOT_THEME_HANDOFF | |
| 478 | +"</body></html>\n", stdout); | |
| 494 | 479 | |
| 495 | 480 | return 0; |
| 496 | 481 | } |
| index 8039ffa..92b10dd 100755 | ||
| --- a/tests/run.sh | ||
| +++ b/tests/run.sh | ||
| @@ -62,7 +62,7 @@ DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/') | ||
| 62 | 62 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 63 | 63 | NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 64 | 64 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" |
| 65 | -check "--version prints version" '1.1.1' "$("$BIN" --version)" | |
| 65 | +check "--version prints version" '1.1.2' "$("$BIN" --version)" | |
| 66 | 66 | |
| 67 | 67 | # ---------------------------------------------------------------- json mode |
| 68 | 68 | section "node auth" |
| @@ -93,7 +93,7 @@ BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d') | ||
| 93 | 93 | check "info ok:true" '"ok":true' "$BODY" |
| 94 | 94 | check "info plugin id" '"plugin":"plugin_hello"' "$BODY" |
| 95 | 95 | check "info slug" '"slug":"hello"' "$BODY" |
| 96 | -check "info version" '"version":"1.1.1"' "$BODY" | |
| 96 | +check "info version" '"version":"1.1.2"' "$BODY" | |
| 97 | 97 | check "info hostname field" '"hostname"' "$BODY" |
| 98 | 98 | check "info os field" '"os"' "$BODY" |
| 99 | 99 | check "info arch field" '"arch"' "$BODY" |
| @@ -134,7 +134,6 @@ HBODY=$(printf '%s' "$HTML" | sed '1,/^\r$/d') | ||
| 134 | 134 | check "html doctype" '<!DOCTYPE html>' "$HBODY" |
| 135 | 135 | check "html title hello" '<title>hello</title>' "$HBODY" |
| 136 | 136 | check "html theme toggle button" 'themeBtn' "$HBODY" |
| 137 | -check "html reads bot_theme" 'bot_theme' "$HBODY" | |
| 138 | 137 | check "html echo button wired" "echoBtn" "$HBODY" |
| 139 | 138 | check "html node info card" 'Live node info' "$HBODY" |
| 140 | 139 | check "html echo tester" 'Echo action tester' "$HBODY" |
| @@ -146,8 +145,24 @@ check "html hub-aware api base" "'/plugins?plugin='" "$HBODY" | ||
| 146 | 145 | check "html direct api base" "'/plugin_hello?action='" "$HBODY" |
| 147 | 146 | check "html send X-Bot-Password" 'X-Bot-Password' "$HBODY" |
| 148 | 147 | check "html responsive viewport" 'width=device-width' "$HBODY" |
| 149 | -check "html light theme block" 'data-theme=light' "$HBODY" | |
| 150 | -check_not "html no internal LAN IP" '192.168.' "$HBODY" | |
| 148 | +check "html light theme block" 'html[data-theme=light]' "$HBODY" | |
| 149 | +check "html reads ?theme=" 'theme=(light|dark)' "$HBODY" | |
| 150 | +check "html reads bot_theme" 'bot_theme' "$HBODY" | |
| 151 | +check "html honours prefers-color" 'prefers-color-scheme' "$HBODY" | |
| 152 | +check "html follows sx-theme posts" "d.type==='sx-theme'" "$HBODY" | |
| 153 | +check "html asks host for theme" "sx-theme-request" "$HBODY" | |
| 154 | +check "html uses bot token --bg-card" '--bg-card' "$HBODY" | |
| 155 | +check "html uses bot token --surface-2" '--surface-2' "$HBODY" | |
| 156 | +check "html uses bot token --text-2" '--text-2' "$HBODY" | |
| 157 | +check "html uses bot accent --teal" '--teal' "$HBODY" | |
| 158 | +check_not "html no private #0d0d10 palette" '#0d0d10' "$HBODY" | |
| 159 | +check_not "html no private #f4f4f7 palette" '#f4f4f7' "$HBODY" | |
| 160 | +check_not "html no retired brand casing" 'Scorpio'"X Bot" "$HBODY" | |
| 161 | +check "html hides toggle when embedded" 'embed-hide' "$HBODY" | |
| 162 | + | |
| 163 | +THEMELIGHT=$(QUERY_STRING='theme=light' "$BIN" | sed '1,/^\r$/d') | |
| 164 | +THEMELIGHT=$(QUERY_STRING='theme=light' "$BIN" | sed '1,/^\r$/d') | |
| 165 | +check "?theme=light still emits the ?theme= reader" 'theme=(light|dark)' "$THEMELIGHT" | |
| 151 | 166 | check_not "html no localhost literal" '127.0.0.1' "$HBODY" |
| 152 | 167 | |
| 153 | 168 | EMBED=$(QUERY_STRING='embed=1' "$BIN" | sed '1,/^\r$/d') |
| 154 | 169 |
| index e79a27b..5a40541 100644 | index e79a27b..5a40541 100644 | ||
| --- a/Makefile | --- a/Makefile | ||
| +++ b/Makefile | +++ b/Makefile | ||
| @@ -1,4 +1,4 @@ | @@ -1,4 +1,4 @@ | ||
| 1 | -# plugin_hello — ScorpioX Bot open-source starter plugin | 1 | +# plugin_hello — SCORPIOX BOT open-source starter plugin |
| 2 | # | 2 | # |
| 3 | # Targets: | 3 | # Targets: |
| 4 | # make native build -> ./plugin_hello | 4 | # make native build -> ./plugin_hello |
| index 567a5b7..764def0 100644 | index 567a5b7..764def0 100644 | ||
| --- a/README.md | --- a/README.md | ||
| +++ b/README.md | +++ b/README.md | ||
| @@ -1,6 +1,6 @@ | @@ -1,6 +1,6 @@ | ||
| 1 | # scorpiox-bot-plugin-hello | 1 | # scorpiox-bot-plugin-hello |
| 2 | 2 | ||
| 3 | -**The canonical clean-room starter plugin for [ScorpioX Bot](https://bot.scorpiox.net).** | 3 | +**The canonical clean-room starter plugin for [SCORPIOX BOT](https://bot.scorpiox.net).** |
| 4 | 4 | ||
| 5 | One C file. Zero dependencies. Three modes. Fork it, change a string, rebuild in one | 5 | One C file. Zero dependencies. Three modes. Fork it, change a string, rebuild in one |
| 6 | command, and you have your own plugin running on your node — no server restart, no SDK, | 6 | command, and you have your own plugin running on your node — no server restart, no SDK, |
| @@ -13,14 +13,14 @@ make | @@ -13,14 +13,14 @@ make | ||
| 13 | cp plugin_hello ~/.scorpiox/plugins/ | 13 | cp plugin_hello ~/.scorpiox/plugins/ |
| 14 | ``` | 14 | ``` |
| 15 | 15 | ||
| 16 | -Open ScorpioX Bot → the **hello** plugin appears in Settings → Menus → Plugins, the | 16 | +Open SCORPIOX BOT → the **hello** plugin appears in Settings → Menus → Plugins, the |
| 17 | Sessions Hub `⋯` menu, and the Chat floating window. | 17 | Sessions Hub `⋯` menu, and the Chat floating window. |
| 18 | 18 | ||
| 19 | --- | 19 | --- |
| 20 | 20 | ||
| 21 | ## What it does | 21 | ## What it does |
| 22 | 22 | ||
| 23 | -A ScorpioX Bot dynamic plugin is a single native executable named `plugin_<id>` that | 23 | +A SCORPIOX BOT dynamic plugin is a single native executable named `plugin_<id>` that |
| 24 | lives in the node's plugin directory (`~/.scorpiox/plugins/`, `/workspace/.scorpiox/plugins/`, | 24 | lives in the node's plugin directory (`~/.scorpiox/plugins/`, `/workspace/.scorpiox/plugins/`, |
| 25 | or `%LOCALAPPDATA%\scorpiox\plugins\` on Windows). The node discovers it live — drop the | 25 | or `%LOCALAPPDATA%\scorpiox\plugins\` on Windows). The node discovers it live — drop the |
| 26 | file in, and it is available. Nothing is recompiled, no daemon is restarted. | 26 | file in, and it is available. Nothing is recompiled, no daemon is restarted. |
| @@ -202,4 +202,4 @@ scorpiox-bot-plugin-hello/ | @@ -202,4 +202,4 @@ scorpiox-bot-plugin-hello/ | ||
| 202 | 202 | ||
| 203 | MIT — see [LICENSE](LICENSE). Fork it, ship it, rename it, sell it. Just keep the notice. | 203 | MIT — see [LICENSE](LICENSE). Fork it, ship it, rename it, sell it. Just keep the notice. |
| 204 | 204 | ||
| 205 | -Published as part of the [ScorpioX Bot plugin marketplace](https://plugingit.scorpiox.net). | 205 | +Published as part of the [SCORPIOX BOT plugin marketplace](https://plugingit.scorpiox.net). |
| index b64bc2b..ecb2c1c 100644 | index b64bc2b..ecb2c1c 100644 | ||
| --- a/plugin.json | --- a/plugin.json | ||
| +++ b/plugin.json | +++ b/plugin.json | ||
| @@ -1,7 +1,7 @@ | @@ -1,7 +1,7 @@ | ||
| 1 | { | 1 | { |
| 2 | "slug": "hello", | 2 | "slug": "hello", |
| 3 | "id": "plugin_hello", | 3 | "id": "plugin_hello", |
| 4 | - "title": "ScorpioX Bot Starter Plugin", | 4 | + "title": "SCORPIOX BOT Starter Plugin", |
| 5 | "summary": "Clean-room C99 reference plugin demonstrating the single-binary three-mode contract: metadata, JSON node API and a responsive dark/light HTML bench.", | 5 | "summary": "Clean-room C99 reference plugin demonstrating the single-binary three-mode contract: metadata, JSON node API and a responsive dark/light HTML bench.", |
| 6 | "category": "utilities", | 6 | "category": "utilities", |
| 7 | "license": "MIT", | 7 | "license": "MIT", |
| index 8ee873d..a6308de 100755 | index 8ee873d..a6308de 100755 | ||
| --- a/release-dist.sh | --- a/release-dist.sh | ||
| +++ b/release-dist.sh | +++ b/release-dist.sh | ||
| @@ -28,7 +28,7 @@ set -euo pipefail | @@ -28,7 +28,7 @@ set -euo pipefail | ||
| 28 | 28 | ||
| 29 | SLUG="hello" | 29 | SLUG="hello" |
| 30 | ID="plugin_hello" | 30 | ID="plugin_hello" |
| 31 | -VERSION="1.1.1" | 31 | +VERSION="1.1.2" |
| 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" | 32 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" |
| 33 | 33 | ||
| 34 | ROOT="$(cd "$(dirname "$0")" && pwd)" | 34 | ROOT="$(cd "$(dirname "$0")" && pwd)" |
| @@ -226,7 +226,7 @@ target_meta() { # target_meta <key> <file> <format> <relpath> <name> | @@ -226,7 +226,7 @@ target_meta() { # target_meta <key> <file> <format> <relpath> <name> | ||
| 226 | printf ' "id": "%s",\n' "$ID" | 226 | printf ' "id": "%s",\n' "$ID" |
| 227 | printf ' "name": "hello",\n' | 227 | printf ' "name": "hello",\n' |
| 228 | printf ' "desc": "Starter demo",\n' | 228 | printf ' "desc": "Starter demo",\n' |
| 229 | - printf ' "title": "ScorpioX Bot Starter Plugin",\n' | 229 | + printf ' "title": "SCORPIOX BOT Starter Plugin",\n' |
| 230 | printf ' "summary": "Clean-room C99 reference plugin demonstrating the single-binary three-mode contract: metadata, JSON node API and a responsive dark/light HTML bench.",\n' | 230 | printf ' "summary": "Clean-room C99 reference plugin demonstrating the single-binary three-mode contract: metadata, JSON node API and a responsive dark/light HTML bench.",\n' |
| 231 | printf ' "category": "utilities",\n' | 231 | printf ' "category": "utilities",\n' |
| 232 | printf ' "version": "%s",\n' "$VERSION" | 232 | printf ' "version": "%s",\n' "$VERSION" |
| 1 | new file mode 100644 | 1 | new file mode 100644 |
| index 0000000..0dd243b | index 0000000..0dd243b | ||
| --- /dev/null | --- /dev/null | ||
| +++ b/src/bot_theme_plugin.h | +++ b/src/bot_theme_plugin.h | ||
| @@ -0,0 +1,129 @@ | @@ -0,0 +1,129 @@ | ||
| 1 | +/* | ||
| 2 | + * bot_theme_plugin.h -- SCORPIOX BOT theme tokens for node plugins. | ||
| 3 | + * | ||
| 4 | + * A trimmed copy of scorpiox-bot-web/bot_theme.h (the bot's single source of | ||
| 5 | + * truth for its dual theme). A plugin runs inside the bot (Hub modal, Session | ||
| 6 | + * Card modal, Chat floating window) or in its own tab, and in every case it | ||
| 7 | + * must look like part of the bot: same tokens, same dark/light pair, same | ||
| 8 | + * localStorage key, same prepaint order. | ||
| 9 | + * | ||
| 10 | + * Three rules, and nothing else: | ||
| 11 | + * | ||
| 12 | + * 1. Colours come from these tokens only. No plugin-private palette. | ||
| 13 | + * 2. The theme is decided BEFORE first paint, in this order: | ||
| 14 | + * ?theme=light|dark -> localStorage.bot_theme -> prefers-color-scheme | ||
| 15 | + * so a plugin opened from the bot paints in the bot's theme from frame 0. | ||
| 16 | + * 3. When the bot's theme changes it posts {type:'sx-theme',theme:'...'} into | ||
| 17 | + * this window; the plugin follows without a reload. The plugin asks once | ||
| 18 | + * with {type:'sx-theme-request'} at startup, which covers the case where | ||
| 19 | + * it was already open when the bot changed theme. | ||
| 20 | + * | ||
| 21 | + * The bottom of :root carries aliases for the names older plugin CSS already | ||
| 22 | + * uses (--surface, --surface2, --muted, --accent, --accent2, --danger, --warn, | ||
| 23 | + * --ok), so adopting the bot palette is a swap, not a redesign. Because they | ||
| 24 | + * are var() references, one definition covers both themes. | ||
| 25 | + * | ||
| 26 | + * MIT License. Copyright (c) 2026 SCORPIOX INC. | ||
| 27 | + */ | ||
| 28 | +#ifndef SX_BOT_THEME_PLUGIN_H | ||
| 29 | +#define SX_BOT_THEME_PLUGIN_H | ||
| 30 | + | ||
| 31 | +/* Dark is the default; light is applied by html[data-theme=light] (chosen by | ||
| 32 | + * ?theme= or the bot) or by prefers-color-scheme when nothing chose. */ | ||
| 33 | +#define SX_BOT_THEME_TOKENS \ | ||
| 34 | +":root{color-scheme:dark;" \ | ||
| 35 | + "--bg:#000000;--bg-2:#08080a;--bg-card:#1c1c1e;" \ | ||
| 36 | + "--surface-2:rgba(255,255,255,.06);--surface-hover:rgba(255,255,255,.05);" \ | ||
| 37 | + "--line:rgba(255,255,255,.08);--line-2:rgba(255,255,255,.16);--border:rgba(255,255,255,.08);" \ | ||
| 38 | + "--text:#f5f5f7;--text-2:#86868b;--dim:#86868b;" \ | ||
| 39 | + "--blue:#0a84ff;--green:#30d158;--orange:#ff9f0a;--red:#ff453a;--gray:#8e8e93;" \ | ||
| 40 | + "--indigo:#5e5ce6;--teal:#64d2ff;--purple:#bf5af2;--yellow:#ffd60a;" \ | ||
| 41 | + "--input-bg:rgba(255,255,255,.04);--modal-bg:#1c1c1e;--menu-bg:#1c1c1e;--code-bg:rgba(255,255,255,.06);" \ | ||
| 42 | + "--mono:'SF Mono',ui-monospace,Menlo,Consolas,'DejaVu Sans Mono',monospace;" \ | ||
| 43 | + "--font:-apple-system,BlinkMacSystemFont,'SF Pro Display','SF Pro Text','Inter','Segoe UI',Roboto,Helvetica,Arial,sans-serif;" \ | ||
| 44 | + "--shadow:0 1px 2px rgba(0,0,0,.35);" \ | ||
| 45 | + "--shadow-lg:0 30px 80px rgba(0,0,0,.65),0 0 0 1px rgba(255,255,255,.04);" \ | ||
| 46 | + "--ease:cubic-bezier(.16,1,.3,1);" \ | ||
| 47 | + "--surface:var(--bg-card);--surface2:var(--surface-2);--muted:var(--text-2);" \ | ||
| 48 | + "--accent:var(--blue);--accent2:var(--green);--accent-dim:#0071e3;" \ | ||
| 49 | + "--danger:var(--red);--err:var(--red);--warn:var(--orange);--ok:var(--green);" \ | ||
| 50 | +"}" \ | ||
| 51 | +"@media (prefers-color-scheme:light){html:not([data-theme=dark]){" \ | ||
| 52 | + "--bg:#f5f5f7;--bg-2:#ffffff;--bg-card:#ffffff;" \ | ||
| 53 | + "--surface-2:rgba(0,0,0,.04);--surface-hover:#ffffff;" \ | ||
| 54 | + "--line:rgba(0,0,0,.06);--line-2:rgba(0,0,0,.12);--border:rgba(0,0,0,.06);" \ | ||
| 55 | + "--text:#1d1d1f;--text-2:#6e6e73;--dim:#6e6e73;" \ | ||
| 56 | + "--blue:#007aff;--green:#34c759;--orange:#ff9500;--red:#ff3b30;--gray:#8e8e93;" \ | ||
| 57 | + "--indigo:#5856d6;--teal:#32ade6;--purple:#af52de;--yellow:#b8860b;" \ | ||
| 58 | + "--accent-dim:#0066d6;" \ | ||
| 59 | + "--input-bg:#f5f5f7;--modal-bg:#ffffff;--menu-bg:#ffffff;--code-bg:rgba(0,0,0,.05);" \ | ||
| 60 | + "--shadow:0 2px 10px rgba(0,0,0,.03);" \ | ||
| 61 | + "--shadow-lg:0 30px 80px rgba(0,0,0,.18),0 0 0 1px rgba(0,0,0,.04);" \ | ||
| 62 | + "color-scheme:light}}" \ | ||
| 63 | +"html[data-theme=light]{" \ | ||
| 64 | + "--bg:#f5f5f7;--bg-2:#ffffff;--bg-card:#ffffff;" \ | ||
| 65 | + "--surface-2:rgba(0,0,0,.04);--surface-hover:#ffffff;" \ | ||
| 66 | + "--line:rgba(0,0,0,.06);--line-2:rgba(0,0,0,.12);--border:rgba(0,0,0,.06);" \ | ||
| 67 | + "--text:#1d1d1f;--text-2:#6e6e73;--dim:#6e6e73;" \ | ||
| 68 | + "--blue:#007aff;--green:#34c759;--orange:#ff9500;--red:#ff3b30;--gray:#8e8e93;" \ | ||
| 69 | + "--indigo:#5856d6;--teal:#32ade6;--purple:#af52de;--yellow:#b8860b;" \ | ||
| 70 | + "--accent-dim:#0066d6;" \ | ||
| 71 | + "--input-bg:#f5f5f7;--modal-bg:#ffffff;--menu-bg:#ffffff;--code-bg:rgba(0,0,0,.05);" \ | ||
| 72 | + "--shadow:0 2px 10px rgba(0,0,0,.03);" \ | ||
| 73 | + "--shadow-lg:0 30px 80px rgba(0,0,0,.18),0 0 0 1px rgba(0,0,0,.04);" \ | ||
| 74 | + "color-scheme:light}" \ | ||
| 75 | +"html{color-scheme:dark}html[data-theme=dark]{color-scheme:dark}" \ | ||
| 76 | +"*{box-sizing:border-box}" \ | ||
| 77 | +"body{margin:0;background:var(--bg);color:var(--text);font-family:var(--font);" \ | ||
| 78 | + "-webkit-font-smoothing:antialiased}" \ | ||
| 79 | +"button{font-family:inherit;letter-spacing:inherit}" \ | ||
| 80 | +"button:active{transform:scale(.98)}" \ | ||
| 81 | +"select option{background:var(--menu-bg);color:var(--text)}" \ | ||
| 82 | +"a{color:var(--blue);text-decoration:none;font-weight:600}" \ | ||
| 83 | +"/* Embed mode (?embed=1): the host owns the title and the theme, so the plugin" \ | ||
| 84 | +" * hides its own back link and its own toggle. */" \ | ||
| 85 | +"html.embedded .embed-hide,html.embedded #themeToggle{display:none!important}" \ | ||
| 86 | +"@media(prefers-reduced-motion:reduce){*{animation:none!important;transition:none!important}}" | ||
| 87 | + | ||
| 88 | +/* Pre-paint: decide the theme before the first frame. Must be the first thing | ||
| 89 | + * in <head> so there is no flash of the wrong theme. Also flags embed mode as | ||
| 90 | + * html.embedded so the embed rules apply before first paint. */ | ||
| 91 | +#define SX_BOT_THEME_PREPAINT \ | ||
| 92 | +"<script>(function(){var t='';" \ | ||
| 93 | +"try{var m=/[?&]theme=(light|dark)/.exec(location.search);if(m)t=m[1];}catch(e){}" \ | ||
| 94 | +"if(!t){try{var s=localStorage.getItem('bot_theme');if(s==='light'||s==='dark')t=s;}catch(e){}}" \ | ||
| 95 | +"if(!t){try{t=(window.matchMedia&&window.matchMedia('(prefers-color-scheme: light)').matches)?'light':'dark';}catch(e){t='dark';}}" \ | ||
| 96 | +"document.documentElement.setAttribute('data-theme',t);" \ | ||
| 97 | +"try{if(/[?&]embed=(1|true)(&|$)/.test(location.search))document.documentElement.classList.add('embedded');}catch(e){}" \ | ||
| 98 | +"try{localStorage.setItem('bot_theme',t);}catch(e){}" \ | ||
| 99 | +"})();</script>\n" | ||
| 100 | + | ||
| 101 | +/* Handoff: follow the bot. The host posts {type:'sx-theme',theme}; we ask once | ||
| 102 | + * at startup in case it changed while this page was already open. Fires the | ||
| 103 | + * same 'bot-theme' CustomEvent the bot pages use, so canvas surfaces can | ||
| 104 | + * re-skin themselves from one listener. */ | ||
| 105 | +#define SX_BOT_THEME_HANDOFF \ | ||
| 106 | +"<script>(function(){" \ | ||
| 107 | +"function apply(t){if(t!=='light'&&t!=='dark')return;" \ | ||
| 108 | +"if(document.documentElement.getAttribute('data-theme')===t)return;" \ | ||
| 109 | +"document.documentElement.setAttribute('data-theme',t);" \ | ||
| 110 | +"try{localStorage.setItem('bot_theme',t);}catch(e){}" \ | ||
| 111 | +"try{window.dispatchEvent(new CustomEvent('bot-theme',{detail:t}));}catch(e){}}" \ | ||
| 112 | +"window.sxApplyTheme=apply;" \ | ||
| 113 | +"window.sxTheme=function(){var t=document.documentElement.getAttribute('data-theme');return (t==='light'||t==='dark')?t:'dark';};" \ | ||
| 114 | +"window.addEventListener('message',function(e){var d=e&&e.data;if(d&&d.type==='sx-theme')apply(d.theme);});" \ | ||
| 115 | +"try{if(window.parent&&window.parent!==window)window.parent.postMessage({type:'sx-theme-request'},'*');}catch(e){}" \ | ||
| 116 | +"})();</script>\n" | ||
| 117 | + | ||
| 118 | +/* Standalone toggle (hidden in embed mode by the CSS above). Only useful when | ||
| 119 | + * the plugin is opened in its own tab; inside the bot the host owns the theme. | ||
| 120 | + * Give it class 'icon-btn'-free styling from the page, or use the helper JS. */ | ||
| 121 | +#define SX_BOT_THEME_TOGGLE_BTN \ | ||
| 122 | +"<button class='embed-hide' id='themeToggle' type='button' title='Toggle appearance'>Theme</button>" | ||
| 123 | + | ||
| 124 | +#define SX_BOT_THEME_TOGGLE_JS \ | ||
| 125 | +"<script>(function(){var b=document.getElementById('themeToggle');if(!b)return;" \ | ||
| 126 | +"b.onclick=function(){window.sxApplyTheme(window.sxTheme()==='dark'?'light':'dark');};" \ | ||
| 127 | +"})();</script>\n" | ||
| 128 | + | ||
| 129 | +#endif /* SX_BOT_THEME_PLUGIN_H */ |
| index ad955ff..23f26e5 100644 | index ad955ff..23f26e5 100644 | ||
| --- a/src/plugin_hello.c | --- a/src/plugin_hello.c | ||
| +++ b/src/plugin_hello.c | +++ b/src/plugin_hello.c | ||
| @@ -1,5 +1,5 @@ | @@ -1,5 +1,5 @@ | ||
| 1 | /* | 1 | /* |
| 2 | - * plugin_hello — ScorpioX Bot open-source starter plugin | 2 | + * plugin_hello — SCORPIOX BOT open-source starter plugin |
| 3 | * | 3 | * |
| 4 | * A single clean-room C99 binary that serves THREE modes: | 4 | * A single clean-room C99 binary that serves THREE modes: |
| 5 | * 1. --meta / SX_PLUGIN_META=1 -> JSON metadata for discovery | 5 | * 1. --meta / SX_PLUGIN_META=1 -> JSON metadata for discovery |
| @@ -32,9 +32,11 @@ | @@ -32,9 +32,11 @@ | ||
| 32 | # include <sys/utsname.h> | 32 | # include <sys/utsname.h> |
| 33 | #endif | 33 | #endif |
| 34 | 34 | ||
| 35 | +#include "bot_theme_plugin.h" | ||
| 36 | + | ||
| 35 | #define PLUGIN_SLUG "hello" | 37 | #define PLUGIN_SLUG "hello" |
| 36 | #define PLUGIN_ID "plugin_hello" | 38 | #define PLUGIN_ID "plugin_hello" |
| 37 | -#define PLUGIN_VER "1.1.1" | 39 | +#define PLUGIN_VER "1.1.2" |
| 38 | 40 | ||
| 39 | /* ------------------------------------------------------------------ */ | 41 | /* ------------------------------------------------------------------ */ |
| 40 | /* Query string helpers */ | 42 | /* Query string helpers */ |
| @@ -334,19 +336,12 @@ static int mode_html(int embed) | @@ -334,19 +336,12 @@ static int mode_html(int embed) | ||
| 334 | 336 | ||
| 335 | fputs("<!DOCTYPE html>\n<html lang='en'><head><meta charset='utf-8'>" | 337 | fputs("<!DOCTYPE html>\n<html lang='en'><head><meta charset='utf-8'>" |
| 336 | "<meta name='viewport' content='width=device-width,initial-scale=1'>" | 338 | "<meta name='viewport' content='width=device-width,initial-scale=1'>" |
| 337 | - "<title>hello</title><style>", stdout); | 339 | + "<title>hello</title>", stdout); |
| 338 | - | 340 | + /* Theme tokens + prepaint come from src/bot_theme_plugin.h (the bot's own |
| 341 | + * palette), so ?theme= / the bot's postMessage land before first paint. */ | ||
| 342 | + fputs(SX_BOT_THEME_PREPAINT "<style>" SX_BOT_THEME_TOKENS, stdout); | ||
| 339 | fputs( | 343 | fputs( |
| 340 | -":root{color-scheme:dark light;" | 344 | +"body{padding:16px;font-size:14px;line-height:1.5}" |
| 341 | - "--bg:#0d0d10;--surface:#16161a;--surface2:#1e1e24;--text:#f5f5f7;" | ||
| 342 | - "--muted:#8e8e96;--line:rgba(255,255,255,.11);--accent:#0a84ff;" | ||
| 343 | - "--accent2:#30d158;--danger:#ff453a;--mono:ui-monospace,SFMono-Regular,Menlo,monospace}" | ||
| 344 | -"html[data-theme=light]{--bg:#f4f4f7;--surface:#ffffff;--surface2:#f0f0f4;" | ||
| 345 | - "--text:#1c1c1e;--muted:#6b6b73;--line:rgba(0,0,0,.10)}" | ||
| 346 | -"*{box-sizing:border-box}" | ||
| 347 | -"body{margin:0;padding:16px;background:var(--bg);color:var(--text);" | ||
| 348 | - "font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;" | ||
| 349 | - "font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased}" | ||
| 350 | ".wrap{max-width:880px;margin:0 auto}" | 345 | ".wrap{max-width:880px;margin:0 auto}" |
| 351 | ".top{display:flex;align-items:center;gap:10px;margin-bottom:16px;flex-wrap:wrap}" | 346 | ".top{display:flex;align-items:center;gap:10px;margin-bottom:16px;flex-wrap:wrap}" |
| 352 | ".title{font-size:20px;font-weight:700;margin:0}" | 347 | ".title{font-size:20px;font-weight:700;margin:0}" |
| @@ -388,7 +383,7 @@ static int mode_html(int embed) | @@ -388,7 +383,7 @@ static int mode_html(int embed) | ||
| 388 | "<span class='pill'>" PLUGIN_VER "</span>" | 383 | "<span class='pill'>" PLUGIN_VER "</span>" |
| 389 | "<span class='pill' id='badge'>connecting</span>" | 384 | "<span class='pill' id='badge'>connecting</span>" |
| 390 | "<span class='spacer'></span>" | 385 | "<span class='spacer'></span>" |
| 391 | - "<button class='ghost' id='themeBtn' type='button'>Theme</button>" | 386 | + "<button class='ghost embed-hide' id='themeBtn' type='button'>Theme</button>" |
| 392 | "<button class='ghost' id='reloadBtn' type='button'>Refresh</button></div>", stdout); | 387 | "<button class='ghost' id='reloadBtn' type='button'>Refresh</button></div>", stdout); |
| 393 | 388 | ||
| 394 | /* ---- live node card ---- */ | 389 | /* ---- live node card ---- */ |
| @@ -474,23 +469,13 @@ static int mode_html(int embed) | @@ -474,23 +469,13 @@ static int mode_html(int embed) | ||
| 474 | " });\n" | 469 | " });\n" |
| 475 | " }\n" | 470 | " }\n" |
| 476 | "\n" | 471 | "\n" |
| 477 | -" function applyTheme(t){\n" | ||
| 478 | -" document.documentElement.setAttribute('data-theme', t === 'light' ? 'light' : 'dark');\n" | ||
| 479 | -" }\n" | ||
| 480 | -" var saved = localStorage.getItem('bot_theme');\n" | ||
| 481 | -" applyTheme(saved || (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'));\n" | ||
| 482 | -" $('themeBtn').addEventListener('click', function(){\n" | ||
| 483 | -" var cur = document.documentElement.getAttribute('data-theme');\n" | ||
| 484 | -" var next = cur === 'light' ? 'dark' : 'light';\n" | ||
| 485 | -" applyTheme(next);\n" | ||
| 486 | -" localStorage.setItem('bot_theme', next);\n" | ||
| 487 | -" });\n" | ||
| 488 | " $('reloadBtn').addEventListener('click', refresh);\n" | 472 | " $('reloadBtn').addEventListener('click', refresh);\n" |
| 489 | " $('echoBtn').addEventListener('click', sendEcho);\n" | 473 | " $('echoBtn').addEventListener('click', sendEcho);\n" |
| 490 | " $('msg').addEventListener('keydown', function(e){ if (e.key === 'Enter') sendEcho(); });\n" | 474 | " $('msg').addEventListener('keydown', function(e){ if (e.key === 'Enter') sendEcho(); });\n" |
| 491 | " refresh();\n" | 475 | " refresh();\n" |
| 492 | "})();\n" | 476 | "})();\n" |
| 493 | -"</script></body></html>\n", stdout); | 477 | +SX_BOT_THEME_HANDOFF |
| 478 | +"</body></html>\n", stdout); | ||
| 494 | 479 | ||
| 495 | return 0; | 480 | return 0; |
| 496 | } | 481 | } |
| index 8039ffa..92b10dd 100755 | index 8039ffa..92b10dd 100755 | ||
| --- a/tests/run.sh | --- a/tests/run.sh | ||
| +++ b/tests/run.sh | +++ b/tests/run.sh | ||
| @@ -62,7 +62,7 @@ DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/') | @@ -62,7 +62,7 @@ DESC=$("$BIN" --meta | sed 's/.*"desc":"\([^"]*\)".*/\1/') | ||
| 62 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" | 62 | [ ${#DESC} -le 15 ] && pass "desc length ${#DESC} <= 15 chars" || fail "desc too long (${#DESC})" |
| 63 | NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/') | 63 | NAME=$("$BIN" --meta | sed 's/.*"name":"\([^"]*\)".*/\1/') |
| 64 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" | 64 | [ "$(printf '%s' "$NAME" | wc -w | tr -d ' ')" -le 1 ] && pass "name is a single word" || fail "name has spaces" |
| 65 | -check "--version prints version" '1.1.1' "$("$BIN" --version)" | 65 | +check "--version prints version" '1.1.2' "$("$BIN" --version)" |
| 66 | 66 | ||
| 67 | # ---------------------------------------------------------------- json mode | 67 | # ---------------------------------------------------------------- json mode |
| 68 | section "node auth" | 68 | section "node auth" |
| @@ -93,7 +93,7 @@ BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d') | @@ -93,7 +93,7 @@ BODY=$(printf '%s' "$INFO" | sed '1,/^\r$/d') | ||
| 93 | check "info ok:true" '"ok":true' "$BODY" | 93 | check "info ok:true" '"ok":true' "$BODY" |
| 94 | check "info plugin id" '"plugin":"plugin_hello"' "$BODY" | 94 | check "info plugin id" '"plugin":"plugin_hello"' "$BODY" |
| 95 | check "info slug" '"slug":"hello"' "$BODY" | 95 | check "info slug" '"slug":"hello"' "$BODY" |
| 96 | -check "info version" '"version":"1.1.1"' "$BODY" | 96 | +check "info version" '"version":"1.1.2"' "$BODY" |
| 97 | check "info hostname field" '"hostname"' "$BODY" | 97 | check "info hostname field" '"hostname"' "$BODY" |
| 98 | check "info os field" '"os"' "$BODY" | 98 | check "info os field" '"os"' "$BODY" |
| 99 | check "info arch field" '"arch"' "$BODY" | 99 | check "info arch field" '"arch"' "$BODY" |
| @@ -134,7 +134,6 @@ HBODY=$(printf '%s' "$HTML" | sed '1,/^\r$/d') | @@ -134,7 +134,6 @@ HBODY=$(printf '%s' "$HTML" | sed '1,/^\r$/d') | ||
| 134 | check "html doctype" '<!DOCTYPE html>' "$HBODY" | 134 | check "html doctype" '<!DOCTYPE html>' "$HBODY" |
| 135 | check "html title hello" '<title>hello</title>' "$HBODY" | 135 | check "html title hello" '<title>hello</title>' "$HBODY" |
| 136 | check "html theme toggle button" 'themeBtn' "$HBODY" | 136 | check "html theme toggle button" 'themeBtn' "$HBODY" |
| 137 | -check "html reads bot_theme" 'bot_theme' "$HBODY" | ||
| 138 | check "html echo button wired" "echoBtn" "$HBODY" | 137 | check "html echo button wired" "echoBtn" "$HBODY" |
| 139 | check "html node info card" 'Live node info' "$HBODY" | 138 | check "html node info card" 'Live node info' "$HBODY" |
| 140 | check "html echo tester" 'Echo action tester' "$HBODY" | 139 | check "html echo tester" 'Echo action tester' "$HBODY" |
| @@ -146,8 +145,24 @@ check "html hub-aware api base" "'/plugins?plugin='" "$HBODY" | @@ -146,8 +145,24 @@ check "html hub-aware api base" "'/plugins?plugin='" "$HBODY" | ||
| 146 | check "html direct api base" "'/plugin_hello?action='" "$HBODY" | 145 | check "html direct api base" "'/plugin_hello?action='" "$HBODY" |
| 147 | check "html send X-Bot-Password" 'X-Bot-Password' "$HBODY" | 146 | check "html send X-Bot-Password" 'X-Bot-Password' "$HBODY" |
| 148 | check "html responsive viewport" 'width=device-width' "$HBODY" | 147 | check "html responsive viewport" 'width=device-width' "$HBODY" |
| 149 | -check "html light theme block" 'data-theme=light' "$HBODY" | 148 | +check "html light theme block" 'html[data-theme=light]' "$HBODY" |
| 150 | -check_not "html no internal LAN IP" '192.168.' "$HBODY" | 149 | +check "html reads ?theme=" 'theme=(light|dark)' "$HBODY" |
| 150 | +check "html reads bot_theme" 'bot_theme' "$HBODY" | ||
| 151 | +check "html honours prefers-color" 'prefers-color-scheme' "$HBODY" | ||
| 152 | +check "html follows sx-theme posts" "d.type==='sx-theme'" "$HBODY" | ||
| 153 | +check "html asks host for theme" "sx-theme-request" "$HBODY" | ||
| 154 | +check "html uses bot token --bg-card" '--bg-card' "$HBODY" | ||
| 155 | +check "html uses bot token --surface-2" '--surface-2' "$HBODY" | ||
| 156 | +check "html uses bot token --text-2" '--text-2' "$HBODY" | ||
| 157 | +check "html uses bot accent --teal" '--teal' "$HBODY" | ||
| 158 | +check_not "html no private #0d0d10 palette" '#0d0d10' "$HBODY" | ||
| 159 | +check_not "html no private #f4f4f7 palette" '#f4f4f7' "$HBODY" | ||
| 160 | +check_not "html no retired brand casing" 'Scorpio'"X Bot" "$HBODY" | ||
| 161 | +check "html hides toggle when embedded" 'embed-hide' "$HBODY" | ||
| 162 | + | ||
| 163 | +THEMELIGHT=$(QUERY_STRING='theme=light' "$BIN" | sed '1,/^\r$/d') | ||
| 164 | +THEMELIGHT=$(QUERY_STRING='theme=light' "$BIN" | sed '1,/^\r$/d') | ||
| 165 | +check "?theme=light still emits the ?theme= reader" 'theme=(light|dark)' "$THEMELIGHT" | ||
| 151 | check_not "html no localhost literal" '127.0.0.1' "$HBODY" | 166 | check_not "html no localhost literal" '127.0.0.1' "$HBODY" |
| 152 | 167 | ||
| 153 | EMBED=$(QUERY_STRING='embed=1' "$BIN" | sed '1,/^\r$/d') | 168 | EMBED=$(QUERY_STRING='embed=1' "$BIN" | sed '1,/^\r$/d') |
| 154 | 169 |