diff --git a/index.html b/index.html index 5a01536..83b2223 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,14 @@ + + + + + + + Timi Server diff --git a/public/manifest.webmanifest b/public/manifest.webmanifest new file mode 100644 index 0000000..4210e82 --- /dev/null +++ b/public/manifest.webmanifest @@ -0,0 +1,10 @@ +{ + "name": "Timi Server", + "short_name": "Timi", + "lang": "zh-CN", + "start_url": "/", + "scope": "/", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#ffffff" +} diff --git a/src/main.ts b/src/main.ts index 6d8f44b..994a99a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -11,6 +11,53 @@ import "vue-virtual-scroller/dist/vue-virtual-scroller.css"; import { axios } from "timi-web"; import { useSettingStore } from "@/store/settingStore.ts"; +type FullscreenElement = HTMLElement & { + webkitRequestFullscreen?: () => Promise | void; + msRequestFullscreen?: () => Promise | void; +}; + +type StandaloneNavigator = Navigator & { + standalone?: boolean; +}; + +const requestLaunchFullscreen = async (): Promise => { + if (document.fullscreenElement) { + return; + } + + const navigatorInfo = window.navigator as StandaloneNavigator; + const isStandaloneMode = window.matchMedia("(display-mode: standalone)").matches || navigatorInfo.standalone === true; + if (isStandaloneMode) { + return; + } + + const rootElement = document.documentElement as FullscreenElement; + if (rootElement.requestFullscreen) { + await rootElement.requestFullscreen(); + return; + } + if (rootElement.webkitRequestFullscreen) { + await rootElement.webkitRequestFullscreen(); + return; + } + if (rootElement.msRequestFullscreen) { + await rootElement.msRequestFullscreen(); + } +}; + +const bindLaunchFullscreenRequest = (): void => { + const onFirstInteraction = async (): Promise => { + try { + await requestLaunchFullscreen(); + } catch (error) { + console.warn("\u5168\u5c4f\u8bf7\u6c42\u88ab\u6d4f\u89c8\u5668\u62d2\u7edd\u6216\u4e0d\u652f\u6301", error); + } + }; + + window.addEventListener("pointerdown", onFirstInteraction, { once: true, passive: true }); + window.addEventListener("keydown", onFirstInteraction, { once: true }); +}; + axios.interceptors.request.use((config) => { const settingStore = useSettingStore(); const token = settingStore.connect.token.trim(); @@ -35,9 +82,10 @@ app.config.errorHandler = (error) => { console.error(error); Toast({ theme: "error", - message: "页面发生异常,请稍后重试" + message: "\u9875\u9762\u53d1\u751f\u5f02\u5e38\uff0c\u8bf7\u7a0d\u540e\u91cd\u8bd5" }); }; app.use(pinia); app.use(router); app.mount("#root"); +bindLaunchFullscreenRequest();