diff --git a/docs/KAAK-CLONE-WORKLOG.zh-CN.md b/docs/KAAK-CLONE-WORKLOG.zh-CN.md index c26abde..a1f7d5c 100644 --- a/docs/KAAK-CLONE-WORKLOG.zh-CN.md +++ b/docs/KAAK-CLONE-WORKLOG.zh-CN.md @@ -634,3 +634,10 @@ - 用户反馈:KAAK 皮肤中服务器密码和频道密码弹窗的绿色确认按钮文字换行难看,要求统一为“确定”。 - 修改范围:KAAK 下两个密码弹窗的主按钮统一显示“确定”,其他皮肤继续使用原有本地化文案;服务器重试、频道提交、取消和错误状态逻辑保持不变。 - 验证与部署:`npm run verify` 通过(696/696 测试、服务端构建、前端类型检查与 Vite 生产构建);3040 健康接口与首页返回 200,生产 WebClient JS 返回 200,大小与本地构建一致(440,272 字节),并包含“确定”文案。静态构建已供 3040 使用,无需重启服务。 + +## 本轮服务器导航新增入口(2026-10-12) + +- 用户要求所有皮肤、任意连接模式下,在进入语音页后都能从左侧服务器导航栏添加服务器。新增入口由 WebSpeak 宿主提供:普通导航栏保留原加号;替换式皮肤的 `server-rail` / `quick-rail` 也由宿主注入分隔线和加号,不依赖单个皮肤包。KAAK 加号按 58×58px、18px 圆角样式呈现,KAAK 升至 3.1.79 并重建示例与内置 `.wskin`。 +- open 模式沿用现有添加对话框,保存收藏后连接新目标。fixed 模式点击加号只显示“该功能已被管理员关闭”,不会打开表单、保存收藏或连接;固定目标策略仍由服务端执行,未放宽。 +- fixed 模式下收藏服务器入口保留可点击事件并以禁用态样式呈现;点击其他服务器的快速入口(通用侧栏、窄屏栏、服务器切换器及皮肤服务器轨道)显示“管理员不允许切换TS服务器”。 +- 验证:服务器轨道注入、可信点击、受限状态无原生禁用、指定中文提示、受限数据投影和 KAAK 分发包定向测试通过(78/78);`npm run verify` 全部通过(698/698 测试、服务端 TypeScript、前端类型检查与 Vite 生产构建);`git diff --check` 通过。 diff --git a/docs/examples/kaak-voice.wskin b/docs/examples/kaak-voice.wskin index cf21510..fca47e0 100644 Binary files a/docs/examples/kaak-voice.wskin and b/docs/examples/kaak-voice.wskin differ diff --git a/docs/examples/kaak-voice/manifest.json b/docs/examples/kaak-voice/manifest.json index 74fa295..e1e6172 100644 --- a/docs/examples/kaak-voice/manifest.json +++ b/docs/examples/kaak-voice/manifest.json @@ -3,7 +3,7 @@ "packageType": "open-skin", "id": "community.kaak-voice", "name": "KAAK", - "version": "3.1.78", + "version": "3.1.79", "author": "WebSpeak Project", "license": "AGPL-3.0-only", "description": "A KOOK-inspired voice workspace with a searchable server header, TeamSpeak banner and welcome message, nested channel members, attached channel chat, and a compact WebSpeak audio dock.", diff --git a/docs/examples/kaak-voice/skin.css b/docs/examples/kaak-voice/skin.css index c90267c..18c5e4f 100644 --- a/docs/examples/kaak-voice/skin.css +++ b/docs/examples/kaak-voice/skin.css @@ -234,7 +234,43 @@ width: 58px; height: 58px; flex: 0 0 58px; -} +} + +[data-ws-plugin-part="kaak-workspace.server-add"] { + display: grid; + box-sizing: border-box; + width: 58px; + height: 58px; + min-height: 58px; + flex: 0 0 58px; + place-items: center; + padding: 0; + border: 2px solid transparent; + border-radius: 18px; + color: #aeb2ba; + background: var(--skin-kaak-rail-item-bg); + font-family: var(--skin-kaak-font); + font-size: 21px; + line-height: 1; + cursor: pointer; + transition: background .15s ease, border-color .15s ease; +} + +[data-ws-plugin-part="kaak-workspace.server-add"]:hover, +[data-ws-plugin-part="kaak-workspace.server-add"]:focus-visible { + color: var(--skin-kaak-rail-text); + background: #383a40; +} + +[data-ws-plugin-part="kaak-workspace.server-add"]:focus-visible { + outline: 2px solid #f0f1f3; + outline-offset: 3px; +} + +[data-ws-plugin-part="kaak-workspace.quick-server"][aria-disabled="true"] { + cursor: not-allowed; + opacity: .48; +} [data-ws-plugin-part="kaak-workspace.quick-server"] { position: relative; diff --git a/src/shared/skin-plugin.test.ts b/src/shared/skin-plugin.test.ts index 5558829..1f51381 100644 --- a/src/shared/skin-plugin.test.ts +++ b/src/shared/skin-plugin.test.ts @@ -100,19 +100,27 @@ test("replacing a built-in public page requires an explicit user approval capabi assert.deepEqual(parseSkinPluginDocument(document).components[0].permissions, ["ui.surface.replace"]); }); -test("custom surfaces can safely render and switch unified favorite and recent server entries", () => { - const document = validDocument(); - document.components[0].permissions = ["servers.quickList.read", "servers.quickList.switch"]; +test("custom surfaces can safely render and switch unified favorite and recent server entries", () => { + const document = validDocument(); + document.schemaVersion = 3; + document.components[0].permissions = ["servers.quickList.read", "servers.quickList.switch"]; document.components[0].actions = { switch: { type: "quickServers.switch", args: { quickServerId: "{{server.id}}" } }, }; document.components[0].root = { tag: "nav", repeat: { path: "servers.quickList", as: "server" }, - children: [{ tag: "button", events: { dblclick: "switch" }, children: [{ text: "{{server.label}}" }] }], + children: [{ + tag: "button", + attributes: { "aria-disabled": "{{server.switchRestricted}}", title: "{{server.switchTitle}}" }, + events: { dblclick: "switch" }, + children: [{ text: "{{server.label}}" }], + }], }; const parsed = parseSkinPluginDocument(document).components[0]; - assert.equal(parsed.root.repeat?.path, "servers.quickList"); + assert.equal(parsed.root.repeat?.path, "servers.quickList"); + assert.equal(parsed.root.children?.[0].attributes?.["aria-disabled"], "{{server.switchRestricted}}"); + assert.equal(parsed.root.children?.[0].attributes?.title, "{{server.switchTitle}}"); assert.equal(parsed.actions.switch.type, "quickServers.switch"); document.components[0].permissions = ["servers.quickList.read"]; diff --git a/src/shared/skin-plugin.ts b/src/shared/skin-plugin.ts index a9de8f9..69a4f76 100644 --- a/src/shared/skin-plugin.ts +++ b/src/shared/skin-plugin.ts @@ -250,7 +250,7 @@ const COLLECTION_FIELDS: Record> = { "session.channels": new Set(["id", "name", "parentId", "depth", "memberCount", "memberCountLabel", "maxClients", "maxClientsLimited", "current"]), "session.members": new Set(["id", "name", "avatarInitial", "channelId", "status", "speaking", "self", "screenSharing", "screenShareStreamId"]), "favorites.items": new Set(["id", "label", "current", "kind"]), - "servers.quickList": new Set(["id", "label", "monogram", "icon", "tone", "current", "kind", "favorite"]), + "servers.quickList": new Set(["id", "label", "monogram", "icon", "tone", "current", "switchRestricted", "switchTitle", "kind", "favorite"]), "chat.messages": new Set(["id", "author", "text", "time", "kind", "channelId"]), "screenShare.streams": new Set(["streamId", "source", "ownerClientId", "ownerNickname", "name", "audio", "viewerCount"]), }; diff --git a/web/public/skins/kaak-voice.wskin b/web/public/skins/kaak-voice.wskin index cf21510..fca47e0 100644 Binary files a/web/public/skins/kaak-voice.wskin and b/web/public/skins/kaak-voice.wskin differ diff --git a/web/src/components/SkinPluginOutlet.ts b/web/src/components/SkinPluginOutlet.ts index 770194d..de0beb1 100644 --- a/web/src/components/SkinPluginOutlet.ts +++ b/web/src/components/SkinPluginOutlet.ts @@ -55,11 +55,13 @@ export default defineComponent({ extensionPermissions: { type: Array as PropType, default: () => [] }, componentNamespace: { type: String, default: "" }, manageSurfaceRecovery: { type: Boolean, default: true }, - page: { type: String as PropType<"home" | "voice" | "demo">, required: true }, - data: { type: Object as PropType, required: true }, - assets: { type: Object as PropType>, required: true }, - actions: { type: Object as PropType>, required: true }, - widgets: { type: Object as PropType>>, default: () => ({}) }, + page: { type: String as PropType<"home" | "voice" | "demo">, required: true }, + data: { type: Object as PropType, required: true }, + assets: { type: Object as PropType>, required: true }, + actions: { type: Object as PropType>, required: true }, + serverAddLabel: { type: String, default: "添加服务器 / Add server" }, + onAddServer: { type: Function as PropType<() => void>, default: () => undefined }, + widgets: { type: Object as PropType>>, default: () => ({}) }, }, emits: { "surface-change": (_active: boolean) => typeof _active === "boolean", @@ -311,12 +313,22 @@ export default defineComponent({ } else if (expected !== undefined ? value !== expected : !value) return null; } const attrs: Record = {}; - for (const [key, value] of Object.entries(node.attributes ?? {})) { + for (const [key, value] of Object.entries(node.attributes ?? {})) { // data-ws-* belongs to host layout, page, and recovery machinery. Older // packages remain loadable, but their nodes cannot impersonate host hooks. if (key.startsWith("data-ws-")) continue; - attrs[svgAttributeNames[key] ?? key] = typeof value === "string" ? interpolate(value, context, state) : value; - } + attrs[svgAttributeNames[key] ?? key] = typeof value === "string" ? interpolate(value, context, state) : value; + } + if (node.tag === "button" && node.part === "quick-server") { + const server = context.server; + if (server && typeof server === "object" && !Array.isArray(server)) { + const restricted = (server as Record).switchRestricted === true; + if (restricted) delete attrs.disabled; + attrs["aria-disabled"] = String(restricted); + const switchTitle = (server as Record).switchTitle; + if (typeof switchTitle === "string") attrs.title = switchTitle; + } + } if (node.asset) { const url = assetUrl(node.asset); if (url) attrs.src = url; @@ -357,7 +369,26 @@ export default defineComponent({ }; } if (node.tag === "form" && !node.events?.submit) attrs.onSubmit = (event: Event) => event.preventDefault(); - const children = (node.children ?? []).map((child, index) => renderNode(component, child, context, state, budget, false, `${nodePath}-${index}`)); + const children = (node.children ?? []).map((child, index) => renderNode(component, child, context, state, budget, false, `${nodePath}-${index}`)); + if (props.page === "voice" && node.tag === "nav" && ["server-rail", "quick-rail"].includes(node.part ?? "")) { + children.push(h("span", { + class: "ws-plugin-server-add-divider", + "data-ws-part": "voice.favorite-servers.skin-add-divider", + "aria-hidden": "true", + })); + children.push(h("button", { + type: "button", + class: "ws-plugin-server-add", + "data-ws-plugin-part": `${component.id}.server-add`, + "data-ws-part": `skin.voice.${component.id}.control-part-server-add`, + "aria-label": props.serverAddLabel, + title: props.serverAddLabel, + onClick: (event: Event) => { + if (!event.isTrusted) return; + props.onAddServer?.(); + }, + }, [h("span", { "aria-hidden": "true" }, "+")])); + } // Custom element names are inert host-rendered placeholders. Never instantiate a page-registered // custom element from generated output, since its connectedCallback would run with page privileges. const tag = node.tag.includes("-") ? "div" : node.tag; diff --git a/web/src/components/SkinRuntimePluginHost.ts b/web/src/components/SkinRuntimePluginHost.ts index a9ef7a9..936cd88 100644 --- a/web/src/components/SkinRuntimePluginHost.ts +++ b/web/src/components/SkinRuntimePluginHost.ts @@ -101,9 +101,11 @@ export default defineComponent({ styles: { type: Object as PropType>, default: () => ({}) }, assets: { type: Object as PropType>, default: () => ({}) }, page: { type: String as PropType, required: true }, - mountRevision: { type: String, default: "" }, - context: { type: Object as PropType>, default: () => ({}) }, - actions: { type: Object as PropType>>, default: () => ({}) }, + mountRevision: { type: String, default: "" }, + context: { type: Object as PropType>, default: () => ({}) }, + actions: { type: Object as PropType>>, default: () => ({}) }, + serverAddLabel: { type: String, default: "添加服务器 / Add server" }, + onAddServer: { type: Function as PropType<() => void>, default: () => undefined }, widgets: { type: Object as PropType VNodeChild>>>, default: () => ({}) }, readSessionStatus: { type: Function as PropType<(signal: AbortSignal) => SkinExtensionSessionStatus | Promise>, required: true }, }, @@ -379,10 +381,12 @@ export default defineComponent({ componentNamespace: plugin.id, manageSurfaceRecovery: false, page: props.page, - data: {}, - assets: pluginAssets, - actions: {}, - extensionPermissions: plugin.permissions, + data: {}, + assets: pluginAssets, + actions: {}, + serverAddLabel: props.serverAddLabel, + onAddServer: props.onAddServer, + extensionPermissions: plugin.permissions, widgets: props.widgets, onExtensionEvent: (event: unknown) => dispatch(plugin.id, event), onSurfaceChange: (active: boolean) => surfaceChanged(plugin.id, active), diff --git a/web/src/components/web-client/VoiceServerSwitcher.vue b/web/src/components/web-client/VoiceServerSwitcher.vue index bb1e5fa..2bb2126 100644 --- a/web/src/components/web-client/VoiceServerSwitcher.vue +++ b/web/src/components/web-client/VoiceServerSwitcher.vue @@ -31,6 +31,8 @@ data-ws-part="voice.server-switcher.item" :class="{ 'is-current': server.current }" :aria-current="server.current ? 'true' : undefined" + :aria-disabled="server.current || server.switchRestricted" + :title="server.switchTitle" :disabled="server.current" @click="switchServer(server)" > diff --git a/web/src/i18n/web-client.ts b/web/src/i18n/web-client.ts index c680b43..c49a145 100644 --- a/web/src/i18n/web-client.ts +++ b/web/src/i18n/web-client.ts @@ -84,6 +84,8 @@ export const webClientTranslations: Record> = { favoriteServers: "常用服务器", quickServers: "快速连接", addFavoriteServer: "添加服务器", + serverFeatureAdminDisabled: "该功能已被管理员关闭", + serverSwitchRestricted: "管理员不允许切换TS服务器", quickConnectTitle: "添加服务器收藏", favoriteDisplayName: "显示名称", favoriteDisplayNamePlaceholder: "例如:游戏、朋友或社区", @@ -495,6 +497,8 @@ export const webClientTranslations: Record> = { favoriteServers: "Favorites", quickServers: "Quick servers", addFavoriteServer: "Add server", + serverFeatureAdminDisabled: "This feature has been disabled by the administrator.", + serverSwitchRestricted: "The administrator does not allow switching TS servers.", quickConnectTitle: "Add a server favorite", favoriteDisplayName: "Display name", favoriteDisplayNamePlaceholder: "For example: gaming, friends, or community", @@ -909,6 +913,8 @@ webClientTranslations.de = { favoriteServers: "Favoriten", quickServers: "Schnellverbindungen", addFavoriteServer: "Server hinzufügen", + serverFeatureAdminDisabled: "Diese Funktion wurde vom Administrator deaktiviert.", + serverSwitchRestricted: "Der Administrator erlaubt keinen Wechsel des TeamSpeak-Servers.", quickConnectTitle: "Server zu Favoriten hinzufügen", favoriteDisplayName: "Anzeigename", favoriteDisplayNamePlaceholder: "Zum Beispiel: Gaming, Freunde oder Community", @@ -1354,6 +1360,8 @@ webClientTranslations.ru = { favoriteServers: "Избранное", quickServers: "Быстрый доступ", addFavoriteServer: "Добавить сервер", + serverFeatureAdminDisabled: "Эта функция отключена администратором.", + serverSwitchRestricted: "Администратор запретил переключение серверов TeamSpeak.", quickConnectTitle: "Добавить сервер в избранное", favoriteDisplayName: "Отображаемое имя", favoriteDisplayNamePlaceholder: "Например: игра, друзья или сообщество", @@ -1552,6 +1560,8 @@ webClientTranslations.ja = { favoriteServers: "お気に入り", quickServers: "クイック接続", addFavoriteServer: "サーバーを追加", + serverFeatureAdminDisabled: "この機能は管理者によって無効にされています。", + serverSwitchRestricted: "管理者はTeamSpeakサーバーの切り替えを許可していません。", quickConnectTitle: "サーバーをお気に入りに追加", favoriteDisplayName: "表示名", favoriteDisplayNamePlaceholder: "例:ゲーム、友人、コミュニティ", diff --git a/web/src/services/skin-catalog.ts b/web/src/services/skin-catalog.ts index ce81920..ced593a 100644 --- a/web/src/services/skin-catalog.ts +++ b/web/src/services/skin-catalog.ts @@ -46,7 +46,7 @@ export const BUILTIN_SKIN_CATALOG: SkinCatalogEntry[] = [ { id: BUILTIN_KAAK_SKIN_ID, name: "KAAK", - version: "3.1.78", + version: "3.1.79", author: "WebSpeak Project", license: "AGPL-3.0-only", description: "A KOOK-inspired voice-room workspace with a searchable server header, TeamSpeak banner and welcome message, nested channel members, attached channel chat, and a compact WebSpeak audio dock.", diff --git a/web/src/services/skin-extension-ui.test.ts b/web/src/services/skin-extension-ui.test.ts index 7095361..c443c1a 100644 --- a/web/src/services/skin-extension-ui.test.ts +++ b/web/src/services/skin-extension-ui.test.ts @@ -217,6 +217,109 @@ test("generated SVG restores case-sensitive standard attribute names in host-ren assert.match(html, /gradientUnits="userSpaceOnUse"/); }); +test("host adds a trusted server-add control to custom server rails in every skin", async () => { + for (const part of ["server-rail", "quick-rail"]) { + const html = await renderToString(createSSRApp(SkinPluginOutlet, { + skinId: "community.server-add-test", + skinVersion: "1.0.0", + document: { schemaVersion: 3, components: [] }, + extensionOutput: generatedOutput("voice-workspace", { tag: "nav", part, children: [] }), + page: "voice", + data: {}, + assets: {}, + actions: {}, + serverAddLabel: "Add server", + })); + assert.match(html, /data-ws-plugin-part="voice-workspace\.server-add"/); + assert.match(html, /aria-label="Add server"/); + } + + const homeHtml = await renderToString(createSSRApp(SkinPluginOutlet, { + skinId: "community.server-add-test", + skinVersion: "1.0.0", + document: { schemaVersion: 3, components: [] }, + extensionOutput: generatedOutput("home-workspace", { tag: "nav", part: "server-rail", children: [] }), + page: "home", + data: {}, + assets: {}, + actions: {}, + })); + assert.doesNotMatch(homeHtml, /\.server-add/); + + const restrictedQuickServerHtml = await renderToString(createSSRApp(SkinPluginOutlet, { + skinId: "community.server-add-test", + skinVersion: "1.0.0", + document: { schemaVersion: 3, components: [] }, + extensionOutput: generatedOutput("voice-workspace", { + tag: "nav", + part: "server-rail", + children: [{ tag: "button", part: "quick-server", attributes: { type: "button", disabled: true } }], + }), + page: "voice", + data: { server: { switchRestricted: true, switchTitle: "管理员不允许切换TS服务器" } }, + assets: {}, + actions: {}, + })); + assert.match(restrictedQuickServerHtml, /aria-disabled="true"/); + assert.match(restrictedQuickServerHtml, /title="管理员不允许切换TS服务器"/); + assert.doesNotMatch(restrictedQuickServerHtml, /\sdisabled(?:="(?:true|disabled)?")?(?:\s|>)/); + + type HostNode = { type: string; props: Record; text: string; children: HostNode[]; parent?: HostNode }; + const createHostNode = (type: string, text = ""): HostNode => ({ type, props: {}, text, children: [] }); + const renderer = createRenderer({ + patchProp(node, key, _previous, next) { node.props[key] = next; }, + insert(node, parent, anchor) { + node.parent = parent; + const oldIndex = parent.children.indexOf(node); + if (oldIndex >= 0) parent.children.splice(oldIndex, 1); + const anchorIndex = anchor ? parent.children.indexOf(anchor) : -1; + parent.children.splice(anchorIndex >= 0 ? anchorIndex : parent.children.length, 0, node); + }, + remove(node) { + if (!node.parent) return; + const index = node.parent.children.indexOf(node); + if (index >= 0) node.parent.children.splice(index, 1); + node.parent = undefined; + }, + createElement: (type) => createHostNode(type), + createText: (text) => createHostNode("#text", text), + createComment: (text) => createHostNode("#comment", text), + setText(node, text) { node.text = text; }, + setElementText(node, text) { node.children = []; node.text = text; }, + parentNode: (node) => node.parent ?? null, + nextSibling(node) { + if (!node.parent) return null; + return node.parent.children[node.parent.children.indexOf(node) + 1] ?? null; + }, + }); + let addCount = 0; + const app = renderer.createApp(SkinPluginOutlet, { + skinId: "community.server-add-test", + skinVersion: "1.0.0", + document: { schemaVersion: 3, components: [] }, + extensionOutput: generatedOutput("voice-workspace", { tag: "nav", part: "server-rail", children: [] }), + page: "voice", + data: {}, + assets: {}, + actions: {}, + onAddServer: () => { addCount += 1; }, + }); + const host = createHostNode("root"); + app.mount(host); + await nextTick(); + const findAddButton = (node: HostNode): HostNode | undefined => { + if (node.type === "button" && node.props["data-ws-plugin-part"] === "voice-workspace.server-add") return node; + return node.children.map(findAddButton).find(Boolean); + }; + const addButton = findAddButton(host); + assert.ok(addButton); + (addButton.props.onClick as (event: Event) => void)({ isTrusted: false } as Event); + assert.equal(addCount, 0, "synthetic events cannot open the host dialog"); + (addButton.props.onClick as (event: Event) => void)({ isTrusted: true } as Event); + assert.equal(addCount, 1, "a trusted click opens the existing host add-server flow"); + app.unmount(); +}); + test("generated UI can exceed the former 16 KiB output ceiling while staying within the new package-sized limit", () => { const source = JSON.stringify({ schemaVersion: 4, diff --git a/web/src/services/skin-pack.test.ts b/web/src/services/skin-pack.test.ts index 76d1560..9d73c5e 100644 --- a/web/src/services/skin-pack.test.ts +++ b/web/src/services/skin-pack.test.ts @@ -479,7 +479,7 @@ test("the distributable KAAK package provides full home and voice surfaces", asy const file = new File([archive], "kaak-voice.wskin", { type: "application/octet-stream" }); const skin = await importSkinPack(file); assert.equal(skin.id, "community.kaak-voice"); - assert.equal(skin.version, "3.1.78"); + assert.equal(skin.version, "3.1.79"); assert.equal(BUILTIN_SKIN_CATALOG.find((entry) => entry.id === skin.id)?.version, skin.version); assert.equal(skin.schemaVersion, 3); const home = skin.pluginData?.components.find((component) => component.page === "home"); @@ -670,6 +670,7 @@ test("the distributable KAAK package provides full home and voice surfaces", asy assert.match(skin.css, /minmax\(340px, min\(38vw, 520px\)\)/); assert.match(skin.css, /grid-template-rows: 40px/); assert.match(skin.css, /kaak-workspace\.server-rail"\]\s*\{[\s\S]*?--skin-kaak-rail-bg: #191a1d;[\s\S]*?--skin-kaak-rail-item-bg: #2b2d32;[\s\S]*?--skin-kaak-rail-accent: #75c900;[\s\S]*?gap: 18px;[\s\S]*?padding: 14px 0 96px;[\s\S]*?background: var\(--skin-kaak-rail-bg\);/); + assert.match(skin.css, /kaak-workspace\.server-add"\]\s*\{[\s\S]*?width: 58px;[\s\S]*?height: 58px;[\s\S]*?border-radius: 18px;/); assert.match(skin.css, /kaak-workspace\.quick-server-item"\]\s*\{[\s\S]*?width: 58px;[\s\S]*?height: 58px;/); assert.match(skin.css, /kaak-workspace\.quick-server"\]\s*\{[\s\S]*?width: 58px;[\s\S]*?height: 58px;[\s\S]*?border: 2px solid transparent;[\s\S]*?border-radius: 18px;/); assert.match(skin.css, /quick-server\"\]\:hover[\s\S]*?background: #383a40;/); diff --git a/web/src/services/skin-plugin-context.ts b/web/src/services/skin-plugin-context.ts index 3449899..50e3565 100644 --- a/web/src/services/skin-plugin-context.ts +++ b/web/src/services/skin-plugin-context.ts @@ -8,6 +8,8 @@ export interface SkinPluginQuickServer { icon: string; tone: number; current: boolean; + switchRestricted: boolean; + switchTitle: string; kind: "favorite" | "recent"; favorite: boolean; } @@ -44,7 +46,12 @@ export function createSkinPluginQuickServerProjection(createId: () => string = r const targetByOpaqueId = new Map(); return { - project(servers: readonly QuickServer[], isCurrent: (server: QuickServer) => boolean): SkinPluginQuickServer[] { + project( + servers: readonly QuickServer[], + isCurrent: (server: QuickServer) => boolean, + switchRestricted = false, + switchRestrictedLabel = "Server switching is restricted by the administrator", + ): SkinPluginQuickServer[] { const activeServerIds = new Set(servers.map((server) => server.id)); for (const id of opaqueIdByServerId.keys()) if (!activeServerIds.has(id)) opaqueIdByServerId.delete(id); targetByOpaqueId.clear(); @@ -70,6 +77,8 @@ export function createSkinPluginQuickServerProjection(createId: () => string = r icon: isSafeQuickServerIcon(server.serverIcon) ? server.serverIcon : "", tone: safeLabelTone(safeLabel), current: isCurrent(server), + switchRestricted, + switchTitle: switchRestricted ? switchRestrictedLabel : safeLabel, kind: server.isFavorite ? "favorite" : "recent", favorite: server.isFavorite, }; diff --git a/web/src/services/skin-plugin-runtime.test.ts b/web/src/services/skin-plugin-runtime.test.ts index 21179bc..d712186 100644 --- a/web/src/services/skin-plugin-runtime.test.ts +++ b/web/src/services/skin-plugin-runtime.test.ts @@ -8,6 +8,7 @@ import { revokeSkinPluginApprovals, } from "./skin-plugin-approval.js"; import { createSkinPluginQuickServerProjection } from "./skin-plugin-context.js"; +import { webClientTranslations } from "../i18n/web-client.js"; import "./skin-plugin-asset-urls.test.js"; function surfaceDocument(): SkinPluginDocument { @@ -74,6 +75,7 @@ test("skin quick-server data redacts connection targets and resolves only host-g ["Recent 2", "recent", false, false], ["Friends", "favorite", true, true], ]); + assert.ok(rows.every(({ switchRestricted, switchTitle }) => !switchRestricted && typeof switchTitle === "string")); assert.equal(JSON.stringify(rows).includes("192.0.2.10"), false); assert.equal(JSON.stringify(rows).includes("voice.example"), false); const friendsTone = rows.find(({ label }) => label === "Friends")?.tone; @@ -82,6 +84,10 @@ test("skin quick-server data redacts connection targets and resolves only host-g assert.equal(reorderedTone, friendsTone, "a server keeps its color tone when its saved-list position changes"); assert.equal(projection.resolve("opaque-1")?.address, "192.0.2.10:9987"); assert.equal(projection.resolve("192.0.2.10:9987"), undefined); + + const restricted = projection.project(servers, () => false, true, "管理员不允许切换TS服务器"); + assert.ok(restricted.every(({ switchRestricted, switchTitle }) => switchRestricted && switchTitle === "管理员不允许切换TS服务器")); + assert.equal(JSON.stringify(restricted).includes("192.0.2.10"), false); }); test("skin quick-server projection uses the TeamSpeak name and public icon while keeping its target private", () => { @@ -116,3 +122,8 @@ test("skin quick-server projection does not expose a network target used as the assert.equal(server.monogram, "F"); assert.equal(JSON.stringify(server).includes("server.example.invalid"), false); }); + +test("fixed-mode server controls use the requested Chinese restriction messages", () => { + assert.equal(webClientTranslations.zh.serverFeatureAdminDisabled, "该功能已被管理员关闭"); + assert.equal(webClientTranslations.zh.serverSwitchRestricted, "管理员不允许切换TS服务器"); +}); diff --git a/web/src/styles/web-client.css b/web/src/styles/web-client.css index aa8fd8e..345a253 100644 --- a/web/src/styles/web-client.css +++ b/web/src/styles/web-client.css @@ -7890,11 +7890,68 @@ border-radius: 0 4px 4px 0; } +[data-ws-plugin-part$=".quick-server"][aria-disabled="true"] { + cursor: not-allowed; + opacity: .48; +} + +.ws-plugin-server-add { + position: sticky; + bottom: 0; + z-index: 1; + display: grid; + width: 42px; + height: 42px; + flex: 0 0 42px; + place-items: center; + padding: 0; + border: 1px solid var(--border); + border-radius: 14px; + color: var(--text-muted); + background: var(--surface-2); + font: inherit; + font-size: 22px; + line-height: 1; + cursor: pointer; + transition: color .14s ease, background .14s ease, border-color .14s ease; +} + +.ws-plugin-server-add-divider { + display: block; + width: 34px; + height: 1px; + flex: 0 0 1px; + background: color-mix(in srgb, currentColor 18%, transparent); +} + +.ws-plugin-server-add:hover, +.ws-plugin-server-add:focus-visible { + color: var(--text-primary); + border-color: var(--accent); + background: var(--surface-2); +} + +.ws-plugin-server-add:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 3px; +} + .favorite-server-button:disabled { cursor: wait; opacity: .65; } +.favorite-server-button[aria-disabled="true"], +.favorite-server-strip-button[aria-disabled="true"] { + cursor: not-allowed; + opacity: .48; +} + +.ws-voice-server-switcher-item[aria-disabled="true"]:not(.is-current) { + cursor: not-allowed; + opacity: .55; +} + .favorite-server-avatar { display: grid; width: 40px; diff --git a/web/src/views/WebClient.vue b/web/src/views/WebClient.vue index 25d76d8..6d14f40 100644 --- a/web/src/views/WebClient.vue +++ b/web/src/views/WebClient.vue @@ -17,10 +17,12 @@ :skin-version="activeSkin.version" :document="skinPluginDocument" :page="showVoiceShell ? 'voice' : 'home'" - :data="skinPluginContext" - :assets="activeSkin.assets" - :actions="skinPluginActions" - :widgets="skinPluginWidgets" + :data="skinPluginContext" + :assets="activeSkin.assets" + :actions="skinPluginActions" + :server-add-label="t('addFavoriteServer')" + :on-add-server="openFavoriteServerDialog" + :widgets="skinPluginWidgets" @surface-change="skinPluginSurfaceActive = $event" @restore-skin="switchToBuiltIn" /> @@ -42,10 +44,12 @@ :styles="activeSkin.runtimePluginStyles ?? {}" :assets="activeSkin.assets" :page="showVoiceShell ? 'voice' : 'home'" - :mount-revision="accessMode" - :context="skinPluginContext" - :actions="skinPluginActions" - :widgets="skinPluginWidgets" + :mount-revision="accessMode" + :context="skinPluginContext" + :actions="skinPluginActions" + :server-add-label="t('addFavoriteServer')" + :on-add-server="openFavoriteServerDialog" + :widgets="skinPluginWidgets" :read-session-status="readSkinRuntimeSessionStatus" @surface-change="skinRuntimePluginSurfaceActive = $event" @restore-skin="switchToBuiltIn" @@ -334,13 +338,12 @@ v-else-if="showVoiceShell && !skinPluginSurfaceActive && !skinRuntimePluginSurfaceActive" :class="['app-shell', `mobile-view-${mobileSection}`]" :data-performance-open="performancePanelOpen ? 'true' : 'false'" - :data-favorite-rail="accessMode === 'open' ? 'true' : 'false'" + :data-favorite-rail="'true'" data-ws-part="voice.shell" @click="memberMenu = null" > @@ -1451,9 +1456,13 @@ const favoriteSwitchLabel = computed(() => quickServers.value.find((server) => server.id === currentServerTarget().toLocaleLowerCase(), )?.label ?? currentServerTarget()); -function isQuickServerTarget(server: QuickServer): boolean { - return server.id === currentServerTarget().toLocaleLowerCase(); -} +function isQuickServerTarget(server: QuickServer): boolean { + return server.id === currentServerTarget().toLocaleLowerCase(); +} + +function serverCanSwitch(_server: QuickServer): boolean { + return accessMode.value === "open"; +} const quickServersForDisplay = computed(() => quickServers.value.map((server) => { const liveInfo = isQuickServerTarget(server) ? voiceServerInfo.value : null; @@ -1469,8 +1478,12 @@ const quickServersForDisplay = computed(() => quickServers.value.map((server) => }; })); -function connectQuickServer(server: QuickServer): void { - if (accessMode.value !== "open" || voiceState.connecting || (voiceState.connected && isQuickServerTarget(server))) return; +function connectQuickServer(server: QuickServer): void { + if (voiceState.connecting || (voiceState.connected && isQuickServerTarget(server))) return; + if (accessMode.value !== "open") { + showToast(t("serverSwitchRestricted")); + return; + } const target = splitTeamSpeakTarget(server.address); serverHost.value = target.address; serverPort.value = target.port || DEFAULT_TEAM_SPEAK_PORT; @@ -1513,9 +1526,18 @@ function leaveVoiceWorkspace(): void { doDisconnect(); } -function toggleQuickFavorite(server: QuickServer): void { - void toggleQuickServerFavorite(server); -} +function toggleQuickFavorite(server: QuickServer): void { + void toggleQuickServerFavorite(server); +} + +function openFavoriteServerDialog(): void { + if (accessMode.value !== "open") { + showToast(t("serverFeatureAdminDisabled")); + return; + } + if (!showVoiceShell.value || voiceState.connecting || favoriteDialogBusy.value) return; + favoriteServerDialogOpen.value = true; +} async function submitFavoriteServerDraft(draft: FavoriteServerDraft): Promise { if (favoriteDialogBusy.value || voiceState.connecting || accessMode.value !== "open") return; @@ -1552,7 +1574,12 @@ async function submitFavoriteServerDraft(draft: FavoriteServerDraft): Promise pokeNotifications.slice(-3)); const skinPluginQuickServers = createSkinPluginQuickServerProjection(); -const skinPluginQuickList = computed(() => skinPluginQuickServers.project(quickServersForDisplay.value, isQuickServerTarget)); +const skinPluginQuickList = computed(() => skinPluginQuickServers.project( + quickServersForDisplay.value, + isQuickServerTarget, + accessMode.value !== "open", + t("serverSwitchRestricted"), +)); const currentServerDisplayName = computed(() => { const target = currentServerTarget(); const liveName = safeSkinServerDisplayName(voiceServerInfo.value?.name ?? "", target); @@ -1657,7 +1684,10 @@ const readSkinRuntimeSessionStatus = (_signal: AbortSignal) => ({ }); function switchQuickServerByOpaqueId(quickServerId: string): void { - if (accessMode.value !== "open") return; + if (accessMode.value !== "open") { + showToast(t("serverSwitchRestricted")); + return; + } const target = skinPluginQuickServers.resolve(quickServerId); if (target && quickServers.value.some((server) => server.id === target.id)) connectQuickServer(target); }