mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
fix(skins): refresh plugin assets when switching skins
This commit is contained in:
1 parent
0c4cc344ef
commit
16f28ca348
5 files changed
+99
-8
No files matched your search
@@ -140,8 +140,9 @@ schema v2 支持公开组件布局、桌面/平板/手机配置、本地覆盖
|
||||
- 存储现按皮肤 ID 和版本分键;单份损坏数据可以单独清除并恢复原包,不影响其他皮肤。宿主保留的 data-ws-* 属性不会由作者节点写入渲染 DOM。
|
||||
- 编辑器操作按钮和选择器现在保留至少 44 px 触控高度,支持 Escape 关闭并在打开/关闭时移动焦点;继续打磨窄屏布局和可理解的校验提示。组件新增权限仍由宿主按既有权限机制要求批准;删除整页 surface 后应自然回到 WebSpeak 页面和宿主恢复控件。
|
||||
- 稳定门禁至少覆盖:组件/节点完整 CRUD 与撤销重做;导入导出往返;空组件文档;旧 schema v1/v2 只读兼容并在首次编辑时安全升到 v3;存储按皮肤版本隔离且坏数据可独立恢复;非法或越权文档不保存、不渲染;页面切换、皮肤切换及恢复入口不丢失。
|
||||
- 2026-10-10 的统一验证通过:617 项测试通过,服务端 TypeScript 构建、前端类型检查与 Vite 生产构建通过。这确认了自动化核心 CRUD 路径,不代表作者体验、跨浏览器行为或插件安全边界已经验收。
|
||||
- 2026-10-10 的统一验证通过:619 项测试通过,服务端 TypeScript 构建、前端类型检查与 Vite 生产构建通过。这确认了自动化核心 CRUD 路径和组件素材生命周期回归,不代表作者体验、跨浏览器行为或插件安全边界已经验收。
|
||||
- 当前补查发现客户端曾接受 v4 包级 `layout.json`,服务端却未读取该字段,造成同一个包本地可导入但服务端拒绝;已为校验一致性修复补充回归用例。后续只在整批修改后统一验证。
|
||||
- 组件渲染器原先只按素材路径缓存 Blob URL,切换皮肤后同名图片可能沿用旧皮肤素材,旧 URL 也会一直留到卸载;现改为同时绑定 Blob,并在资源替换、皮肤切换或组件卸载时释放。对应缺失素材和换包回归已加入自动化验证。
|
||||
- R5 完成门槛包括:编辑器能完整管理组件和节点;更新后页面即时预览;导入、导出、版本隔离、坏数据恢复及旧格式迁移可靠;客户端与服务端对每种包格式采用一致校验;键盘与窄屏作者流程可用;授权拒绝/撤销、恢复原生页面、插件销毁与资源回收通过针对性验证;跨浏览器动作和资源边界完成独立复核。
|
||||
- R5 门槛通过前暂停新增参考皮肤功能和视觉扩展。R6 现有样例作为回归材料保留,之后只因明确的样例阻塞做小范围系统修补,不再反复重做通用架构或重新采集参考页面。
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
import { parseSkinExtensionUiOutput } from "../../../src/shared/skin-extension-ui.js";
|
||||
import { parseSkinExtensionUiInput } from "../../../src/shared/skin-extension-ui-input.js";
|
||||
import { approveSkinPluginComponents, getMissingSkinPluginApprovals, isSkinPluginComponentApproved, revokeSkinPluginApprovals } from "../services/skin-plugin-approval.js";
|
||||
import { createSkinPluginAssetUrlCache } from "../services/skin-plugin-asset-urls.js";
|
||||
|
||||
type Scalar = string | number | boolean;
|
||||
type SafeContext = Record<string, unknown>;
|
||||
@@ -66,7 +67,7 @@ export default defineComponent({
|
||||
const manageOpen = ref(false);
|
||||
const refresh = ref(0);
|
||||
const stateByComponent = reactive<Record<string, Record<string, Scalar>>>({});
|
||||
const objectUrls = new Map<string, string>();
|
||||
const assetUrls = createSkinPluginAssetUrlCache();
|
||||
const validatedDocument = computed(() => {
|
||||
let document: SkinPluginDocument;
|
||||
const emptyRuntimeBase = Boolean(props.extensionOutput)
|
||||
@@ -118,6 +119,7 @@ export default defineComponent({
|
||||
surfaceSuppressed.value = false;
|
||||
refresh.value += 1;
|
||||
}, { immediate: true });
|
||||
watch(() => [props.skinId, props.skinVersion, props.assets] as const, () => assetUrls.clear());
|
||||
watch(activeSurface, (surface) => emit("surface-change", Boolean(surface)), { immediate: true, flush: "sync" });
|
||||
|
||||
function localState(component: SkinPluginComponent): Record<string, Scalar> {
|
||||
@@ -202,11 +204,7 @@ export default defineComponent({
|
||||
}
|
||||
|
||||
function assetUrl(path: string): string | undefined {
|
||||
const current = props.assets[path];
|
||||
if (!(current instanceof Blob)) return undefined;
|
||||
let url = objectUrls.get(path);
|
||||
if (!url) { url = URL.createObjectURL(current); objectUrls.set(path, url); }
|
||||
return url;
|
||||
return assetUrls.resolve(path, props.assets);
|
||||
}
|
||||
|
||||
function layoutComponentPath(component: SkinPluginComponent): string {
|
||||
@@ -345,7 +343,7 @@ export default defineComponent({
|
||||
refresh.value += 1;
|
||||
}
|
||||
|
||||
onUnmounted(() => { objectUrls.forEach((url) => URL.revokeObjectURL(url)); objectUrls.clear(); });
|
||||
onUnmounted(() => assetUrls.clear());
|
||||
|
||||
return () => {
|
||||
const nodes: VNodeChild[] = renderedComponents.value.map((component) => h("div", {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { createSkinPluginAssetUrlCache } from "./skin-plugin-asset-urls.js";
|
||||
|
||||
test("plugin asset URLs are reused only for the same Blob and released on replacement or skin change", () => {
|
||||
const originalCreate = URL.createObjectURL;
|
||||
const originalRevoke = URL.revokeObjectURL;
|
||||
const created: string[] = [];
|
||||
const revoked: string[] = [];
|
||||
URL.createObjectURL = () => {
|
||||
const url = `blob:skin-test-${created.length + 1}`;
|
||||
created.push(url);
|
||||
return url;
|
||||
};
|
||||
URL.revokeObjectURL = (url) => { revoked.push(url); };
|
||||
|
||||
try {
|
||||
const cache = createSkinPluginAssetUrlCache();
|
||||
const path = "assets/icon.png";
|
||||
const firstAsset = new Blob(["first skin"]);
|
||||
const secondAsset = new Blob(["second skin"]);
|
||||
|
||||
const firstUrl = cache.resolve(path, { [path]: firstAsset });
|
||||
assert.equal(firstUrl, "blob:skin-test-1");
|
||||
assert.equal(cache.resolve(path, { [path]: firstAsset }), firstUrl);
|
||||
assert.equal(cache.size, 1);
|
||||
|
||||
const secondUrl = cache.resolve(path, { [path]: secondAsset });
|
||||
assert.equal(secondUrl, "blob:skin-test-2");
|
||||
assert.deepEqual(revoked, [firstUrl]);
|
||||
assert.equal(cache.size, 1);
|
||||
|
||||
cache.clear();
|
||||
assert.deepEqual(revoked, [firstUrl, secondUrl]);
|
||||
assert.equal(cache.size, 0);
|
||||
} finally {
|
||||
URL.createObjectURL = originalCreate;
|
||||
URL.revokeObjectURL = originalRevoke;
|
||||
}
|
||||
});
|
||||
|
||||
test("a missing plugin asset releases a cached URL instead of returning stale artwork", () => {
|
||||
const originalCreate = URL.createObjectURL;
|
||||
const originalRevoke = URL.revokeObjectURL;
|
||||
const revoked: string[] = [];
|
||||
URL.createObjectURL = () => "blob:skin-test";
|
||||
URL.revokeObjectURL = (url) => { revoked.push(url); };
|
||||
|
||||
try {
|
||||
const cache = createSkinPluginAssetUrlCache();
|
||||
const path = "assets/icon.png";
|
||||
cache.resolve(path, { [path]: new Blob(["old"]) });
|
||||
assert.equal(cache.resolve(path, {}), undefined);
|
||||
assert.deepEqual(revoked, ["blob:skin-test"]);
|
||||
assert.equal(cache.size, 0);
|
||||
} finally {
|
||||
URL.createObjectURL = originalCreate;
|
||||
URL.revokeObjectURL = originalRevoke;
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
/** Owns object URLs for one rendered skin-plugin outlet. */
|
||||
export function createSkinPluginAssetUrlCache() {
|
||||
const urls = new Map<string, { asset: Blob; url: string }>();
|
||||
|
||||
function release(path: string): void {
|
||||
const entry = urls.get(path);
|
||||
if (!entry) return;
|
||||
URL.revokeObjectURL(entry.url);
|
||||
urls.delete(path);
|
||||
}
|
||||
|
||||
return {
|
||||
resolve(path: string, assets: Readonly<Record<string, Blob>>): string | undefined {
|
||||
const asset = assets[path];
|
||||
const existing = urls.get(path);
|
||||
if (!(asset instanceof Blob)) {
|
||||
release(path);
|
||||
return undefined;
|
||||
}
|
||||
if (existing?.asset === asset) return existing.url;
|
||||
release(path);
|
||||
const url = URL.createObjectURL(asset);
|
||||
urls.set(path, { asset, url });
|
||||
return url;
|
||||
},
|
||||
clear(): void {
|
||||
for (const path of urls.keys()) release(path);
|
||||
},
|
||||
get size(): number { return urls.size; },
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
revokeSkinPluginApprovals,
|
||||
} from "./skin-plugin-approval.js";
|
||||
import { createSkinPluginQuickServerProjection } from "./skin-plugin-context.js";
|
||||
import "./skin-plugin-asset-urls.test.js";
|
||||
|
||||
function surfaceDocument(): SkinPluginDocument {
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user