Skip to content

Local AI BGM and sound effects for Claude Code and any MCP client. Stable Audio 3 on Apple Silicon (MLX) and Windows NVIDIA GPUs (PyTorch). No cloud, no API key.

Web UI: theme switch with light / follow the system / dark icons (GAME-224)

Kanad3db4ba802f6
diff --git a/src/audio_studio_mcp/static/app.css b/src/audio_studio_mcp/static/app.css
index 4ee90c0..86784a9 100644
--- a/src/audio_studio_mcp/static/app.css
+++ b/src/audio_studio_mcp/static/app.css
@@ -104,14 +104,15 @@ select {
:root:not([data-theme="light"]) select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23a4acb5' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
}
.select-sm { width: auto; padding: 5px 30px 5px 10px; font-size: 12.5px; background-position: right 9px center; }
-.icon-btn {
- appearance: none; width: 32px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
- border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text); cursor: pointer; padding: 0;
+.theme-switch { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); }
+.theme-switch button {
+ appearance: none; width: 28px; height: 26px; display: inline-flex; align-items: center; justify-content: center;
+ border: 0; border-radius: 6px; background: none; color: var(--muted); cursor: pointer; padding: 0;
}
-.icon-btn:hover { background: var(--surface-2); }
-.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
-.icon-btn .icon-moon { fill: currentColor; stroke: none; }
-#theme[aria-pressed="true"] .icon-sun, #theme[aria-pressed="false"] .icon-moon { display: none; }
+.theme-switch button:hover { color: var(--text); background: var(--surface-2); }
+.theme-switch button[aria-checked="true"] { color: var(--accent); background: var(--accent-soft); }
+.theme-switch svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
+.theme-switch svg .fill { fill: currentColor; stroke: none; }
.btn {
appearance: none; font: inherit; font-weight: 550; border-radius: 6px; padding: 7px 14px; cursor: pointer;
border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
diff --git a/src/audio_studio_mcp/static/app.js b/src/audio_studio_mcp/static/app.js
index 4ded559..949b9e8 100644
--- a/src/audio_studio_mcp/static/app.js
+++ b/src/audio_studio_mcp/static/app.js
@@ -157,17 +157,22 @@ document.addEventListener("keydown", (e) => {
// ── theme / language settings ────────────────────────────────────────────────
function initSettings() {
- // Sun / moon toggle. Only a choice that differs from the system is saved, so
- // switching back to the system's look means "follow the system" again.
- const systemDark = matchMedia("(prefers-color-scheme: dark)");
- $("#theme").addEventListener("click", () => {
- const next = isDark() ? "light" : "dark";
- if ((next === "dark") === systemDark.matches) { delete document.documentElement.dataset.theme; localStorage.removeItem("as.theme"); }
- else { document.documentElement.dataset.theme = next; localStorage.setItem("as.theme", next); }
+ // Light / follow the system / dark. "system" is the default and is not saved.
+ const buttons = [...$("#theme").querySelectorAll("[role=radio]")];
+ const setMode = (mode) => {
+ if (mode === "system") { delete document.documentElement.dataset.theme; localStorage.removeItem("as.theme"); }
+ else { document.documentElement.dataset.theme = mode; localStorage.setItem("as.theme", mode); }
renderThemeButton();
window.dispatchEvent(new Event("as:theme"));
+ };
+ buttons.forEach((btn, i) => {
+ btn.addEventListener("click", () => setMode(btn.dataset.mode));
+ btn.addEventListener("keydown", (e) => { // radio group: arrows move and select
+ if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return;
+ const next = buttons[(i + (e.key === "ArrowRight" ? 1 : buttons.length - 1)) % buttons.length];
+ next.focus(); setMode(next.dataset.mode); e.preventDefault();
+ });
});
- systemDark.addEventListener("change", renderThemeButton);
const lang = localStorage.getItem("as.lang") || "auto";
$("#lang").value = lang;
state.lang = pickLang(lang);
@@ -179,15 +184,13 @@ function initSettings() {
});
}
-function isDark() {
- const forced = document.documentElement.dataset.theme;
- return forced ? forced === "dark" : matchMedia("(prefers-color-scheme: dark)").matches;
-}
function renderThemeButton() {
- const b = $("#theme"), dark = isDark(), label = t(dark ? "settings.toLight" : "settings.toDark");
- b.setAttribute("aria-pressed", String(dark));
- b.setAttribute("aria-label", label);
- b.title = label;
+ const mode = document.documentElement.dataset.theme || "system";
+ for (const btn of $("#theme").querySelectorAll("[role=radio]")) {
+ const on = btn.dataset.mode === mode;
+ btn.setAttribute("aria-checked", String(on));
+ btn.tabIndex = on ? 0 : -1;
+ }
}
// ── pages ────────────────────────────────────────────────────────────────────
diff --git a/src/audio_studio_mcp/static/i18n.js b/src/audio_studio_mcp/static/i18n.js
index 832191d..4493a5c 100644
--- a/src/audio_studio_mcp/static/i18n.js
+++ b/src/audio_studio_mcp/static/i18n.js
@@ -1,7 +1,7 @@
// UI strings: English, Japanese, Simplified Chinese. {name} = placeholder.
window.I18N = {
en: {
- "settings.toDark": "Switch to dark mode", "settings.toLight": "Switch to light mode",
+ "settings.theme": "Theme", "settings.light": "Light", "settings.system": "Follow the system", "settings.dark": "Dark",
"nav.generate": "Generate", "nav.edit": "Edit", "nav.library": "Library",
"status.unload": "Unload model", "status.unloadHint": "Frees the 5–7 GB the model uses. It loads again on the next generation.",
"status.loaded": "Model ready", "status.notLoaded": "Model loads on first use", "status.working": "Working",
@@ -146,7 +146,7 @@ window.I18N = {
"sum.fadeShort": "fade {a}/{b} ms (shortened to fit)",
},
ja: {
- "settings.toDark": "ダークモードに切り替え", "settings.toLight": "ライトモードに切り替え",
+ "settings.theme": "テーマ", "settings.light": "ライト", "settings.system": "システムに合わせる", "settings.dark": "ダーク",
"nav.generate": "生成", "nav.edit": "編集", "nav.library": "ライブラリ",
"status.unload": "モデルを解放", "status.unloadHint": "モデルが使っている 5〜7 GB のメモリを解放します。次の生成でまた読み込みます。",
"status.loaded": "モデル準備完了", "status.notLoaded": "初回の生成時にモデルを読み込みます", "status.working": "処理中",
@@ -291,7 +291,7 @@ window.I18N = {
"sum.fadeShort": "フェード {a}/{b} ms(長さに合わせて短縮)",
},
zh: {
- "settings.toDark": "切换到深色模式", "settings.toLight": "切换到浅色模式",
+ "settings.theme": "主题", "settings.light": "浅色", "settings.system": "跟随系统", "settings.dark": "深色",
"nav.generate": "生成", "nav.edit": "编辑", "nav.library": "作品库",
"status.unload": "卸载模型", "status.unloadHint": "释放模型占用的 5–7 GB 内存,下次生成时会重新加载。",
"status.loaded": "模型已就绪", "status.notLoaded": "首次生成时加载模型", "status.working": "处理中",
diff --git a/src/audio_studio_mcp/static/index.html b/src/audio_studio_mcp/static/index.html
index cae93f9..93e0800 100644
--- a/src/audio_studio_mcp/static/index.html
+++ b/src/audio_studio_mcp/static/index.html
@@ -36,11 +36,18 @@
<option value="en">English</option>
<option value="zh">简体中文</option>
</select>
- <!-- sun / moon toggle: follows the system until clicked -->
- <button type="button" class="icon-btn" id="theme" aria-pressed="false">
- <svg class="icon-sun" viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4.2"/><path d="M12 2.5v2.2M12 19.3v2.2M2.5 12h2.2M19.3 12h2.2M5.3 5.3l1.6 1.6M17.1 17.1l1.6 1.6M5.3 18.7l1.6-1.6M17.1 6.9l1.6-1.6"/></svg>
- <svg class="icon-moon" viewBox="0 0 24 24" aria-hidden="true"><path d="M20.2 14.6A8.3 8.3 0 0 1 9.4 3.8a8.3 8.3 0 1 0 10.8 10.8z"/></svg>
- </button>
+ <!-- theme: light / follow the system / dark -->
+ <div class="theme-switch" id="theme" role="radiogroup" data-i18n-aria-label="settings.theme">
+ <button type="button" role="radio" data-mode="light" aria-checked="false" data-i18n-aria-label="settings.light" data-i18n-title="settings.light">
+ <svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="4.2"/><path d="M12 2.5v2.2M12 19.3v2.2M2.5 12h2.2M19.3 12h2.2M5.3 5.3l1.6 1.6M17.1 17.1l1.6 1.6M5.3 18.7l1.6-1.6M17.1 6.9l1.6-1.6"/></svg>
+ </button>
+ <button type="button" role="radio" data-mode="system" aria-checked="true" data-i18n-aria-label="settings.system" data-i18n-title="settings.system">
+ <svg viewBox="0 0 24 24" aria-hidden="true"><rect x="3" y="4.5" width="18" height="12" rx="2"/><path d="M9 20h6M12 16.5V20"/></svg>
+ </button>
+ <button type="button" role="radio" data-mode="dark" aria-checked="false" data-i18n-aria-label="settings.dark" data-i18n-title="settings.dark">
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path class="fill" d="M20.2 14.6A8.3 8.3 0 0 1 9.4 3.8a8.3 8.3 0 1 0 10.8 10.8z"/></svg>
+ </button>
+ </div>
</div>
</header>
diff --git a/tests/test_webui_browser.py b/tests/test_webui_browser.py
index 75d1acf..e96a22d 100644
--- a/tests/test_webui_browser.py
+++ b/tests/test_webui_browser.py
@@ -424,20 +424,23 @@ def test_languages_and_themes(web, browser, shots, lang, theme):
def test_manual_theme_and_language_switch(web, browser):
errors: list[str] = []
page = _page(browser, web, "en", "light", errors)
- assert page.get_attribute("#theme", "aria-label") == "Switch to dark mode"
- page.click("#theme") # sun → moon
+ # three icons: light / follow the system (default) / dark
+ assert page.get_attribute("#theme [data-mode=system]", "aria-checked") == "true"
+ assert page.get_attribute("#theme [data-mode=system]", "aria-label") == "Follow the system"
+ page.click("#theme [data-mode=dark]")
assert page.evaluate("document.documentElement.dataset.theme") == "dark"
- assert page.get_attribute("#theme", "aria-pressed") == "true"
- assert page.is_visible("#theme .icon-moon") and not page.is_visible("#theme .icon-sun")
+ assert page.get_attribute("#theme [data-mode=dark]", "aria-checked") == "true"
+ assert page.get_attribute("#theme [data-mode=system]", "aria-checked") == "false"
bg = page.evaluate("getComputedStyle(document.body).backgroundColor")
page.select_option("#lang", "ja")
assert page.text_content("#tab-library") == "ライブラリ"
- assert page.get_attribute("#theme", "aria-label") == "ライトモードに切り替え"
+ assert page.get_attribute("#theme [data-mode=system]", "title") == "システムに合わせる"
page.reload() # both choices persist
assert page.evaluate("document.documentElement.dataset.theme") == "dark"
assert page.evaluate("getComputedStyle(document.body).backgroundColor") == bg
assert page.text_content("#tab-library") == "ライブラリ"
- page.click("#theme") # back to the system's look = follow the system again
+ page.focus("#theme [data-mode=dark]")
+ page.keyboard.press("ArrowLeft") # arrow keys move within the group: dark → system
page.select_option("#lang", "auto")
assert page.evaluate("document.documentElement.dataset.theme") is None
assert page.evaluate("localStorage.getItem('as.theme')") is None