mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
feat(skin): add approved full-page surface composition
This commit is contained in:
1 parent
eabc78f36a
commit
d505815f28
19 files changed
+1261
-99
No files matched your search
@@ -5,6 +5,7 @@ import {
|
||||
type SkinPluginActionDefinition,
|
||||
type SkinPluginComponent,
|
||||
type SkinPluginDocument,
|
||||
type SkinPluginHostWidget,
|
||||
type SkinPluginNode,
|
||||
} from "../../../src/shared/skin-plugin.js";
|
||||
import { approveSkinPluginComponents, getMissingSkinPluginApprovals, isSkinPluginComponentApproved, revokeSkinPluginApprovals } from "../services/skin-plugin-approval.js";
|
||||
@@ -12,6 +13,7 @@ import { approveSkinPluginComponents, getMissingSkinPluginApprovals, isSkinPlugi
|
||||
type Scalar = string | number | boolean;
|
||||
type SafeContext = Record<string, unknown>;
|
||||
type HostAction = (args: Record<string, Scalar>, component: SkinPluginComponent) => void | Promise<void>;
|
||||
type HostWidget = () => VNodeChild;
|
||||
|
||||
const eventProps: Record<string, string> = {
|
||||
click: "onClick", dblclick: "onDblclick", change: "onChange", input: "onInput", submit: "onSubmit", keydown: "onKeydown",
|
||||
@@ -27,16 +29,22 @@ export default defineComponent({
|
||||
data: { type: Object as PropType<SafeContext>, required: true },
|
||||
assets: { type: Object as PropType<Record<string, Blob>>, required: true },
|
||||
actions: { type: Object as PropType<Record<string, HostAction>>, required: true },
|
||||
widgets: { type: Object as PropType<Partial<Record<SkinPluginHostWidget, HostWidget>>>, default: () => ({}) },
|
||||
},
|
||||
setup(props) {
|
||||
emits: {
|
||||
"surface-change": (_active: boolean) => typeof _active === "boolean",
|
||||
"restore-skin": () => true,
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
const denied = ref(false);
|
||||
const surfaceSuppressed = ref(false);
|
||||
const manageOpen = ref(false);
|
||||
const refresh = ref(0);
|
||||
const stateByComponent = reactive<Record<string, Record<string, Scalar>>>({});
|
||||
const objectUrls = new Map<string, string>();
|
||||
const validatedDocument = computed(() => {
|
||||
try { return parseSkinPluginDocument(props.document); }
|
||||
catch { return { schemaVersion: 1 as const, components: [] }; }
|
||||
catch { return { schemaVersion: 2 as const, components: [] }; }
|
||||
});
|
||||
const matchingComponents = computed(() => validatedDocument.value.components.filter((component) => component.page === props.page));
|
||||
const pendingApproval = computed(() => {
|
||||
@@ -50,8 +58,17 @@ export default defineComponent({
|
||||
refresh.value;
|
||||
return matchingComponents.value.filter((component) => isSkinPluginComponentApproved(props.skinId, props.skinVersion, component));
|
||||
});
|
||||
const surfaceCandidate = computed(() => activeComponents.value.find((component) => component.mode === "surface") ?? null);
|
||||
const activeSurface = computed(() => surfaceSuppressed.value ? null : surfaceCandidate.value);
|
||||
const renderedComponents = computed(() => activeComponents.value.filter((component) =>
|
||||
component.mode !== "surface" || component !== surfaceCandidate.value || !surfaceSuppressed.value));
|
||||
|
||||
watch(() => [props.skinId, props.skinVersion, props.document, props.page], () => { denied.value = false; refresh.value += 1; }, { immediate: true });
|
||||
watch(() => [props.skinId, props.skinVersion, props.document, props.page], () => {
|
||||
denied.value = false;
|
||||
surfaceSuppressed.value = false;
|
||||
refresh.value += 1;
|
||||
}, { immediate: true });
|
||||
watch(activeSurface, (surface) => emit("surface-change", Boolean(surface)), { immediate: true, flush: "sync" });
|
||||
|
||||
function localState(component: SkinPluginComponent): Record<string, Scalar> {
|
||||
const key = `${props.skinId}/${component.id}`;
|
||||
@@ -114,6 +131,20 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function renderNode(component: SkinPluginComponent, node: SkinPluginNode, context: SafeContext, state: Record<string, Scalar>, skipRepeat = false): VNodeChild {
|
||||
if (node.widget) {
|
||||
if (node.when) {
|
||||
const value = resolvePath(node.when.path, context, state);
|
||||
if (node.when.equals !== undefined ? value !== node.when.equals : !value) return null;
|
||||
}
|
||||
const widget = props.widgets[node.widget];
|
||||
if (!widget) return null;
|
||||
return h("div", {
|
||||
class: ["ws-plugin-host-widget", node.className],
|
||||
"data-ws-plugin-widget": node.widget,
|
||||
"data-ws-plugin-part": node.part ? `${component.id}.${node.part}` : component.id,
|
||||
"aria-label": component.accessibleName,
|
||||
}, [widget()]);
|
||||
}
|
||||
if (!node.tag) return interpolate(node.text ?? "", context, state);
|
||||
if (!skipRepeat && node.repeat) {
|
||||
const values = resolvePath(node.repeat.path, context, state);
|
||||
@@ -194,12 +225,13 @@ export default defineComponent({
|
||||
onUnmounted(() => { objectUrls.forEach((url) => URL.revokeObjectURL(url)); objectUrls.clear(); });
|
||||
|
||||
return () => {
|
||||
const nodes: VNodeChild[] = activeComponents.value.map((component) => h("div", {
|
||||
const nodes: VNodeChild[] = renderedComponents.value.map((component) => h("div", {
|
||||
key: `${props.skinId}:${component.id}`,
|
||||
class: "ws-plugin-component",
|
||||
class: ["ws-plugin-component", component.mode === "surface" && "ws-plugin-surface"],
|
||||
"data-ws-plugin-component": component.id,
|
||||
"data-ws-plugin-name": component.name,
|
||||
"data-ws-plugin-part": component.id,
|
||||
...(component.mode === "surface" ? { "data-ws-plugin-surface": component.page } : {}),
|
||||
"aria-label": component.accessibleName,
|
||||
}, [renderNode(component, component.root, props.data, localState(component))]));
|
||||
const hasPermissions = matchingComponents.value.some((component) => component.permissions.length > 0);
|
||||
@@ -210,7 +242,23 @@ export default defineComponent({
|
||||
"aria-label": "管理皮肤组件权限 / Manage skin component access",
|
||||
onClick: openAccessManager,
|
||||
}, "权限 / Access")]) : null;
|
||||
if (!showConsent) return h(Fragment, null, [...nodes, ...(accessToggle ? [accessToggle] : [])]);
|
||||
const surfaceRecovery = activeSurface.value ? h(Teleport, { to: "body" }, [h("button", {
|
||||
type: "button",
|
||||
class: "ws-plugin-surface-recovery",
|
||||
"aria-label": "返回 WebSpeak 标准界面 / Return to the built-in interface",
|
||||
onClick: () => { surfaceSuppressed.value = true; },
|
||||
}, "标准界面 / Built-in UI")]) : null;
|
||||
const skinRecovery = activeSurface.value ? h(Teleport, { to: "body" }, [h("button", {
|
||||
type: "button",
|
||||
class: "ws-plugin-surface-reset",
|
||||
"aria-label": "恢复内置皮肤 / Restore the built-in skin",
|
||||
onClick: () => emit("restore-skin"),
|
||||
}, "恢复内置皮肤 / Reset skin")]) : null;
|
||||
const recoveryControls = [
|
||||
...(surfaceRecovery ? [surfaceRecovery] : []),
|
||||
...(skinRecovery ? [skinRecovery] : []),
|
||||
];
|
||||
if (!showConsent) return h(Fragment, null, [...nodes, ...(accessToggle ? [accessToggle] : []), ...recoveryControls]);
|
||||
|
||||
const requested = accessComponents.value;
|
||||
const hasMissing = pendingApproval.value.length > 0;
|
||||
@@ -222,7 +270,7 @@ export default defineComponent({
|
||||
h("strong", null, component.name),
|
||||
h("ul", null, component.permissions.map((permission) => h("li", { key: permission }, permissionLabel(permission)))),
|
||||
])),
|
||||
h("p", { class: "ws-plugin-consent-note" }, "组件不能运行脚本、访问浏览器存储、读取连接地址/密码或控制麦克风。/ Components cannot run code, access storage or credentials, or control the microphone."),
|
||||
h("p", { class: "ws-plugin-consent-note" }, "页面可以替换公开客户端外观;内置控件仍由 WebSpeak 处理。皮肤不能运行脚本、访问网络或存储,也不能读取连接地址、密码和身份材料。/ A surface can replace the public client UI while built-in controls remain host-owned. Skins cannot run code, access network or storage, or read connection targets, passwords, or identity material."),
|
||||
h("div", { class: "ws-plugin-consent-actions" }, [
|
||||
...(hasMissing ? [h("button", { type: "button", class: "secondary", onClick: closeOrDisable }, "暂不启用 / Keep disabled")]
|
||||
: [h("button", { type: "button", class: "secondary", onClick: revokeAll }, "撤销全部授权 / Revoke all access")]),
|
||||
@@ -230,7 +278,7 @@ export default defineComponent({
|
||||
]),
|
||||
]),
|
||||
])]);
|
||||
return h(Fragment, null, [...nodes, ...(accessToggle ? [accessToggle] : []), consent]);
|
||||
return h(Fragment, null, [...nodes, ...(accessToggle ? [accessToggle] : []), ...recoveryControls, consent]);
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -115,6 +115,9 @@ export function usePublicSkin(options: PublicSkinOptions = {}) {
|
||||
if (!skinLoadError.value) return;
|
||||
await select(fallbackId());
|
||||
}
|
||||
async function switchToBuiltIn(): Promise<void> {
|
||||
await select(fallbackId());
|
||||
}
|
||||
|
||||
return { activeSkin, activeSkinId, skinReady, skinLoadError, installedSkins, catalogSkins, initialize, select, cancel, reset, switchToBuiltInAfterLoadError };
|
||||
return { activeSkin, activeSkinId, skinReady, skinLoadError, installedSkins, catalogSkins, initialize, select, cancel, reset, switchToBuiltIn, switchToBuiltInAfterLoadError };
|
||||
}
|
||||
@@ -331,6 +331,37 @@ test("schema version 3 supports arbitrary public layouts and validated declarati
|
||||
await assert.rejects(importSkinPack(makeSkinV3(missingAsset, "[data-ws-part=app] { color: red; }")), (error: unknown) => error instanceof SkinPackError && error.code === "SKIN_PLUGIN_ASSET_INVALID");
|
||||
});
|
||||
|
||||
test("schema version 3 accepts a schema v2 full-page surface with host widgets", async () => {
|
||||
const components = {
|
||||
schemaVersion: 2,
|
||||
components: [{
|
||||
id: "custom-voice-surface",
|
||||
name: "Custom voice surface",
|
||||
page: "voice",
|
||||
mode: "surface",
|
||||
accessibleName: "Custom voice workspace",
|
||||
permissions: ["ui.surface.replace"],
|
||||
actions: {},
|
||||
root: {
|
||||
tag: "main",
|
||||
className: "custom-workspace",
|
||||
children: [
|
||||
{ widget: "voice.channel-panel" },
|
||||
{ widget: "voice.member-cards" },
|
||||
{ widget: "voice.chat-panel" },
|
||||
{ widget: "voice.audio-controls" },
|
||||
],
|
||||
},
|
||||
}],
|
||||
};
|
||||
const skin = await importSkinPack(makeSkinV3(components, '[data-ws-part="app"] { --skin-surface: #123456; }'));
|
||||
assert.equal(skin.pluginData?.schemaVersion, 2);
|
||||
assert.equal(skin.pluginData?.components[0].mode, "surface");
|
||||
assert.deepEqual(skin.pluginData?.components[0].root.children?.map((node) => node.widget), [
|
||||
"voice.channel-panel", "voice.member-cards", "voice.chat-panel", "voice.audio-controls",
|
||||
]);
|
||||
});
|
||||
|
||||
test("the distributable KAAK v3 package validates end to end", async () => {
|
||||
const archive = await readFile(new URL("../../../docs/examples/kaak-voice.wskin", import.meta.url));
|
||||
const file = new File([archive], "kaak-voice.wskin", { type: "application/octet-stream" });
|
||||
@@ -341,6 +372,24 @@ test("the distributable KAAK v3 package validates end to end", async () => {
|
||||
assert.ok(skin.css.includes('data-ws-plugin-part="kaak-room-sidebar.channel-row"'));
|
||||
});
|
||||
|
||||
test("the full voice surface example packages home, voice, and host-owned controls", async () => {
|
||||
const archive = await readFile(new URL("../../../docs/examples/open-voice-surface.wskin", import.meta.url));
|
||||
const file = new File([archive], "open-voice-surface.wskin", { type: "application/octet-stream" });
|
||||
const skin = await importSkinPack(file);
|
||||
assert.equal(skin.id, "community.open-voice-surface");
|
||||
assert.equal(skin.pluginData?.schemaVersion, 2);
|
||||
assert.deepEqual(skin.pluginData?.components.map((component) => [component.page, component.mode]), [
|
||||
["home", "surface"], ["voice", "surface"],
|
||||
]);
|
||||
const voiceSurface = skin.pluginData?.components.find((component) => component.page === "voice");
|
||||
assert.ok(voiceSurface?.permissions.includes("ui.surface.replace"));
|
||||
assert.ok(voiceSurface?.permissions.includes("servers.quickList.read"));
|
||||
assert.ok(voiceSurface?.permissions.includes("servers.quickList.switch"));
|
||||
assert.ok(voiceSurface?.permissions.includes("session.channels.read"));
|
||||
assert.ok(voiceSurface?.permissions.includes("session.members.read"));
|
||||
assert.ok(skin.css.includes("@media (max-width: 800px)"));
|
||||
});
|
||||
|
||||
function makeSkinV2(layout: unknown, manifestChanges: Record<string, unknown> = {}): File {
|
||||
const packageFiles: Record<string, Uint8Array> = {
|
||||
"manifest.json": strToU8(JSON.stringify({
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import type { QuickServer } from "./quick-servers.js";
|
||||
import { splitTeamSpeakTarget } from "./teamspeak-target.js";
|
||||
|
||||
export interface SkinPluginQuickServer {
|
||||
id: string;
|
||||
label: string;
|
||||
current: boolean;
|
||||
kind: "favorite" | "recent";
|
||||
favorite: boolean;
|
||||
}
|
||||
|
||||
function randomOpaqueId(): string {
|
||||
return globalThis.crypto?.randomUUID?.() ?? `quick-server-${Math.random().toString(36).slice(2)}`;
|
||||
}
|
||||
|
||||
function containsConnectionTarget(label: string, address: string): boolean {
|
||||
const candidates = new Set([address.trim()]);
|
||||
try { candidates.add(splitTeamSpeakTarget(address).address.trim()); } catch { /* Persisted targets are validated on write. */ }
|
||||
const normalizedLabel = label.toLocaleLowerCase();
|
||||
return [...candidates].some((candidate) => candidate.length >= 3 && normalizedLabel.includes(candidate.toLocaleLowerCase()));
|
||||
}
|
||||
|
||||
/** Projects local favorite/recent entries without exposing their connection targets. */
|
||||
export function createSkinPluginQuickServerProjection(createId: () => string = randomOpaqueId) {
|
||||
const opaqueIdByServerId = new Map<string, string>();
|
||||
const targetByOpaqueId = new Map<string, QuickServer>();
|
||||
|
||||
return {
|
||||
project(servers: readonly QuickServer[], isCurrent: (server: QuickServer) => boolean): 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();
|
||||
|
||||
return servers.map((server, index) => {
|
||||
let opaqueId = opaqueIdByServerId.get(server.id);
|
||||
if (!opaqueId) {
|
||||
opaqueId = createId();
|
||||
opaqueIdByServerId.set(server.id, opaqueId);
|
||||
}
|
||||
targetByOpaqueId.set(opaqueId, server);
|
||||
const label = server.label.trim();
|
||||
const safeLabel = !label || containsConnectionTarget(label, server.address)
|
||||
? `${server.isFavorite ? "Favorite" : "Recent"} ${index + 1}`
|
||||
: label;
|
||||
return {
|
||||
id: opaqueId,
|
||||
label: safeLabel,
|
||||
current: isCurrent(server),
|
||||
kind: server.isFavorite ? "favorite" : "recent",
|
||||
favorite: server.isFavorite,
|
||||
};
|
||||
});
|
||||
},
|
||||
resolve(opaqueId: string): QuickServer | undefined {
|
||||
return targetByOpaqueId.get(opaqueId);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { parseSkinPluginDocument, type SkinPluginDocument } from "../../../src/shared/skin-plugin.js";
|
||||
import {
|
||||
approveSkinPluginComponents,
|
||||
getMissingSkinPluginApprovals,
|
||||
isSkinPluginComponentApproved,
|
||||
revokeSkinPluginApprovals,
|
||||
} from "./skin-plugin-approval.js";
|
||||
import { createSkinPluginQuickServerProjection } from "./skin-plugin-context.js";
|
||||
|
||||
function surfaceDocument(): SkinPluginDocument {
|
||||
return {
|
||||
schemaVersion: 2,
|
||||
components: [{
|
||||
id: "custom-surface",
|
||||
name: "Custom surface",
|
||||
page: "voice",
|
||||
mode: "surface",
|
||||
accessibleName: "Custom voice page",
|
||||
permissions: ["ui.surface.replace"],
|
||||
actions: {},
|
||||
root: { tag: "main", children: [{ tag: "h1", children: [{ text: "Custom client" }] }] },
|
||||
}],
|
||||
};
|
||||
}
|
||||
|
||||
test("page replacement stays disabled until local approval and returns to the host after revocation", () => {
|
||||
const storage = new Map<string, string>();
|
||||
const previousStorage = Object.getOwnPropertyDescriptor(globalThis, "localStorage");
|
||||
Object.defineProperty(globalThis, "localStorage", {
|
||||
configurable: true,
|
||||
value: {
|
||||
getItem: (key: string) => storage.get(key) ?? null,
|
||||
setItem: (key: string, value: string) => { storage.set(key, value); },
|
||||
},
|
||||
});
|
||||
try {
|
||||
const document = parseSkinPluginDocument(surfaceDocument());
|
||||
const component = document.components[0];
|
||||
|
||||
assert.deepEqual(getMissingSkinPluginApprovals("test.skin", "1.0.0", document), [component]);
|
||||
assert.equal(isSkinPluginComponentApproved("test.skin", "1.0.0", component), false);
|
||||
approveSkinPluginComponents("test.skin", "1.0.0", [component]);
|
||||
assert.deepEqual(getMissingSkinPluginApprovals("test.skin", "1.0.0", document), []);
|
||||
assert.equal(isSkinPluginComponentApproved("test.skin", "1.0.0", component), true);
|
||||
revokeSkinPluginApprovals("test.skin");
|
||||
assert.equal(isSkinPluginComponentApproved("test.skin", "1.0.0", component), false);
|
||||
} finally {
|
||||
if (previousStorage) Object.defineProperty(globalThis, "localStorage", previousStorage);
|
||||
else Reflect.deleteProperty(globalThis, "localStorage");
|
||||
}
|
||||
});
|
||||
|
||||
test("skin quick-server data redacts connection targets and resolves only host-generated opaque IDs", () => {
|
||||
const servers = [
|
||||
{ id: "192.0.2.10:9987", address: "192.0.2.10:9987", label: "192.0.2.10:9987", isFavorite: true },
|
||||
{ id: "voice.example:9987", address: "voice.example:9987", label: "Friends (voice.example:9987)", isFavorite: false },
|
||||
{ id: "voice2.example:9987", address: "voice2.example:9987", label: "Friends", isFavorite: true },
|
||||
];
|
||||
let sequence = 0;
|
||||
const projection = createSkinPluginQuickServerProjection(() => `opaque-${++sequence}`);
|
||||
const rows = projection.project(servers, (server) => server.id === "voice2.example:9987");
|
||||
|
||||
assert.deepEqual(rows.map(({ label, kind, favorite, current }) => [label, kind, favorite, current]), [
|
||||
["Favorite 1", "favorite", true, false],
|
||||
["Recent 2", "recent", false, false],
|
||||
["Friends", "favorite", true, true],
|
||||
]);
|
||||
assert.equal(JSON.stringify(rows).includes("192.0.2.10"), false);
|
||||
assert.equal(JSON.stringify(rows).includes("voice.example"), false);
|
||||
assert.equal(projection.resolve("opaque-1")?.address, "192.0.2.10:9987");
|
||||
assert.equal(projection.resolve("192.0.2.10:9987"), undefined);
|
||||
});
|
||||
@@ -15,7 +15,7 @@
|
||||
position: fixed;
|
||||
right: 12px;
|
||||
bottom: 12px;
|
||||
z-index: 2147483000;
|
||||
z-index: 2147483647;
|
||||
min-height: 34px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid #8197ac;
|
||||
@@ -28,6 +28,37 @@
|
||||
}
|
||||
.ws-plugin-access-toggle:focus-visible { outline: 3px solid #fbbf24; outline-offset: 3px; }
|
||||
|
||||
.ws-plugin-surface {
|
||||
display: block;
|
||||
width: 100%;
|
||||
min-height: var(--ws-viewport-height, 100vh);
|
||||
}
|
||||
|
||||
.ws-plugin-host-widget {
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.ws-plugin-surface-recovery,
|
||||
.ws-plugin-surface-reset {
|
||||
position: fixed;
|
||||
left: 12px;
|
||||
z-index: 2147483647;
|
||||
min-height: 34px;
|
||||
padding: 0 12px;
|
||||
border: 1px solid #8197ac;
|
||||
border-radius: 999px;
|
||||
color: #f7fbff;
|
||||
background: #182331ef;
|
||||
box-shadow: 0 4px 18px #0006;
|
||||
font: 12px/1.2 Inter, ui-sans-serif, system-ui, sans-serif;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ws-plugin-surface-recovery { bottom: 12px; }
|
||||
.ws-plugin-surface-reset { bottom: 54px; }
|
||||
.ws-plugin-surface-recovery:focus-visible,
|
||||
.ws-plugin-surface-reset:focus-visible { outline: 3px solid #fbbf24; outline-offset: 3px; }
|
||||
|
||||
.ws-plugin-consent {
|
||||
width: min(640px, 100%);
|
||||
max-height: min(86vh, 800px);
|
||||
|
||||
+196
-42
@@ -20,10 +20,13 @@
|
||||
:data="skinPluginContext"
|
||||
:assets="activeSkin.assets"
|
||||
:actions="skinPluginActions"
|
||||
:widgets="skinPluginWidgets"
|
||||
@surface-change="skinPluginSurfaceActive = $event"
|
||||
@restore-skin="switchToBuiltIn"
|
||||
/>
|
||||
<!-- Connection / welcome screen -->
|
||||
<section
|
||||
v-if="!showVoiceShell"
|
||||
v-if="!showVoiceShell && !skinPluginSurfaceActive"
|
||||
class="join-page"
|
||||
data-ws-part="home"
|
||||
>
|
||||
@@ -236,18 +239,6 @@
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<IdentityImportDialog
|
||||
v-if="identityImportOpen"
|
||||
v-model="identityImportText"
|
||||
:busy="identityImportBusy"
|
||||
:reading="identityFileReading"
|
||||
:error="identityImportError"
|
||||
:t="t"
|
||||
@close="closeIdentityImport"
|
||||
@submit="importIdentity"
|
||||
@file="readIdentityFile"
|
||||
/>
|
||||
|
||||
<footer
|
||||
class="join-footer"
|
||||
data-ws-part="home.footer"
|
||||
@@ -310,7 +301,7 @@
|
||||
|
||||
<!-- Connected application shell -->
|
||||
<div
|
||||
v-else
|
||||
v-else-if="showVoiceShell && !skinPluginSurfaceActive"
|
||||
:class="['app-shell', `mobile-view-${mobileSection}`]"
|
||||
:data-performance-open="performancePanelOpen ? 'true' : 'false'"
|
||||
:data-favorite-rail="accessMode === 'open' ? 'true' : 'false'"
|
||||
@@ -540,13 +531,6 @@
|
||||
<button v-if="favoriteSwitchFailed" type="button" @click="leaveVoiceWorkspace">{{ t('back') }}</button>
|
||||
</div>
|
||||
|
||||
<ScreenShareSettingsDialog
|
||||
v-if="screenShareSettingsOpen"
|
||||
:model="screenShareControls"
|
||||
:t="t"
|
||||
@close="screenShareSettingsOpen = false"
|
||||
/>
|
||||
|
||||
<div
|
||||
v-if="voiceState.reconnecting || voiceState.reconnectFailed"
|
||||
:class="['reconnect-banner', { failed: voiceState.reconnectFailed }]"
|
||||
@@ -853,6 +837,25 @@
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<IdentityImportDialog
|
||||
v-if="identityImportOpen"
|
||||
v-model="identityImportText"
|
||||
:busy="identityImportBusy"
|
||||
:reading="identityFileReading"
|
||||
:error="identityImportError"
|
||||
:t="t"
|
||||
@close="closeIdentityImport"
|
||||
@submit="importIdentity"
|
||||
@file="readIdentityFile"
|
||||
/>
|
||||
|
||||
<ScreenShareSettingsDialog
|
||||
v-if="screenShareSettingsOpen"
|
||||
:model="screenShareControls"
|
||||
:t="t"
|
||||
@close="screenShareSettingsOpen = false"
|
||||
/>
|
||||
|
||||
<MemberActionsMenu
|
||||
:model="memberControls"
|
||||
:is-mobile-viewport="isMobileViewport"
|
||||
@@ -924,7 +927,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { observeMobileViewport } from "../services/mobile-viewport.js";
|
||||
import { computed, onMounted, onUnmounted, reactive, ref, shallowRef, watch } from "vue";
|
||||
import { computed, h, onMounted, onUnmounted, reactive, ref, shallowRef, watch } from "vue";
|
||||
import Icon from "../components/Icon.vue";
|
||||
import SkinPluginOutlet from "../components/SkinPluginOutlet.js";
|
||||
import SkinLoadRecoveryNotice from "../components/SkinLoadRecoveryNotice.vue";
|
||||
@@ -968,6 +971,7 @@ import { BUILTIN_DARK_SKIN, BUILTIN_LIGHT_SKIN } from "../services/skin-runtime.
|
||||
import { applyTheme, getStoredTheme, type ThemeMode } from "../services/theme.js";
|
||||
import { createScreenWakeLockController, getScreenWakeLockApi, type ScreenWakeLockController, type ScreenWakeLockSnapshot } from "../services/screen-wake-lock.js";
|
||||
import { createMobileAwayController, type MobileAwayController } from "../services/mobile-away.js";
|
||||
import { createSkinPluginQuickServerProjection } from "../services/skin-plugin-context.js";
|
||||
import { combineTeamSpeakTarget, DEFAULT_TEAM_SPEAK_PORT, isValidTeamSpeakPort, splitTeamSpeakTarget } from "../services/teamspeak-target.js";
|
||||
|
||||
const {
|
||||
@@ -1092,6 +1096,8 @@ let toastTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
const language = ref<Language>(getInitialLanguage());
|
||||
const activeSkin = shallowRef<InstalledSkin | null>(null);
|
||||
const skinPluginSurfaceActive = ref(false);
|
||||
watch(activeSkin, () => { skinPluginSurfaceActive.value = false; }, { flush: "sync" });
|
||||
const skinMessageOverrides = computed(() => resolveSkinMessages(activeSkin.value, language.value));
|
||||
const { t: translate, localizedMessage, localizedAudioNotice, visibleErrorCode } = useWebClientI18n(language);
|
||||
function t(key: string, variables: Record<string, string | number> = {}) {
|
||||
@@ -1136,7 +1142,7 @@ const themeMode = ref<ThemeMode>(getStoredTheme());
|
||||
applyTheme(themeMode.value);
|
||||
const publicSkin = usePublicSkin({ activeSkin, themeMode, appVersion: () => appVersion.value });
|
||||
const { activeSkinId, skinReady, skinLoadError, installedSkins, catalogSkins,
|
||||
select: onSkinChange, initialize: initializeSkin, switchToBuiltInAfterLoadError } = publicSkin;
|
||||
select: onSkinChange, initialize: initializeSkin, switchToBuiltIn, switchToBuiltInAfterLoadError } = publicSkin;
|
||||
const skinOptions = computed<SkinOption[]>(() => [
|
||||
...catalogSkins.value.map((skin) => ({
|
||||
value: skin.id,
|
||||
@@ -1457,23 +1463,11 @@ async function submitFavoriteServerDraft(draft: FavoriteServerDraft): Promise<vo
|
||||
|
||||
const visiblePokes = computed(() => pokeNotifications.slice(-3));
|
||||
|
||||
const opaqueFavoriteTokenById = new Map<string, string>();
|
||||
const skinPluginFavoriteTargets = new Map<string, QuickServer>();
|
||||
const skinPluginFavorites = computed(() => {
|
||||
const targets = quickServers.value.filter((server) => server.isFavorite);
|
||||
const activeIds = new Set(targets.map((server) => server.id));
|
||||
for (const id of opaqueFavoriteTokenById.keys()) if (!activeIds.has(id)) opaqueFavoriteTokenById.delete(id);
|
||||
skinPluginFavoriteTargets.clear();
|
||||
return targets.map((server) => {
|
||||
let token = opaqueFavoriteTokenById.get(server.id);
|
||||
if (!token) {
|
||||
token = globalThis.crypto?.randomUUID?.() ?? `favorite-${Math.random().toString(36).slice(2)}`;
|
||||
opaqueFavoriteTokenById.set(server.id, token);
|
||||
}
|
||||
skinPluginFavoriteTargets.set(token, server);
|
||||
return { id: token, label: server.label, current: isQuickServerTarget(server), kind: "favorite" };
|
||||
});
|
||||
});
|
||||
const skinPluginQuickServers = createSkinPluginQuickServerProjection();
|
||||
const skinPluginQuickList = computed(() => skinPluginQuickServers.project(quickServers.value, isQuickServerTarget));
|
||||
const skinPluginFavorites = computed(() => skinPluginQuickList.value
|
||||
.filter((server) => server.favorite)
|
||||
.map(({ favorite: _favorite, ...server }) => server));
|
||||
|
||||
const skinPluginContext = computed(() => ({
|
||||
session: {
|
||||
@@ -1502,6 +1496,7 @@ const skinPluginContext = computed(() => ({
|
||||
}))),
|
||||
},
|
||||
favorites: { items: skinPluginFavorites.value },
|
||||
servers: { quickList: skinPluginQuickList.value },
|
||||
chat: {
|
||||
messages: chat.visibleMessages.value.filter((message) => message.scope === "channel").map((message) => ({
|
||||
id: message.id,
|
||||
@@ -1522,8 +1517,13 @@ const skinPluginActions = {
|
||||
},
|
||||
"favorites.switch": (args: Record<string, string | number | boolean>) => {
|
||||
if (accessMode.value !== "open" || typeof args.favoriteId !== "string") return;
|
||||
const target = skinPluginFavoriteTargets.get(args.favoriteId);
|
||||
if (target?.isFavorite) connectQuickServer(target);
|
||||
const target = skinPluginQuickServers.resolve(args.favoriteId);
|
||||
if (target?.isFavorite && quickServers.value.some((server) => server.id === target.id && server.isFavorite)) connectQuickServer(target);
|
||||
},
|
||||
"quickServers.switch": (args: Record<string, string | number | boolean>) => {
|
||||
if (accessMode.value !== "open" || typeof args.quickServerId !== "string") return;
|
||||
const target = skinPluginQuickServers.resolve(args.quickServerId);
|
||||
if (target && quickServers.value.some((server) => server.id === target.id)) connectQuickServer(target);
|
||||
},
|
||||
"chat.sendMessage": (args: Record<string, string | number | boolean>) => {
|
||||
if (!voiceState.connected || typeof args.text !== "string" || !currentChannel.value?.id) return;
|
||||
@@ -1533,6 +1533,160 @@ const skinPluginActions = {
|
||||
},
|
||||
};
|
||||
|
||||
const skinPluginWidgets = {
|
||||
"home.connection-form": () => h(JoinForm, {
|
||||
autofocusNickname: !isMobileViewport.value,
|
||||
serverHost: serverHost.value,
|
||||
"onUpdate:serverHost": (value: string) => { serverHost.value = value; },
|
||||
serverPort: serverPort.value,
|
||||
"onUpdate:serverPort": (value: string) => { serverPort.value = value; },
|
||||
serverPassword: serverPassword.value,
|
||||
"onUpdate:serverPassword": (value: string) => { serverPassword.value = value; },
|
||||
nickname: nickname.value,
|
||||
"onUpdate:nickname": (value: string) => { nickname.value = value; },
|
||||
channel: channel.value,
|
||||
"onUpdate:channel": (value: string) => { channel.value = value; },
|
||||
rememberIdentity: rememberIdentity.value,
|
||||
"onUpdate:rememberIdentity": (value: boolean) => { rememberIdentity.value = value; },
|
||||
accelerationRelayId: accelerationRelayId.value,
|
||||
"onUpdate:accelerationRelayId": (value: string) => { accelerationRelayId.value = value; },
|
||||
accessMode: accessMode.value,
|
||||
openTargetPrefillBlocked: openTargetPrefillBlocked.value,
|
||||
accelerationRelays: accelerationRelays.value,
|
||||
quickServers: quickServers.value,
|
||||
isFavorite: isFavorite.value,
|
||||
identityExportBusy: identityExportBusy.value,
|
||||
hasIdentity: Boolean(identityMaterial.value),
|
||||
connecting: voiceState.connecting,
|
||||
joinDisabled: !canJoin.value || serverConfigLoading.value || !identityReady.value || voiceState.connecting,
|
||||
t,
|
||||
onConnect: doConnect,
|
||||
onDisconnect: doDisconnect,
|
||||
onSelectServer: selectLocalServer,
|
||||
onToggleFavorite: toggleFavorite,
|
||||
onToggleQuickFavorite: toggleQuickFavorite,
|
||||
onImportIdentity: openIdentityImport,
|
||||
onExportIdentity: exportIdentity,
|
||||
}),
|
||||
"app.skin-switcher": () => h(SkinSwitcher, {
|
||||
modelValue: activeSkinId.value,
|
||||
"onUpdate:modelValue": (value: string) => { activeSkinId.value = value; },
|
||||
class: "skin-switcher",
|
||||
menuLabel: t("skinSelector"),
|
||||
options: skinOptions.value,
|
||||
onChange: onSkinChange,
|
||||
}),
|
||||
"app.language-switcher": () => h(LanguageSwitcher, {
|
||||
modelValue: language.value,
|
||||
"onUpdate:modelValue": (value: Language) => { language.value = value; },
|
||||
menuLabel: t("languageMenu"),
|
||||
onChange: persistLanguage,
|
||||
}),
|
||||
"voice.channel-panel": () => h(ChannelMemberPanel, {
|
||||
query: memberQuery.value,
|
||||
"onUpdate:query": (value: string) => { memberQuery.value = value; },
|
||||
model: memberControls,
|
||||
filteredMemberChannels: filteredMemberChannels.value,
|
||||
currentChannelId: currentChannel.value?.id,
|
||||
mobileVisible: true,
|
||||
isMobileViewport: isMobileViewport.value,
|
||||
volumes,
|
||||
avatarStyle,
|
||||
avatarInitial,
|
||||
rangeStyle,
|
||||
t,
|
||||
onSelectChannel: selectChannel,
|
||||
onVolumeInput: onVolInput,
|
||||
}),
|
||||
"voice.member-cards": () => h(VoiceMemberCards, {
|
||||
currentMembers: currentMembers.value,
|
||||
isMobileViewport: isMobileViewport.value,
|
||||
sharing: memberSharingState,
|
||||
controls: screenShareControls,
|
||||
isSpeaking,
|
||||
avatarStyle,
|
||||
avatarInitial,
|
||||
t,
|
||||
onMemberActions: openMemberActions,
|
||||
onStopShare: stopScreenShare,
|
||||
}),
|
||||
"voice.chat-panel": () => h(ChatPanel, {
|
||||
model: chat,
|
||||
t,
|
||||
currentChannelName: currentChannelName.value,
|
||||
mobileHidden: false,
|
||||
serverEvents,
|
||||
avatarStyle,
|
||||
avatarInitial,
|
||||
messageAvatar,
|
||||
formatTime,
|
||||
}),
|
||||
"voice.audio-controls": () => isMobileViewport.value
|
||||
? h("div", { class: "mobile-voice-controls", role: "toolbar", "aria-label": t("desktopAudioControls") }, [
|
||||
h("button", {
|
||||
type: "button",
|
||||
class: ["mobile-voice-toggle", microphoneMuted.value && "muted"],
|
||||
"aria-label": t("microphone"),
|
||||
"aria-pressed": !microphoneMuted.value,
|
||||
onClick: toggleMicrophone,
|
||||
}, [h(Icon, { name: microphoneMuted.value ? "mic-off" : "mic", size: 20 }), h("span", null, t("microphone"))]),
|
||||
h("button", {
|
||||
type: "button",
|
||||
class: ["mobile-voice-toggle", outputMuted.value && "muted"],
|
||||
"aria-label": t("speaker"),
|
||||
"aria-pressed": !outputMuted.value,
|
||||
onClick: toggleOutputMute,
|
||||
}, [h(Icon, { name: outputMuted.value ? "volume-off" : "volume", size: 20 }), h("span", null, t("speaker"))]),
|
||||
])
|
||||
: h(AudioDock, {
|
||||
model: audioDockState,
|
||||
controls: audioControls,
|
||||
t,
|
||||
rangeStyle,
|
||||
onSettings: () => { settingsOpen.value = true; },
|
||||
onOutputMute: toggleOutputMute,
|
||||
}),
|
||||
"voice.screen-share-player": () => screenShareViewing.value ? h(ScreenSharePlayer, {
|
||||
model: screenShareControls,
|
||||
screenShareRemoteStream: screenShareRemoteStream.value,
|
||||
screenShareRemoteVolume: screenShareRemoteVolume.value,
|
||||
screenShareError: screenShareError.value,
|
||||
leaveScreenShare,
|
||||
avatarInitial,
|
||||
t,
|
||||
}) : null,
|
||||
"voice.whisper-controls": () => whisperTargetIds.size ? h(WhisperControls, {
|
||||
targets: whisperTargets.value,
|
||||
active: whisperActive.value,
|
||||
enabled: !isMobileViewport.value || mobileSection.value === "voice",
|
||||
controls: audioControls,
|
||||
t,
|
||||
onClear: clearWhisperTargets,
|
||||
}) : null,
|
||||
"voice.performance-panel": () => h(VoicePerformancePanel, {
|
||||
model: performance,
|
||||
screenShareWebRtcStats,
|
||||
t,
|
||||
}),
|
||||
"voice.connection-controls": () => h("div", { class: "ws-plugin-connection-controls", role: "toolbar", "aria-label": t("desktopAudioControls") }, [
|
||||
h("button", { type: "button", "aria-label": t("copyInvite"), title: t("copyInvite"), onClick: doShare }, [h(Icon, { name: "share", size: 18 })]),
|
||||
...(accessMode.value === "open" ? [h("button", {
|
||||
type: "button",
|
||||
"aria-label": t(isFavorite.value ? "removeFavorite" : "saveFavorite"),
|
||||
"aria-pressed": isFavorite.value,
|
||||
title: t(isFavorite.value ? "removeFavorite" : "saveFavorite"),
|
||||
onClick: toggleFavorite,
|
||||
}, [h(Icon, { name: "star", size: 18 })])] : []),
|
||||
h("button", { type: "button", "aria-label": t("exit"), title: t("exit"), onClick: leaveVoiceWorkspace }, [h(Icon, { name: "door", size: 18 }), h("span", null, t("exit"))]),
|
||||
]),
|
||||
"voice.disconnect-control": () => h("button", {
|
||||
type: "button",
|
||||
class: "ws-plugin-disconnect-control",
|
||||
"aria-label": t("exit"),
|
||||
onClick: leaveVoiceWorkspace,
|
||||
}, [h(Icon, { name: "door", size: 18 }), h("span", null, t("exit"))]),
|
||||
};
|
||||
|
||||
watch(() => pokeNotifications.length, (length, previousLength) => {
|
||||
const latest = pokeNotifications[length - 1];
|
||||
if (!latest || length <= previousLength) return;
|
||||
|
||||
Reference in new issue
Block a user