mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 03:52:50 +08:00
fix: cancel stale voice operations and isolate Android startup
This commit is contained in:
1 parent
8960189bc7
commit
e2f0a43762
15 files changed
+913
-174
No files matched your search
+2
-56
@@ -1,8 +1,7 @@
|
||||
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 { bootstrapPlatform } from "./platform/bootstrap.js";
|
||||
import App from "./App.vue";
|
||||
import WebClient from "./views/WebClient.vue";
|
||||
import AdminView from "./views/AdminView.vue";
|
||||
@@ -40,11 +39,7 @@ const router = createRouter({
|
||||
routes,
|
||||
});
|
||||
|
||||
if (Capacitor.isNativePlatform() && !(location.hostname === "127.0.0.1" && location.port === "3040")) {
|
||||
void startAndroidGateway();
|
||||
} else {
|
||||
mountApp();
|
||||
}
|
||||
void bootstrapPlatform(mountApp);
|
||||
|
||||
function mountApp(): void {
|
||||
const app = createApp(App);
|
||||
@@ -52,52 +47,3 @@ function mountApp(): void {
|
||||
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 = "本地语音服务启动失败,请重新打开应用。";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user