feat: add Android gateway preview and refactoring plan

This commit is contained in:
illusia committed 2026-10-01 08:13:46 +08:00
1 parent 9e2b9bf564
commit aeaeb15965
73 files changed
+4347 -24

No files matched your search

+6 -1
View File
@@ -4,6 +4,7 @@
type="button"
class="skin-trigger"
data-ws-part="skin.trigger"
:disabled="options.length === 0"
:aria-label="menuLabel"
:title="`${menuLabel}: ${selectedOption.label}`"
aria-haspopup="listbox"
@@ -60,7 +61,11 @@ const emit = defineEmits<{
}>();
const options = computed(() => props.options);
const selectedOption = computed(() => options.value.find((option) => option.value === props.modelValue) ?? options.value[0]);
const selectedOption = computed(() => options.value.find((option) => option.value === props.modelValue) ?? options.value[0] ?? {
value: props.modelValue,
label: props.menuLabel,
icon: "compass",
});
const root = ref<HTMLElement | null>(null);
const open = ref(false);
const menuId = `skin-menu-${Math.random().toString(36).slice(2, 9)}`;
@@ -26,6 +26,7 @@ export function useWebClientPublicConfig({
}: UseWebClientPublicConfigOptions) {
const accessMode = ref<"fixed" | "open">("fixed");
const initialized = ref(false);
const mobileMode = ref(false);
const siteName = ref("WebSpeak");
const appVersion = ref("0.2.5-preview");
const visitorNumber = ref<number | null>(null);
@@ -45,6 +46,7 @@ export function useWebClientPublicConfig({
const config = await response.json() as {
version?: unknown;
initialized?: unknown;
mobile?: unknown;
siteName?: unknown;
welcomeText?: unknown;
welcomeTextEn?: unknown;
@@ -60,6 +62,7 @@ export function useWebClientPublicConfig({
visitorNumber.value = Number.isSafeInteger(config.visitorNumber) && Number(config.visitorNumber) > 0 ? Number(config.visitorNumber) : null;
visitorTotal.value = Number.isSafeInteger(config.visitorTotal) && Number(config.visitorTotal) > 0 ? Number(config.visitorTotal) : null;
initialized.value = config.initialized === true;
mobileMode.value = config.mobile === true;
if (typeof config.siteName === "string" && config.siteName.trim()) siteName.value = config.siteName.trim();
if (typeof config.welcomeText === "string") welcomeTexts.zh = config.welcomeText;
if (typeof config.welcomeTextEn === "string") welcomeTexts.en = config.welcomeTextEn;
@@ -101,6 +104,7 @@ export function useWebClientPublicConfig({
return {
accessMode,
initialized,
mobileMode,
siteName,
appVersion,
visitorNumber,
+63 -4
View File
@@ -1,6 +1,8 @@
import { createApp } from "vue";
import { createPinia } from "pinia";
import { createRouter, createWebHistory } from "vue-router";
import { Capacitor } from "@capacitor/core";
import { Nodejs } from "@capawesome/capacitor-nodejs";
import App from "./App.vue";
import WebClient from "./views/WebClient.vue";
import AdminView from "./views/AdminView.vue";
@@ -38,7 +40,64 @@ const router = createRouter({
routes,
});
const app = createApp(App);
app.use(createPinia());
app.use(router);
app.mount("#app");
if (Capacitor.isNativePlatform() && !(location.hostname === "127.0.0.1" && location.port === "3040")) {
void startAndroidGateway();
} else {
mountApp();
}
function mountApp(): void {
const app = createApp(App);
app.use(createPinia());
app.use(router);
app.mount("#app");
}
async function startAndroidGateway(): Promise<void> {
const root = document.getElementById("app");
if (!root) return;
root.innerHTML = '<main style="min-height:100dvh;display:grid;place-items:center;background:#e9fbfb;color:#0b5960;font:16px system-ui;text-align:center;padding:24px"><div><h1 style="font-size:26px">WebSpeak</h1><p id="mobile-gateway-status">正在启动本地语音服务…</p></div></main>';
const status = document.getElementById("mobile-gateway-status");
let complete = false;
let pollTimer = 0;
let timeoutTimer = 0;
try {
const listener = await Nodejs.addListener("message", (event) => {
if (complete) return;
if (event.eventName === "webspeak-error") {
complete = true;
window.clearInterval(pollTimer);
window.clearTimeout(timeoutTimer);
if (status) status.textContent = "本地语音服务启动失败,请重新打开应用。";
return;
}
if (event.eventName !== "webspeak-health") return;
const health = event.args[0];
if (!health || typeof health !== "object" || Array.isArray(health) || health.ready !== true) return;
complete = true;
window.clearInterval(pollTimer);
window.clearTimeout(timeoutTimer);
void listener.remove();
window.location.replace("http://127.0.0.1:3040/");
});
const poll = async () => {
if (complete) return;
const { ready } = await Nodejs.isReady();
if (ready) await Nodejs.send({ eventName: "webspeak-health", args: [] });
};
pollTimer = window.setInterval(() => { void poll().catch(() => {}); }, 500);
timeoutTimer = window.setTimeout(() => {
if (complete) return;
complete = true;
window.clearInterval(pollTimer);
if (status) status.textContent = "本地语音服务启动超时,请重新打开应用。";
}, 45_000);
await poll();
} catch {
complete = true;
window.clearInterval(pollTimer);
window.clearTimeout(timeoutTimer);
if (status) status.textContent = "本地语音服务启动失败,请重新打开应用。";
}
}
+2 -1
View File
@@ -10,7 +10,7 @@
<small>{{ t('browserWorkspace') }}</small>
</div>
</div>
<div class="header-tools" data-ws-part="home.header-tools"><div class="header-note" data-ws-part="home.gateway-status"><span class="tiny-dot"></span> {{ t('secureGateway') }}</div><a class="github-button" href="https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak" target="_blank" rel="noreferrer" :title="t('githubRepository')" :aria-label="t('githubRepository')"><Icon name="github" :size="18" /><span>{{ t('githubRepository') }}</span></a><button type="button" class="qq-button" :title="t('qqGroup')" :aria-label="t('qqGroup')" aria-haspopup="dialog" @click="qqModalOpen = true"><Icon name="qq" :size="18" /><span class="qq-label">{{ t('qqGroup') }}</span></button><a class="bilibili-button" href="https://space.bilibili.com/25414873" target="_blank" rel="noreferrer" :title="t('bilibiliProfile')" :aria-label="t('bilibiliProfile')"><span class="bilibili-glyph">B</span><span class="bilibili-label">{{ t('bilibiliProfile') }}</span></a><span class="version-badge" :title="`${t('currentVersion')}: v${appVersion}`" :aria-label="`${t('currentVersion')}: v${appVersion}`">v{{ appVersion }}</span><a class="changelog-button" href="https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak/blob/master/CHANGELOG.md" target="_blank" rel="noreferrer" :title="t('viewChangelog')" :aria-label="t('viewChangelog')"><Icon name="clock" :size="16" /><span>{{ t('viewChangelog') }}</span></a><a class="guide-button" href="/admin" :title="t('adminConsole')" :aria-label="t('adminConsole')"><Icon name="settings" :size="15" /><span>{{ t('adminConsole') }}</span></a><SkinSwitcher v-model="activeSkinId" class="join-skin-switcher" :menu-label="t('skinSelector')" :options="skinOptions" @change="onSkinChange" /><LanguageSwitcher v-model="language" class="join-language-switcher" :menu-label="t('languageMenu')" @change="persistLanguage" /></div>
<div class="header-tools" data-ws-part="home.header-tools"><div class="header-note" data-ws-part="home.gateway-status"><span class="tiny-dot"></span> {{ t('secureGateway') }}</div><a class="github-button" href="https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak" target="_blank" rel="noreferrer" :title="t('githubRepository')" :aria-label="t('githubRepository')"><Icon name="github" :size="18" /><span>{{ t('githubRepository') }}</span></a><button type="button" class="qq-button" :title="t('qqGroup')" :aria-label="t('qqGroup')" aria-haspopup="dialog" @click="qqModalOpen = true"><Icon name="qq" :size="18" /><span class="qq-label">{{ t('qqGroup') }}</span></button><a class="bilibili-button" href="https://space.bilibili.com/25414873" target="_blank" rel="noreferrer" :title="t('bilibiliProfile')" :aria-label="t('bilibiliProfile')"><span class="bilibili-glyph">B</span><span class="bilibili-label">{{ t('bilibiliProfile') }}</span></a><span class="version-badge" :title="`${t('currentVersion')}: v${appVersion}`" :aria-label="`${t('currentVersion')}: v${appVersion}`">v{{ appVersion }}</span><a class="changelog-button" href="https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak/blob/master/CHANGELOG.md" target="_blank" rel="noreferrer" :title="t('viewChangelog')" :aria-label="t('viewChangelog')"><Icon name="clock" :size="16" /><span>{{ t('viewChangelog') }}</span></a><a v-if="!mobileMode" class="guide-button" href="/admin" :title="t('adminConsole')" :aria-label="t('adminConsole')"><Icon name="settings" :size="15" /><span>{{ t('adminConsole') }}</span></a><SkinSwitcher v-model="activeSkinId" class="join-skin-switcher" :menu-label="t('skinSelector')" :options="skinOptions" @change="onSkinChange" /><LanguageSwitcher v-model="language" class="join-language-switcher" :menu-label="t('languageMenu')" @change="persistLanguage" /></div>
</header>
<main class="join-content" data-ws-part="home.content">
@@ -569,6 +569,7 @@ const {
const {
accessMode,
initialized,
mobileMode,
siteName,
appVersion,
visitorNumber,