mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-02 19:42:51 +08:00
fix(audio): keep device menus within viewport
This commit is contained in:
1 parent
1951884d12
commit
fbcbe994f0
5 files changed
+88
-12
No files matched your search
@@ -219,3 +219,11 @@
|
||||
- 依据与兼容:这些部件原本就属于文档化公开接口,也已被 KAAK CSS 使用;本次补齐注册表不增加新行为、不改变皮肤包内容或版本。
|
||||
- 验证结果:公开钩子扫描无遗漏;`src/shared/skin-layout.test.ts` 8/8、完整 `npm test` 656/656、`npm run build` 和 `npm run web:build` 均通过,`git diff --check` 通过。
|
||||
- 当前状态与下一步:成员静音图标和音频设备选择器子部件现在可被布局系统分别识别和自定义。继续按已记录的 KOOK 行为推进视觉与交互细节;音乐频道首次进入时聊天状态仍缺少直接观察,不按频道名猜测。
|
||||
|
||||
## 本轮修改节点(2026-10-11,设备选择菜单视口适配)
|
||||
|
||||
- 问题依据:设备下拉菜单按触发器位置打开,但原定位逻辑在可用空间不足时仍强制至少 80px 高;屏幕较矮或弹窗靠近底边时,列表会超出视口。KOOK 参考中的菜单最高约 240px、选项约 32px,超长列表可滚动。
|
||||
- 修改内容与边界:将菜单定位计算抽为可复用的纯函数;根据上下方实际空间选择开口方向并限高,同时将菜单宽度约束在窄视口内。保留 240px 最大高度和 32px 选项尺寸,空间不足时继续在菜单内滚动。只修通用设备选择组件的视口适配,不切换设备、不碰音频值或设备权限,也不加入 KAAK 专属运行逻辑。
|
||||
- KAAK 对应:KAAK 使用同一宿主设备选择器,仍保留其已记录的字体、深色菜单、选中/悬停/键盘态和箭头反馈;无需变更皮肤包版本。
|
||||
- 验证:定位边界测试 4/4、完整 `npm test` 660/660、`npm run build`、`npm run web:build` 和 `git diff --check` 均通过。本节点未进行浏览器视觉验收或触碰真实音频设备;测试验证的是菜单几何边界。
|
||||
- 当前状态与下一步:菜单不再靠最小高度越过视口边界。后续继续把音量交互、性能状态卡与字体层级按已记录证据逐项验收;付费屏幕分享仍跳过。
|
||||
+1
-1
@@ -11,7 +11,7 @@
|
||||
"scripts": {
|
||||
"dev": "tsx src/index.ts",
|
||||
"build": "tsc",
|
||||
"test": "node --import tsx --test src/admin/skin-registry.test.ts web/test/admin-api.integration.test.ts web/test/admin-view.test.mjs web/src/services/admin-api.test.ts src/security/open-target-policy.test.ts src/server/visitor-count.test.ts src/server/voice-protocol.test.ts src/server/teamspeak-resolver.test.ts src/server/ts-client.test.ts src/server/join-ticket.test.ts src/server/identity-lease.test.ts src/server/session-manager.test.ts src/server/directory-sync.test.ts src/server/session-events.test.ts src/server/reconnect-policy.test.ts src/server/voice-commands.test.ts src/server/voice-bridge.test.ts src/server/session-audio.test.ts src/server/voice-bridge.integration.test.ts src/server/webrtc-audio.test.ts src/server/webrtc-config.test.ts src/server/audio-stats.test.ts src/server/channel-capacity.test.ts src/server/directory-view.test.ts src/server/member-avatars.test.ts src/server/screen-share-coordinator.test.ts src/shared/client-commands.test.ts src/shared/skin-layout.test.ts src/shared/skin-plugin.test.ts src/shared/skin-runtime-plugin-context.test.ts src/shared/skin-runtime-plugins.test.ts src/shared/skin-runtime-plugin-approval.test.ts src/shared/server-messages.test.ts src/shared/webrtc.test.ts scripts/docker-healthcheck.test.mjs web/test/voice-session.test.mjs web/test/audio-controls.test.mjs web/test/connection-dialogs.test.mjs web/test/voice-performance.test.mjs web/test/screen-share.test.ts web/test/screen-share-ui.test.mjs web/test/android-gateway.test.ts web/src/services/skin-catalog.test.ts web/src/services/skin-plugin-runtime.test.ts web/src/services/skin-plugin-authoring.test.ts web/src/services/host-editor-top-layer.test.ts web/src/services/skin-extension-ui.test.ts web/src/services/member-menu-placement.test.ts web/src/services/mobile-viewport.test.ts web/src/services/mobile-away.test.ts web/src/services/screen-wake-lock.test.ts web/src/services/microphone-start.test.ts web/src/services/skin-pack.test.ts web/src/services/skin-runtime-plugin-approval.test.ts web/src/services/skin-layout-storage.test.ts web/src/services/skin-layout-geometry.test.ts web/src/services/skin-layout-focus.test.ts web/test/skin-layout-runtime.test.mjs web/test/skin-plugin-editor.test.mjs web/src/services/identity-import.test.ts web/test/identity-dialog.test.mjs web/test/skin-lifecycle.test.mjs web/src/services/local-persistence.test.ts web/src/services/quick-servers.test.ts src/server/teamspeak-alias.test.ts src/server/teamspeak-alias-integration.test.ts web/src/services/teamspeak-target.test.ts web/src/services/skin-extension-sandbox.test.ts web/src/services/skin-extension-wasm-policy.test.ts web/src/services/skin-extension-wasm-sandbox.test.ts web/src/services/skin-runtime-plugin-wasm.test.ts web/src/services/skin-extension-wasm-ui-loop.test.ts web/src/services/skin-wasm-interpreter.test.ts",
|
||||
"test": "node --import tsx --test src/admin/skin-registry.test.ts web/test/admin-api.integration.test.ts web/test/admin-view.test.mjs web/src/services/admin-api.test.ts src/security/open-target-policy.test.ts src/server/visitor-count.test.ts src/server/voice-protocol.test.ts src/server/teamspeak-resolver.test.ts src/server/ts-client.test.ts src/server/join-ticket.test.ts src/server/identity-lease.test.ts src/server/session-manager.test.ts src/server/directory-sync.test.ts src/server/session-events.test.ts src/server/reconnect-policy.test.ts src/server/voice-commands.test.ts src/server/voice-bridge.test.ts src/server/session-audio.test.ts src/server/voice-bridge.integration.test.ts src/server/webrtc-audio.test.ts src/server/webrtc-config.test.ts src/server/audio-stats.test.ts src/server/channel-capacity.test.ts src/server/directory-view.test.ts src/server/member-avatars.test.ts src/server/screen-share-coordinator.test.ts src/shared/client-commands.test.ts src/shared/skin-layout.test.ts src/shared/skin-plugin.test.ts src/shared/skin-runtime-plugin-context.test.ts src/shared/skin-runtime-plugins.test.ts src/shared/skin-runtime-plugin-approval.test.ts src/shared/server-messages.test.ts src/shared/webrtc.test.ts scripts/docker-healthcheck.test.mjs web/test/voice-session.test.mjs web/test/audio-controls.test.mjs web/test/connection-dialogs.test.mjs web/test/voice-performance.test.mjs web/test/screen-share.test.ts web/test/screen-share-ui.test.mjs web/test/android-gateway.test.ts web/src/services/skin-catalog.test.ts web/src/services/skin-plugin-runtime.test.ts web/src/services/skin-plugin-authoring.test.ts web/src/services/host-editor-top-layer.test.ts web/src/services/skin-extension-ui.test.ts web/src/services/member-menu-placement.test.ts web/src/services/audio-device-menu-placement.test.ts web/src/services/mobile-viewport.test.ts web/src/services/mobile-away.test.ts web/src/services/screen-wake-lock.test.ts web/src/services/microphone-start.test.ts web/src/services/skin-pack.test.ts web/src/services/skin-runtime-plugin-approval.test.ts web/src/services/skin-layout-storage.test.ts web/src/services/skin-layout-geometry.test.ts web/src/services/skin-layout-focus.test.ts web/test/skin-layout-runtime.test.mjs web/test/skin-plugin-editor.test.mjs web/src/services/identity-import.test.ts web/test/identity-dialog.test.mjs web/test/skin-lifecycle.test.mjs web/src/services/local-persistence.test.ts web/src/services/quick-servers.test.ts src/server/teamspeak-alias.test.ts src/server/teamspeak-alias-integration.test.ts web/src/services/teamspeak-target.test.ts web/src/services/skin-extension-sandbox.test.ts web/src/services/skin-extension-wasm-policy.test.ts web/src/services/skin-extension-wasm-sandbox.test.ts web/src/services/skin-runtime-plugin-wasm.test.ts web/src/services/skin-extension-wasm-ui-loop.test.ts web/src/services/skin-wasm-interpreter.test.ts",
|
||||
"verify": "npm test && npm run build && npm run web:build",
|
||||
"skin:harbor:build": "node web/scripts/build-harbor-voice-skin.mjs",
|
||||
"skin:kaak:build": "node web/scripts/build-kaak-voice-skin.mjs",
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch, type CSSProperties } from "vue";
|
||||
import { placeAudioDeviceMenu } from "../../services/audio-device-menu-placement.js";
|
||||
|
||||
export interface AudioDeviceOption {
|
||||
value: string;
|
||||
@@ -92,19 +93,13 @@ function updateMenuPosition(): void {
|
||||
const rect = trigger.value?.getBoundingClientRect();
|
||||
if (!rect || typeof window === "undefined") return;
|
||||
|
||||
const fullHeight = Math.min(240, props.options.length * 32 + 8);
|
||||
const below = Math.max(0, window.innerHeight - rect.bottom - 8);
|
||||
const above = Math.max(0, rect.top - 8);
|
||||
const opensAbove = below < fullHeight && above > below;
|
||||
const available = opensAbove ? above : below;
|
||||
const height = Math.min(fullHeight, Math.max(80, available));
|
||||
const top = opensAbove ? Math.max(8, rect.top - height - 4) : Math.min(rect.bottom + 4, window.innerHeight - height - 8);
|
||||
const placement = placeAudioDeviceMenu(rect, { width: window.innerWidth, height: window.innerHeight }, props.options.length);
|
||||
|
||||
menuStyle.value = {
|
||||
top: `${top}px`,
|
||||
left: `${rect.left}px`,
|
||||
width: `${rect.width}px`,
|
||||
maxHeight: `${height}px`,
|
||||
top: `${placement.top}px`,
|
||||
left: `${placement.left}px`,
|
||||
width: `${placement.width}px`,
|
||||
maxHeight: `${placement.maxHeight}px`,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { placeAudioDeviceMenu } from "./audio-device-menu-placement.js";
|
||||
|
||||
test("device menu opens below the trigger and keeps the 240px cap", () => {
|
||||
assert.deepEqual(
|
||||
placeAudioDeviceMenu({ top: 80, bottom: 120, left: 40, width: 280 }, { width: 1280, height: 720 }, 20),
|
||||
{ top: 124, left: 40, width: 280, maxHeight: 240 },
|
||||
);
|
||||
});
|
||||
|
||||
test("device menu opens above when the bottom edge cannot fit the list", () => {
|
||||
assert.deepEqual(
|
||||
placeAudioDeviceMenu({ top: 600, bottom: 640, left: 80, width: 300 }, { width: 1280, height: 700 }, 20),
|
||||
{ top: 356, left: 80, width: 300, maxHeight: 240 },
|
||||
);
|
||||
});
|
||||
|
||||
test("device menu shrinks to the remaining space in a short viewport", () => {
|
||||
const placement = placeAudioDeviceMenu(
|
||||
{ top: 40, bottom: 60, left: 8, width: 180 },
|
||||
{ width: 320, height: 84 },
|
||||
8,
|
||||
);
|
||||
|
||||
assert.deepEqual(placement, { top: 8, left: 8, width: 180, maxHeight: 28 });
|
||||
assert.ok(placement.top + placement.maxHeight <= 84 - 8);
|
||||
});
|
||||
|
||||
test("device menu width stays inside narrow viewport bounds", () => {
|
||||
assert.deepEqual(
|
||||
placeAudioDeviceMenu({ top: 20, bottom: 40, left: 120, width: 220 }, { width: 200, height: 400 }, 4),
|
||||
{ top: 44, left: 8, width: 184, maxHeight: 136 },
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,38 @@
|
||||
export interface AudioDeviceMenuAnchor {
|
||||
top: number;
|
||||
bottom: number;
|
||||
left: number;
|
||||
width: number;
|
||||
}
|
||||
|
||||
export interface AudioDeviceMenuPlacement {
|
||||
top: number;
|
||||
left: number;
|
||||
width: number;
|
||||
maxHeight: number;
|
||||
}
|
||||
|
||||
const VIEWPORT_INSET = 8;
|
||||
const MENU_GAP = 4;
|
||||
const OPTION_HEIGHT = 32;
|
||||
const MENU_PADDING = 8;
|
||||
const MAX_MENU_HEIGHT = 240;
|
||||
|
||||
export function placeAudioDeviceMenu(
|
||||
anchor: AudioDeviceMenuAnchor,
|
||||
viewport: { width: number; height: number },
|
||||
optionCount: number,
|
||||
): AudioDeviceMenuPlacement {
|
||||
const insetX = Math.min(VIEWPORT_INSET, Math.max(0, viewport.width / 2));
|
||||
const width = Math.min(Math.max(0, anchor.width), Math.max(0, viewport.width - insetX * 2));
|
||||
const left = Math.max(insetX, Math.min(anchor.left, viewport.width - insetX - width));
|
||||
const fullHeight = Math.min(MAX_MENU_HEIGHT, Math.max(0, optionCount) * OPTION_HEIGHT + MENU_PADDING);
|
||||
const below = Math.max(0, viewport.height - VIEWPORT_INSET - anchor.bottom - MENU_GAP);
|
||||
const above = Math.max(0, anchor.top - VIEWPORT_INSET - MENU_GAP);
|
||||
const opensAbove = below < fullHeight && above > below;
|
||||
const available = opensAbove ? above : below;
|
||||
const maxHeight = Math.min(fullHeight, available);
|
||||
const top = opensAbove ? anchor.top - MENU_GAP - maxHeight : anchor.bottom + MENU_GAP;
|
||||
|
||||
return { top, left, width, maxHeight };
|
||||
}
|
||||
Reference in new issue
Block a user