mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat(skin): add v3 declarative plugin components
This commit is contained in:
1 parent
02441410a0
commit
eabc78f36a
30 files changed
+2483
-308
No files matched your search
@@ -1,5 +1,15 @@
|
||||
<template>
|
||||
<div :class="['demo-page', 'ws-skin-root', { 'skin-initializing': !skinReady }]" :lang="language" data-ws-part="app" data-ws-page="demo">
|
||||
<SkinPluginOutlet
|
||||
v-if="activeSkin?.pluginData"
|
||||
:skin-id="activeSkin.id"
|
||||
:skin-version="activeSkin.version"
|
||||
:document="activeSkin.pluginData"
|
||||
page="demo"
|
||||
:data="skinPluginContext"
|
||||
:assets="activeSkin.assets"
|
||||
:actions="skinPluginActions"
|
||||
/>
|
||||
<header class="demo-header" data-ws-part="demo.header">
|
||||
<div class="demo-brand" data-ws-part="demo.brand"><span><Icon name="waveform" :size="21" /></span><div><strong>WebSpeak</strong><small>{{ copy.browserClient }}</small></div></div>
|
||||
<div class="demo-tools" data-ws-part="demo.header-tools"><span class="demo-badge" data-ws-part="demo.badge">{{ copy.demoBadge }}</span><SkinSwitcher v-model="activeSkinId" data-ws-part="demo.skin-switcher" :menu-label="copy.skinSelector" :options="skinOptions" @change="onSkinChange" /><LanguageSwitcher v-model="language" data-ws-part="demo.language-switcher" :menu-label="copy.languageMenu" @change="persistLanguage" /><a href="/" data-ws-part="demo.home-link">{{ copy.back }}</a></div>
|
||||
@@ -53,6 +63,8 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import Icon from "../components/Icon.vue";
|
||||
import "../styles/skin-plugin.css";
|
||||
import SkinPluginOutlet from "../components/SkinPluginOutlet.js";
|
||||
import LanguageSwitcher from "../components/LanguageSwitcher.vue";
|
||||
import SkinLoadRecoveryNotice from "../components/SkinLoadRecoveryNotice.vue";
|
||||
import SkinSwitcher, { type SkinOption } from "../components/SkinSwitcher.vue";
|
||||
@@ -125,6 +137,35 @@ function toggleSpeaking() { speakingId.value = speakingId.value ? "" : selectedC
|
||||
function messageText(message: DemoMessage): string { return language.value === "zh" ? message.zhText ?? message.text : language.value === "ru" ? message.ruText ?? message.enText ?? message.text : language.value === "ja" ? message.jaText ?? message.enText ?? message.text : message.enText ?? message.text; }
|
||||
function sendMessage() { const text = draft.value.trim(); if (!text) return; messages.value.push({ id: Date.now(), author: "illusia", time: "now", text, mine: true }); draft.value = ""; }
|
||||
function avatarStyle(name: string) { let hash = 0; for (const char of name) hash = char.charCodeAt(0) + ((hash << 5) - hash); const colors = ["#168f83", "#7b9ed0", "#b99070", "#8b78b9"]; return { background: colors[Math.abs(hash) % colors.length] }; }
|
||||
|
||||
const skinPluginContext = computed(() => ({
|
||||
session: {
|
||||
status: { connected: true, connecting: false, channelId: selectedChannel.value.id, channelName: selectedChannel.value.name, userName: "illusia" },
|
||||
channels: channels.map((channel, depth) => ({ id: channel.id, name: channel.name, parentId: "", depth, memberCount: channel.members.length, current: channel.id === selectedChannel.value.id })),
|
||||
members: selectedChannel.value.members.map((member) => ({
|
||||
id: member.id,
|
||||
name: member.name,
|
||||
channelId: selectedChannel.value.id,
|
||||
status: member.id === speakingId.value ? "speaking" : "online",
|
||||
speaking: member.id === speakingId.value,
|
||||
self: member.id === "illusia",
|
||||
})),
|
||||
},
|
||||
favorites: { items: [] },
|
||||
chat: { messages: visibleMessages.value.map((message) => ({ id: String(message.id), author: message.author, text: messageText(message), time: message.time, kind: message.mine ? "self" : "message", channelId: selectedChannel.value.id })) },
|
||||
}));
|
||||
|
||||
const skinPluginActions = {
|
||||
"voice.joinChannel": (args: Record<string, string | number | boolean>) => {
|
||||
if (typeof args.channelId === "string" && channels.some((channel) => channel.id === args.channelId)) selectChannel(args.channelId);
|
||||
},
|
||||
"favorites.switch": (_args: Record<string, string | number | boolean>) => undefined,
|
||||
"chat.sendMessage": (args: Record<string, string | number | boolean>) => {
|
||||
if (typeof args.text !== "string" || args.text.length > 1000) return;
|
||||
draft.value = args.text;
|
||||
sendMessage();
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -11,6 +11,16 @@
|
||||
data-ws-part="app"
|
||||
:data-ws-page="showVoiceShell ? 'voice' : 'home'"
|
||||
>
|
||||
<SkinPluginOutlet
|
||||
v-if="activeSkin?.pluginData"
|
||||
:skin-id="activeSkin.id"
|
||||
:skin-version="activeSkin.version"
|
||||
:document="activeSkin.pluginData"
|
||||
:page="showVoiceShell ? 'voice' : 'home'"
|
||||
:data="skinPluginContext"
|
||||
:assets="activeSkin.assets"
|
||||
:actions="skinPluginActions"
|
||||
/>
|
||||
<!-- Connection / welcome screen -->
|
||||
<section
|
||||
v-if="!showVoiceShell"
|
||||
@@ -916,6 +926,7 @@
|
||||
import { observeMobileViewport } from "../services/mobile-viewport.js";
|
||||
import { computed, 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";
|
||||
import VoiceMemberCards from "../components/web-client/VoiceMemberCards.vue";
|
||||
import VoicePerformancePanel from "../components/web-client/VoicePerformancePanel.vue";
|
||||
@@ -1446,6 +1457,82 @@ 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 skinPluginContext = computed(() => ({
|
||||
session: {
|
||||
status: {
|
||||
connected: voiceState.connected,
|
||||
connecting: voiceState.connecting,
|
||||
channelId: currentChannel.value?.id ?? "",
|
||||
channelName: currentChannelName.value,
|
||||
userName: nickname.value,
|
||||
},
|
||||
channels: channelTree.value.map((item) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
parentId: item.parentID,
|
||||
depth: item.depth,
|
||||
memberCount: item.members.length,
|
||||
current: item.id === currentChannel.value?.id,
|
||||
})),
|
||||
members: memberChannels.value.flatMap((item) => item.members.map((member) => ({
|
||||
id: String(member.id),
|
||||
name: member.nickname,
|
||||
channelId: item.id,
|
||||
status: member.away ? "away" : member.inputMuted ? "muted" : speakingIds.has(member.id) ? "speaking" : "online",
|
||||
speaking: speakingIds.has(member.id),
|
||||
self: member.id === voiceState.tsClientId,
|
||||
}))),
|
||||
},
|
||||
favorites: { items: skinPluginFavorites.value },
|
||||
chat: {
|
||||
messages: chat.visibleMessages.value.filter((message) => message.scope === "channel").map((message) => ({
|
||||
id: message.id,
|
||||
author: message.invokerName,
|
||||
text: message.message,
|
||||
time: new Date(message.timestamp).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }),
|
||||
kind: message.isSelf ? "self" : "message",
|
||||
channelId: message.targetId ?? currentChannel.value?.id ?? "",
|
||||
})),
|
||||
},
|
||||
}));
|
||||
|
||||
const skinPluginActions = {
|
||||
"voice.joinChannel": (args: Record<string, string | number | boolean>) => {
|
||||
if (!voiceState.connected || typeof args.channelId !== "string") return;
|
||||
const target = channelTree.value.find((item) => item.id === args.channelId);
|
||||
if (target && target.id !== currentChannel.value?.id) selectChannel(target);
|
||||
},
|
||||
"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);
|
||||
},
|
||||
"chat.sendMessage": (args: Record<string, string | number | boolean>) => {
|
||||
if (!voiceState.connected || typeof args.text !== "string" || !currentChannel.value?.id) return;
|
||||
const text = args.text.trim();
|
||||
if (!text || text.length > 1000 || text.includes("\u0000")) return;
|
||||
void sendTextMessage(text, currentChannel.value.id);
|
||||
},
|
||||
};
|
||||
|
||||
watch(() => pokeNotifications.length, (length, previousLength) => {
|
||||
const latest = pokeNotifications[length - 1];
|
||||
if (!latest || length <= previousLength) return;
|
||||
@@ -1657,3 +1744,5 @@ function resolveSkinMessages(skin: InstalledSkin | null, locale: Language): Reco
|
||||
<style scoped src="../styles/web-client.css"></style>
|
||||
|
||||
<style scoped src="../styles/web-client-mobile.css"></style>
|
||||
|
||||
<style src="../styles/skin-plugin.css"></style>
|
||||
Reference in new issue
Block a user