Skip to content

🤖 Open-source, local-first alternative to Grok Bot, OpenAI dots and Claude Duet. Your own AI bots on any model: GPT, Claude, Gemini, Grok, DeepSeek, Kimi, GLM and 70+ more through one Modelflare key. Reach them in the app, WeChat or Feishu; they remember you, work in the background, run commands and use your computer. Pay per use.

feat(ui): PowerShell 7 install progress, result and one-click recovery

Marla131a7d890f70
diff --git a/ui/components/pwsh-hint.js b/ui/components/pwsh-hint.js
index 9078f3b..005f097 100644
--- a/ui/components/pwsh-hint.js
+++ b/ui/components/pwsh-hint.js
@@ -1,33 +1,74 @@
-// "建议安装 PowerShell 7":一条安静的 .notice(淡底 + 图标 + 字,不描边),多一行等宽的安装命令和一排操作。
-// 放在对话空状态和设置 → 常规的顶部;只在 Windows 上、没有 PowerShell 7、没点过"不再提示"时出现。
+// 代理的 PowerShell:一条安静的 .notice(淡底 + 图标 + 字,不描边),放在对话空状态和设置 → 常规的顶部,只在 Windows 上出现。
+// 正在为代理安装 PowerShell 7(带进度)→ 装好了 / 没装上;用的 PowerShell 起不来、已自动换掉;这台电脑装不了;没有 PowerShell 7。
import { useState } from "preact/hooks";
-import { html, Icon, CopyButton } from "./ui.js";
-import { PWSH_INSTALL_URL, PWSH_WINGET, dismissPwsh, recheckPwsh, showPwshHint, usePwsh } from "../lib/pwsh.js";
+import { html, Icon, CopyButton, Spinner } from "./ui.js";
+import { PWSH_INSTALL_URL, PWSH_WINGET, ackPwsh, dismissPwsh, installPwsh, pwshHint, pwshProgress, recheckPwsh, usePwsh } from "../lib/pwsh.js";
import { failed } from "../lib/store.js";
+const SLOW = "机器人执行命令现在用的是系统自带的 Windows PowerShell 5.1,每条可能要等二三十秒";
+
export function PwshHint() {
const s = usePwsh();
- const [busy, setBusy] = useState(false);
- if (!showPwshHint(s)) return null;
- const recheck = async () => {
- setBusy(true);
+ const [busy, setBusy] = useState("");
+ const kind = pwshHint(s);
+ if (!kind) return null;
+ const run = (what, fn) => async () => {
+ setBusy(what);
try {
- await recheckPwsh();
+ await fn();
} catch (e) {
failed(e);
} finally {
- setBusy(false);
+ setBusy("");
}
};
+ const p = s.private || {};
+ const inst = p.install || {};
+ const btn = (what, label, fn, cls = "text", busyLabel = `${label}…`) =>
+ html`<button type="button" class=${cls} disabled=${!!busy} aria-busy=${busy === what || undefined} onClick=${run(what, fn)}>${busy === what ? busyLabel : label}</button>`;
+ const dismiss = btn("dismiss", "不再提示", dismissPwsh);
+ const box = (icon, title, body, actions, tone = "") => html`<div class=${`notice pwsh-hint${tone ? ` ${tone}` : ""}`} role=${kind === "installing" ? "status" : "note"} aria-label=${title}>
+ ${icon === "spinner" ? html`<${Spinner} />` : html`<${Icon} name=${icon} size=${14} />`}
+ <div class="pwsh-body">
+ <p><b>${title}</b>${body}</p>
+ ${actions && html`<div class="pwsh-actions">${actions}</div>`}
+ </div>
+ </div>`;
+
+ if (kind === "installing")
+ return box("spinner", "正在为代理安装 PowerShell 7…", `${pwshProgress(inst)}。装好后机器人执行命令快得多(大约 1 秒一条);不需要管理员权限,也不影响你自己的 PowerShell。装好之前命令照常用 Windows PowerShell 5.1。`);
+ if (kind === "installed")
+ return box("check", "PowerShell 7 已就绪", `机器人之后执行命令用应用内置的 PowerShell ${s.version || p.version}(已核对微软签名并试运行通过),大约 1 秒一条。`, html`<button type="button" class="text" onClick=${() => ackPwsh(`ok:${inst.finishedAt}`)}>知道了</button>`);
+ if (kind === "fallback")
+ return box(
+ "alert",
+ "PowerShell 出了问题,已自动换掉",
+ `${s.fallback.from} 起不来(${s.fallback.reason})。机器人改用 ${s.source === "private" ? "应用内置的" : ""}PowerShell ${s.version || "7"} 执行命令。`,
+ html`<button type="button" class="text" onClick=${() => ackPwsh(`fb:${s.fallback.at}`)}>知道了</button>`,
+ "amber",
+ );
+ if (kind === "broken")
+ return box("alert", "应用内置的 PowerShell 7 用不了", `${p.bad.reason}。${SLOW}。重新安装一般就能恢复。`, html`${btn("install", "重新安装", () => installPwsh(true), "btn")}${dismiss}`, "amber");
+ if (kind === "failed")
+ return box(
+ "alert",
+ "PowerShell 7 没装上",
+ `${inst.error || "未知原因"}。${SLOW}。`,
+ html`${btn("install", "重试", () => installPwsh(false), "btn")}<a class="text" href=${PWSH_INSTALL_URL} target="_blank" rel="noopener noreferrer">自己安装 ↗</a>${dismiss}`,
+ "amber",
+ );
+ if (kind === "unsupported") return box("info", "这台电脑装不了 PowerShell 7", `${p.reason}。${SLOW}。`, dismiss);
+ // missing:改回了系统默认、关了自动安装,或者还没开始装
return html`<div class="notice pwsh-hint" role="note" aria-label="建议安装 PowerShell 7">
<${Icon} name="info" size=${14} />
<div class="pwsh-body">
- <p><b>建议安装 PowerShell 7</b>机器人执行命令现在用的是系统自带的 Windows PowerShell 5.1,每条可能要等二三十秒。装上 PowerShell 7,命令执行快得多,也更稳定。</p>
+ <p><b>建议安装 PowerShell 7</b>${SLOW}。装上 PowerShell 7,命令执行快得多,也更稳定。${p.supported ? "应用可以自己装一份,不需要管理员权限,也不影响你自己的 PowerShell。" : ""}</p>
<div class="pwsh-cmd"><span class="t-meta">或在终端运行</span><code>${PWSH_WINGET}</code><${CopyButton} text=${PWSH_WINGET} label="复制安装命令" /></div>
<div class="pwsh-actions">
- <a class="btn" href=${PWSH_INSTALL_URL} target="_blank" rel="noopener noreferrer">安装 PowerShell 7 ↗</a>
- <button type="button" class="text" disabled=${busy} aria-busy=${busy || undefined} onClick=${recheck}>${busy ? "检测中…" : "重新检测"}</button>
- <button type="button" class="text" onClick=${() => dismissPwsh().catch(failed)}>不再提示</button>
+ ${p.supported ? btn("install", "一键安装", () => installPwsh(false), "btn") : html`<a class="btn" href=${PWSH_INSTALL_URL} target="_blank" rel="noopener noreferrer">安装 PowerShell 7 ↗</a>`}
+ ${p.supported && html`<a class="text" href=${PWSH_INSTALL_URL} target="_blank" rel="noopener noreferrer">自己安装 ↗</a>`}
+ ${btn("recheck", "重新检测", recheckPwsh, "text", "检测中…")}
+ ${dismiss}
</div>
</div>
</div>`;
diff --git a/ui/css/shell.css b/ui/css/shell.css
index 2663aed..e21b062 100644
--- a/ui/css/shell.css
+++ b/ui/css/shell.css
@@ -219,10 +219,11 @@ button.thread:active { background: var(--side-press); }
:root { --side-w: 240px; }
}
-/* "建议安装 PowerShell 7"(components/pwsh-hint.js):一条 .notice(淡底 + 图标 + 字,不描边),文字之下多一行等宽的
- 安装命令(就是一行字,不再套底)和一排操作。对话空状态与设置 → 常规共用 */
+/* 代理的 PowerShell(components/pwsh-hint.js):一条 .notice(淡底 + 图标 + 字,不描边)——正在安装(转圈 + 进度)、装好了、
+ 没装上、起不来已换掉、建议安装;文字之下可以多一行等宽的安装命令(就是一行字,不再套底)和一排操作。对话空状态与设置 → 常规共用 */
.notice.pwsh-hint { align-items: flex-start; padding: var(--space-3); text-align: left; }
-.notice.pwsh-hint > .ic { margin-top: 3px; } /* 微调:图标对齐第一行文字(14px 图标 / 约 20px 行高) */
+.notice.pwsh-hint > .ic, .notice.pwsh-hint > .spinner { margin-top: 3px; } /* 微调:图标对齐第一行文字(14px 图标 / 约 20px 行高) */
+.notice.pwsh-hint > .spinner { color: var(--notice-ic); }
.pwsh-body { flex: 1; min-width: 0; display: grid; gap: var(--space-2); }
.pwsh-body b { display: block; margin-bottom: var(--space-0-5); font-weight: var(--fw-semibold); }
.pwsh-cmd { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
diff --git a/ui/lib/pwsh.js b/ui/lib/pwsh.js
index aba22bf..041ff15 100644
--- a/ui/lib/pwsh.js
+++ b/ui/lib/pwsh.js
@@ -1,5 +1,5 @@
-// Windows:没有 PowerShell 7 时建议安装。检测结果放在一个全局 store 里,对话空状态、设置 → 常规、故障排查共用,
-// "重新检测""不再提示"立即同步到每一处。检测在后端(只看文件、不拉起进程),这里只读接口。
+// Windows:代理用哪个 PowerShell(系统里的 7 → 应用内置的 7 → 5.1)。状态放在一个全局 store 里,对话空状态、设置 → 常规、
+// 故障排查共用,按钮的结果立即同步到每一处。安装在后台进行:装的时候每 1.5 秒刷新进度,平时每分钟看一次(自动安装、自动退回都在后台发生)。
import { useEffect } from "preact/hooks";
import { api } from "./api.js";
import { createStore, toast, useStore } from "./store.js";
@@ -9,35 +9,124 @@ export const PWSH_WINGET = "winget install --id Microsoft.PowerShell --source wi
export const pwshState = createStore(null);
let loading = null;
+let timer = null;
+let users = 0;
+
+const BUSY = ["waiting", "downloading", "extracting", "verifying", "testing"];
+/** 内置副本正在安装 */
+export const pwshInstalling = (s) => !!s?.private && BUSY.includes(s.private.install?.state);
+
+const mb = (n) => (n === undefined || n === null ? "?" : Math.round(n / 1048576));
+/** 安装进度的一句话 */
+export function pwshProgress(p) {
+ if (!p) return "";
+ if (p.state === "downloading") return `下载 ${mb(p.received)} / ${mb(p.total)} MB${p.total ? `(${Math.min(100, Math.floor(((p.received || 0) / p.total) * 100))}%)` : ""}`;
+ return { waiting: p.error || "准备中", extracting: "解压", verifying: "核对签名", testing: "试运行", done: "已装好", failed: `没装上:${p.error || "未知原因"}` }[p.state] || "";
+}
+
+function schedule(s) {
+ clearTimeout(timer);
+ timer = null;
+ if (!users || !s?.applicable) return;
+ timer = setTimeout(loadPwsh, s.checking || pwshInstalling(s) ? 1500 : 60_000);
+}
+function set(s) {
+ pwshState.set(s);
+ schedule(s);
+ return s;
+}
export function loadPwsh() {
loading ??= api("/pwsh")
- .then((s) => pwshState.set(s))
+ .then(set)
.catch(() => {})
.finally(() => (loading = null));
return loading;
}
-/** 重新检测:装好后点它,下一条消息起代理就用 PowerShell 7 */
+/** 重新检测:重新找、重新试运行(装好系统的 PowerShell 7 后点它;代理空闲时换用) */
export async function recheckPwsh() {
- const s = await api("/pwsh/recheck", { method: "POST", body: {} });
- pwshState.set(s);
- toast(s.missing ? "还没有检测到 PowerShell 7" : `已检测到 PowerShell ${s.version || "7"},下一条消息起生效`, s.missing ? "warn" : "ok");
+ const s = set(await api("/pwsh/recheck", { method: "POST", body: {} }));
+ if (!s.missing) toast(`已检测到 PowerShell ${s.version || "7"}${s.source === "private" ? "(应用内置)" : ""},代理空闲时换用`, "ok");
+ else toast(pwshInstalling(s) ? "还没有能用的 PowerShell 7,正在为代理安装" : "还没有检测到能用的 PowerShell 7", "warn");
+ return s;
+}
+
+/** 安装 / 重新安装应用内置的 PowerShell 7(后台进行,进度在提示和故障排查里) */
+export async function installPwsh(reinstall = false) {
+ const s = set(await api("/pwsh/install", { method: "POST", body: { reinstall } }));
+ if (pwshInstalling(s)) toast(reinstall ? "正在重新安装 PowerShell 7…" : "正在安装 PowerShell 7…");
+ else if (!s.missing) toast(`代理用 PowerShell ${s.version || "7"}`, "ok");
+ return s;
+}
+
+/** 改回系统默认(system)/ 重新用应用内置的(auto) */
+export async function setPwshMode(mode) {
+ const s = set(await api("/pwsh/mode", { method: "PUT", body: { mode } }));
+ toast(mode === "system" ? "已改回系统默认,代理空闲时生效" : "已改用应用内置的 PowerShell 7", "ok");
return s;
}
/** 不再提示:记在 config.json(ui.pwshHintDismissed);故障排查里的状态行照常显示 */
export async function dismissPwsh() {
- pwshState.set(await api("/pwsh", { method: "PUT", body: { dismissed: true } }));
+ set(await api("/pwsh", { method: "PUT", body: { dismissed: true } }));
}
+// "知道了":装好、自动退回这类一次性的结果,看过就不再显示(记在本机浏览器里)
+const SEEN = "amb.pwsh.seen";
+function seenList() {
+ try {
+ return JSON.parse(localStorage.getItem(SEEN) || "[]");
+ } catch {
+ return [];
+ }
+}
+const seen = (key) => seenList().includes(key);
+export function ackPwsh(key) {
+ try {
+ localStorage.setItem(SEEN, JSON.stringify([...seenList(), key].slice(-20)));
+ } catch {
+ /* 存不了就只在这次隐藏 */
+ }
+ const s = pwshState.get();
+ if (s) pwshState.set({ ...s, acked: [...(s.acked || []), key] });
+}
+const acked = (s, key) => seen(key) || (s.acked || []).includes(key);
+
export function usePwsh() {
const s = useStore(pwshState);
useEffect(() => {
+ users++;
if (!pwshState.get()) loadPwsh();
+ else schedule(pwshState.get());
+ return () => {
+ users--;
+ if (!users) clearTimeout(timer);
+ };
}, []);
return s;
}
-/** 要不要显示提示:Windows(或模拟)、没有 PowerShell 7、没点过"不再提示" */
-export const showPwshHint = (s) => !!(s && s.applicable && s.missing && !s.dismissed);
+/**
+ * 提示显示哪一种(null = 不显示):
+ * installing 正在安装;installed 刚装好;fallback 用的 PowerShell 起不来、已自动换掉(还有能用的 7);
+ * broken 内置的坏了、退回了 5.1;failed 没装上;unsupported 这台电脑装不了;missing 没有 PowerShell 7。
+ * 后四种点过"不再提示"就不显示(故障排查里照常有)。
+ */
+export function pwshHint(s) {
+ if (!s || !s.applicable || s.checking) return null;
+ const p = s.private;
+ const inst = p?.install;
+ if (pwshInstalling(s)) return "installing";
+ if (!s.missing) {
+ if (s.fallback && !acked(s, `fb:${s.fallback.at}`)) return "fallback";
+ if (s.source === "private" && inst?.state === "done" && inst.finishedAt && !acked(s, `ok:${inst.finishedAt}`)) return "installed";
+ return null;
+ }
+ if (s.dismissed) return null;
+ if (s.mode !== "system" && p?.bad) return "broken";
+ if (s.mode !== "system" && inst?.state === "failed") return "failed";
+ if (p && !p.supported && p.reason) return "unsupported";
+ return "missing";
+}
+export const showPwshHint = (s) => !!pwshHint(s);
diff --git a/ui/screens/settings.js b/ui/screens/settings.js
index 9ab311b..75aa9a8 100644
--- a/ui/screens/settings.js
+++ b/ui/screens/settings.js
@@ -267,7 +267,7 @@ export function SettingsScreen({ tab, query: q, onQuery: setQ, onTab, focusRow,
{ tab: "about", id: "diagnostics", name: "诊断信息", sub: status ? `内置模型网关 · ${GATEWAY[status.gateway.state] || status.gateway.state}${status.gateway.restarts ? ` · 重启 ${status.gateway.restarts} 次` : ""}${status.gateway.lastError ? ` · ${status.gateway.lastError}` : ""}` : "", keys: "网关 gateway magpie",
ctl: html`<button type="button" class="text" onClick=${() => onTab?.("troubleshoot")}>故障排查</button>` },
// 故障排查页是单独的面板(troubleshoot.js),这一行只给搜索用:搜"日志""测试模型"时能找到入口
- { tab: "troubleshoot", id: "troubleshoot", name: "故障排查", sub: "模型网关与代理进程的状态、测试模型、测试代理、最近日志、复制诊断信息", keys: "日志 log 测试 test 代理 agent 卡住 转圈 诊断 diagnostics 重启 PowerShell pwsh 命令慢",
+ { tab: "troubleshoot", id: "troubleshoot", name: "故障排查", sub: "模型网关与代理进程的状态、测试模型、测试代理、最近日志、复制诊断信息", keys: "日志 log 测试 test 代理 agent 卡住 转圈 诊断 diagnostics 重启 PowerShell pwsh 命令慢 安装 重新安装 内置 系统默认",
ctl: html`<button type="button" class="text" onClick=${() => { setQ(""); onTab?.("troubleshoot"); }}>打开</button>` },
{ tab: "about", id: "links", name: "Modelflare", sub: "官网与文档",
ctl: html`<a class="text" href=${MF_CONSOLE} target="_blank" rel="noopener noreferrer">modelflare.dev ↗</a><a class="text" href=${MF_DOCS} target="_blank" rel="noopener noreferrer">文档 ↗</a>` },
diff --git a/ui/screens/troubleshoot.js b/ui/screens/troubleshoot.js
index c9fb134..49c7458 100644
--- a/ui/screens/troubleshoot.js
+++ b/ui/screens/troubleshoot.js
@@ -4,7 +4,7 @@ import { useEffect, useRef, useState } from "preact/hooks";
import { html, Button, CopyButton, Icon, Skeleton } from "../components/ui.js";
import { api } from "../lib/api.js";
import { failed, toast } from "../lib/store.js";
-import { PWSH_INSTALL_URL, PWSH_WINGET, recheckPwsh } from "../lib/pwsh.js";
+import { PWSH_INSTALL_URL, PWSH_WINGET, installPwsh, pwshInstalling, pwshProgress, recheckPwsh, setPwshMode } from "../lib/pwsh.js";
const GATEWAY = { running: ["运行中", "ok"], starting: ["启动中", "warn"], restarting: ["重启中", "warn"], failed: ["失败", "err"], stopped: ["已停止", "off"], external: ["外部端点", "ok"] };
const HOST = { running: ["运行中", "ok"], starting: ["启动中", "warn"], backoff: ["等待重试", "warn"], error: ["已暂停", "err"], stopped: ["未启动", "off"] };
@@ -45,24 +45,58 @@ const Verdict = ({ ok }) => html`<span class="ts-state"><span class=${`dot ${ok
const ms = (v) => (v === undefined || v === null ? "" : v >= 10_000 ? `${(v / 1000).toFixed(1)} 秒` : `${v} ms`);
const exitText = (e) => (e ? `上次退出 code=${e.code ?? "-"}${e.signal ? ` signal=${e.signal}` : ""}` : "");
const join = (...a) => a.filter(Boolean).join(" · ");
-const PS_SOURCE = { "program-files": "安装目录", path: "PATH", preview: "预览版", store: "Microsoft Store" };
-
-/** PowerShell(只在 Windows 上):版本或"未安装";没有 7 时下面多一行安装命令和下载链接 */
-function PwshRows({ ps, busy, onRecheck }) {
+const PS_SOURCE = { "program-files": "安装目录", path: "PATH", preview: "预览版", store: "Microsoft Store", private: "应用内置" };
+const fmtTime = (t) => (t ? new Date(t).toLocaleString() : "");
+
+/**
+ * PowerShell(只在 Windows 上):代理用的是哪个;下面一行是应用内置的 PowerShell 7(状态、安装进度、安装 / 重新安装 / 改回系统默认);
+ * 没有 7 又没法自己装时再多一行手动安装命令
+ */
+function PwshRows({ ps, busy, onRecheck, onInstall, onMode }) {
if (!ps || !ps.applicable) return null;
- const [text, kind] = ps.checking ? ["检测中", ""] : !ps.missing ? [ps.version || "7", "ok"] : ps.found && ps.version ? [ps.version, "warn"] : ["未安装", "warn"];
+ const p = ps.private;
+ const installing = pwshInstalling(ps);
+ const [text, kind] = ps.checking ? ["检测中", ""] : !ps.missing ? [ps.version || "7", "ok"] : installing ? ["安装中", "warn"] : ps.found && ps.version ? [ps.version, "warn"] : ["未安装", "warn"];
+ const fb = ps.fallback ? `${fmtTime(ps.fallback.at)} ${ps.fallback.from} 起不来(${ps.fallback.reason}),已自动换掉` : "";
const sub = ps.checking
? "正在找 PowerShell 7"
: !ps.missing
- ? join(ps.path, PS_SOURCE[ps.source], "代理用它执行命令")
- : ps.found
- ? join(ps.path, "版本较旧:装上 PowerShell 7,命令执行快得多,也更稳定")
- : "代理执行命令用的是系统自带的 Windows PowerShell 5.1,每条可能要二三十秒。装上 PowerShell 7,命令执行快得多,也更稳定";
+ ? join(ps.path, PS_SOURCE[ps.source], "代理用它执行命令", fb)
+ : join(
+ ps.systemIssue ? `${ps.path} 用不了:${ps.systemIssue}` : ps.found && `${ps.path} 版本较旧`,
+ "代理执行命令用的是系统自带的 Windows PowerShell 5.1,每条可能要二三十秒",
+ installing ? "装好 PowerShell 7 后自动换用" : "装上 PowerShell 7,命令执行快得多,也更稳定",
+ );
+ // 内置副本
+ let row = null;
+ if (p) {
+ const inst = p.install || {};
+ const system = ps.mode === "system";
+ const [pt, pk] = !p.supported ? ["装不了", ""] : installing ? [pwshProgress(inst), "warn"] : system ? ["未使用", ""] : p.ready ? ["已就绪", "ok"] : p.bad ? ["用不了", "err"] : inst.state === "failed" ? ["没装上", "err"] : p.installed ? ["已安装", "warn"] : ["未安装", ""];
+ const psub = !p.supported
+ ? p.reason
+ : join(
+ installing ? "正在下载、核对哈希与微软签名、试运行,不需要管理员权限" : "",
+ !installing && p.ready && `${p.version}${p.arch ? ` ${p.arch}` : ""} · 已核对微软签名,试运行通过(${p.test ? `${p.test.ms} ms,${fmtTime(p.test.at)}` : ""})`,
+ !installing && p.bad && `用不了:${p.bad.reason}`,
+ !installing && !p.bad && inst.state === "failed" && `没装上:${inst.error || "未知原因"}`,
+ !installing && !p.installed && inst.state !== "failed" && (system ? "已改回系统默认,不用应用内置的 PowerShell 7" : ps.autoInstall ? "系统里没有能用的 PowerShell 7 时自动安装" : `${p.version},点"安装"下载(约 110 MB)`),
+ p.installed && system && "已改回系统默认,不用它",
+ p.dir,
+ );
+ const b = (what, label, fn, cls = "text") => html`<button type="button" class=${cls} disabled=${!!busy || installing} aria-busy=${busy === what || undefined} onClick=${fn}>${busy === what ? `${label}…` : label}</button>`;
+ row = html`<${Row} compact id="pwsh-private" name="应用内置的 PowerShell 7" sub=${psub}>
+ <span class="ts-state"><span class=${`dot ${pk}`}></span>${pt}</span>
+ ${p.supported && !installing && (system ? (p.ready ? b("pwsh-auto", "改用它", () => onMode("auto")) : b("pwsh-install", "安装", () => onInstall(false))) : !p.installed ? b("pwsh-install", "安装", () => onInstall(false)) : b("pwsh-install", "重新安装", () => onInstall(true)))}
+ ${p.supported && !installing && !system && (p.installed || p.ready) && b("pwsh-system", "改回系统默认", () => onMode("system"))}
+ <//>`;
+ }
return html`<${Row} id="pwsh" name="PowerShell" sub=${sub}>
<span class="ts-state"><span class=${`dot ${kind}`}></span>${text}</span>
<button type="button" class="text" disabled=${!!busy} aria-busy=${busy === "pwsh" || undefined} onClick=${onRecheck}>${busy === "pwsh" ? "检测中…" : "重新检测"}</button>
<//>
- ${ps.missing && html`<${Row} compact id="pwsh-install" name="安装 PowerShell 7" sub=${PWSH_WINGET} mono>
+ ${row}
+ ${ps.missing && !installing && (!p || !p.supported || ps.mode === "system" || p.bad || p.install?.state === "failed") && html`<${Row} compact id="pwsh-manual" name="自己安装 PowerShell 7" sub=${PWSH_WINGET} mono>
<${CopyButton} text=${PWSH_WINGET} label="复制安装命令" />
<a class="btn sm" href=${PWSH_INSTALL_URL} target="_blank" rel="noopener noreferrer">下载安装 ↗</a>
<//>`}`;
@@ -131,6 +165,8 @@ export function TroubleshootPane({ bots, desktop }) {
toast(r.restarted.length ? "代理进程已重启" : "代理进程还没有启动,下一条消息时启动");
});
const recheckPs = () => run("pwsh", recheckPwsh);
+ const installPs = (reinstall) => run("pwsh-install", () => installPwsh(reinstall));
+ const modePs = (mode) => run(mode === "system" ? "pwsh-system" : "pwsh-auto", () => setPwshMode(mode));
const copy = () =>
run("copy", async () => {
const { text } = await api("/diagnostics/report?lines=200");
@@ -157,7 +193,7 @@ export function TroubleshootPane({ bots, desktop }) {
<${State} map=${HOST} s=${h.state} />
<//>`)}
${tail.length > 0 && html`<div class="row-edit ts-tail"><span class="t-label">代理进程输出(stderr 最后 ${tail.length} 行)</span><pre class="ts-mono">${tail.join("\n")}</pre></div>`}
- <${PwshRows} ps=${st.pwsh} busy=${busy} onRecheck=${recheckPs} />
+ <${PwshRows} ps=${st.pwsh} busy=${busy} onRecheck=${recheckPs} onInstall=${installPs} onMode=${modePs} />
<${Row} id="version" name="版本" sub=${join(st.os, st.electron && `Electron ${st.electron}`, `Node ${st.node}`)}>
<span class="val">${st.version} · ${st.platform} ${st.arch}</span>
<//>