fix(app): the wizard resumes until finished, late answers stay off other screens, logs follow the chosen folder

- app_status reports firstRun until wizard_finish; wizard_step saves the
  step reached in config/setup.json, and the wizard resumes there (a stored
  token lets the bot step go on).
- show() and refresh() drop answers that arrive after the screen changed.
- folder_choose points the log hub at the folder's logs/ at once.
- Choosing another server clears the voice channel picker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-12 14:25:59 +09:00
parent 20300c017e
commit b68eef3ec1
4 changed files with 126 additions and 27 deletions

View File

@@ -193,15 +193,21 @@ async function fillPickers(root, view) {
...list.map((x) => h("option", { value: x.id, selected: x.id === current }, x.name)));
if (current && !list.some((x) => x.id === current)) sel.append(h("option", { value: current, selected: true }, current));
};
const loadVoice = async () => {
// `current`: the saved voice channel, kept only while its own server is shown. Another server
// starts with none chosen, so a channel of the previous server is never saved with it.
const loadVoice = async (current) => {
if (!v) return;
if (!g.value) return opts(v, [], null, "자동으로 들어가지 않음");
try { opts(v, (await api("discord_channels", { guildId: g.value })).voice, view["discord.voiceChannelId"], "자동으로 들어가지 않음"); }
catch (e) { /* the ID stays as it was */ }
opts(v, [], current, "자동으로 들어가지 않음");
if (!g.value) return;
const guild = g.value;
try {
const voice = (await api("discord_channels", { guildId: guild })).voice;
if (g.value === guild) opts(v, voice, current, "자동으로 들어가지 않음");
} catch (e) { /* the saved ID stays as it was */ }
};
try { opts(g, await api("discord_guilds"), view["discord.guildId"], "선택 안 함"); } catch (e) { return; }
g.addEventListener("change", loadVoice);
loadVoice();
g.addEventListener("change", () => loadVoice(null));
loadVoice(view["discord.voiceChannelId"]);
}
async function tokenCard() {
@@ -333,10 +339,14 @@ function logsScreen() {
let current = null, ticker = null;
let headerKey = null;
// Each show() starts a new generation: an answer that arrives after the user moved on is dropped.
let gen = 0;
async function refresh() {
if (current !== "dashboard") return;
const my = gen;
try {
const d = await api("dashboard");
if (my !== gen || current !== "dashboard") return;
const screen = $("#screen");
let head = $("#dash-head"), body = $("#dash-body");
if (!head || !body) {
@@ -350,6 +360,7 @@ async function refresh() {
} catch (e) { fail(e); }
}
async function show(name) {
const my = ++gen;
current = name;
clearInterval(ticker);
for (const b of document.querySelectorAll(".nav")) b.classList.toggle("on", b.dataset.screen === name);
@@ -359,7 +370,8 @@ async function show(name) {
if (name === "logs") { const l = logsScreen(); screen.replaceChildren(l.view); ticker = setInterval(l.tick, 1000); return; }
const titles = { bot: "봇", channels: "채널·호출", chat: "채팅 채널", memory: "대화 기억", model: "모델" };
const extra = name === "bot" ? await tokenCard() : null;
screen.replaceChildren(await settingsScreen(name, titles[name], extra));
const view = await settingsScreen(name, titles[name], extra);
if (my === gen) screen.replaceChildren(view);
} catch (e) { fail(e); }
}
@@ -368,17 +380,24 @@ async function show(name) {
const WIZ = ["데이터 폴더", "PC 점검", "모델", "디스코드 봇", "서버·채널", "호출어", "완료"];
async function wizard(status) {
const root = $("#wizard");
let step = status.dataDir ? 3 : 0;
// Resume where it was left: the step saved in the data folder (setup.json), not just "token stored".
let step = status.dataDir ? Math.max(1, Math.min(status.wizardStep || 1, WIZ.length - 1)) : 0;
let wgen = 0;
const s = {};
const nav = (back, next, nextLabel = "다음") => h("div", { class: "nav-row" },
back ? h("button", { class: "btn", onclick: () => go(step - 1) }, "이전") : h("span"),
next ? h("button", { class: "btn primary", onclick: next }, nextLabel) : h("span"));
async function go(n) {
step = n;
const my = ++wgen;
if (n >= 1) api("wizard_step", { step: n }).catch(() => {});
const card = h("div", { class: "card" });
root.replaceChildren(h("h1", {}, "Jarvis 처음 설정"),
h("div", { class: "steps" }, WIZ.map((t, i) => h("span", { class: "step" + (i === step ? " on" : i < step ? " done" : "") }, t))), card);
try { card.append(...(await STEPS[step](card)).filter((x) => x != null)); } catch (e) { fail(e); }
try {
const kids = await STEPS[n](card);
if (my === wgen) card.append(...kids.filter((x) => x != null));
} catch (e) { fail(e); }
}
const STEPS = [
async () => {
@@ -416,7 +435,9 @@ async function wizard(status) {
async () => {
const input = h("input", { type: "password", placeholder: "디스코드 봇 토큰", autocomplete: "off" });
const out = h("div");
const stored = await api("token_status");
return [h("h2", {}, "디스코드 봇 연결"),
stored.set ? h("p", { class: "small" }, `저장된 토큰 ${stored.masked}가 있습니다. 바꾸려면 새 토큰을 확인하세요.`) : null,
h("p", {}, "Discord Developer Portal의 Bot 탭에서 토큰을 복사해 붙여 넣으세요. 토큰은 이 PC의 Windows 계정으로 암호화해 저장합니다."),
h("div", { class: "row" }, input, h("button", { class: "btn", onclick: async () => {
try {
@@ -430,7 +451,7 @@ async function wizard(status) {
} catch (e) { fail(e); }
} }, "연결 확인")), out,
nav(true, async () => {
if (!s.check) return toast("먼저 연결을 확인해 주세요", true);
if (!s.check) return stored.set ? go(4) : toast("먼저 연결을 확인해 주세요", true);
try { await api("token_save", { token: s.token }); go(4); } catch (e) { fail(e); }
})];
},
@@ -470,6 +491,7 @@ async function wizard(status) {
async () => [h("h2", {}, "준비됐습니다"),
h("p", {}, "시작하면 봇이 디스코드에 연결되고, 처음 시작할 때 서버에 슬래시 명령을 등록합니다."),
nav(true, async () => {
try { await api("wizard_finish"); } catch (e) { return fail(e); }
root.hidden = true;
await start();
try { await api("service_start"); } catch (e) { fail(e); }