mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
Add server navigation controls across modes
This commit is contained in:
1 parent
c6eeb49f44
commit
319a16f384
18 files changed
+372
-63
No files matched your search
@@ -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.",
|
||||
|
||||
@@ -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<string, unknown>; text: string; children: HostNode[]; parent?: HostNode };
|
||||
const createHostNode = (type: string, text = ""): HostNode => ({ type, props: {}, text, children: [] });
|
||||
const renderer = createRenderer<HostNode, HostNode>({
|
||||
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,
|
||||
|
||||
@@ -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;/);
|
||||
|
||||
@@ -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<string, QuickServer>();
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
@@ -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服务器");
|
||||
});
|
||||
Reference in new issue
Block a user