diff --git a/packages/frontend/src/Layout.vue b/packages/frontend/src/Layout.vue index 60a7c8b..3dc3116 100755 --- a/packages/frontend/src/Layout.vue +++ b/packages/frontend/src/Layout.vue @@ -18,7 +18,7 @@ : ""' title="ホーム" > - @@ -56,7 +56,7 @@
{{ title - ?? (serverInfo.success + ?? (serverInfo?.success ? serverInfo.name : null) ?? "LynqChat" @@ -261,7 +261,7 @@ watch(route, () => { title.value = route.meta.title; }); -if (!serverInfo.value.success) { +if (!serverInfo.value?.success) { throw new Error("サーバー情報の取得に失敗しました。"); } @@ -294,6 +294,24 @@ function handleError(event: ErrorEvent | PromiseRejectionEvent) { onMounted(async () => { window.addEventListener("error", handleError); window.addEventListener("unhandledrejection", handleError); + + if ("serviceWorker" in navigator) { + try { + const swFile = import.meta.env.MODE === "production" + ? "/sw.js" + : "/dev-sw.js?dev-sw"; + const registration = await navigator.serviceWorker.register(swFile, { + updateViaCache: "none", + type: import.meta.env.MODE === "production" + ? "classic" + : "module", + scope: "/", + }); + await registration.update(); + } catch (err) { + console.error("Service Worker registration failed:", err); + } + } }); onBeforeUnmount(() => { diff --git a/packages/frontend/src/lib/account.ts b/packages/frontend/src/lib/account.ts index a04dc51..71ed415 100644 --- a/packages/frontend/src/lib/account.ts +++ b/packages/frontend/src/lib/account.ts @@ -4,8 +4,15 @@ import { ref } from "vue"; await initClient(); -export let serverInfo = ref(await client.value.request("server-info")); -export let account = ref(await client.value.request("me")); +let serverInfoDraft: ApiMap["server-info"]["response"] | null = null; +let accountDraft: ApiMap["me"]["response"] | null = null; +try { + serverInfoDraft = await client.value.request("server-info"); + accountDraft = await client.value.request("me"); +} catch {} + +export let serverInfo = ref(serverInfoDraft); +export let account = ref(accountDraft); export let presentCommunity = ref["communitys"][number]>(); let communitys = ref["communitys"]>([]); diff --git a/packages/frontend/src/lib/sw.ts b/packages/frontend/src/lib/sw.ts index 8170517..bbb6c61 100644 --- a/packages/frontend/src/lib/sw.ts +++ b/packages/frontend/src/lib/sw.ts @@ -50,7 +50,13 @@ swSelf.addEventListener("fetch", (event) => { return; event.respondWith((async () => { - const cached = await caches.match(request); + let cached: Response | undefined; + if (request.destination === "document") { + cached = await caches.match("/index.html"); + } else { + cached = await caches.match(request); + } + if (cached) return cached; diff --git a/packages/frontend/src/main.ts b/packages/frontend/src/main.ts index 4268f17..3dc9aa9 100755 --- a/packages/frontend/src/main.ts +++ b/packages/frontend/src/main.ts @@ -90,7 +90,7 @@ router.afterEach((to, from) => { let serverName = "LynqChat"; - if (serverInfo.value.success && serverInfo.value.name) { + if (serverInfo.value?.success && serverInfo.value.name) { serverName = serverInfo.value.name; } diff --git a/packages/frontend/src/routes/community/channel.vue b/packages/frontend/src/routes/community/channel.vue index 3efb379..1267fe2 100644 --- a/packages/frontend/src/routes/community/channel.vue +++ b/packages/frontend/src/routes/community/channel.vue @@ -137,7 +137,7 @@ import Message from "@/components/Message.vue"; const route = useRoute(); const router = useRouter(); -if (!serverInfo.value.success) { +if (!serverInfo.value?.success) { throw new Error("サーバー情報の取得に失敗しました。"); } @@ -145,8 +145,8 @@ if (!serverInfo.value.isInitialized) { router.replace("/setup/initialization"); } -if (!account.value.success) { - switch (account.value.error.bad) { +if (!account.value?.success) { + switch (account.value?.error.bad) { case "client": router.replace("/signin"); break; @@ -270,7 +270,7 @@ const send = async (e: Event) => { return; } - if (!account.value.success) { + if (!account.value?.success) { isSending.value = false; createModal({ component: ErrorModal, @@ -336,7 +336,7 @@ provide("now", now); (async () => { isProcessing.value = true; - if (!serverInfo.value.success) { + if (!serverInfo.value?.success) { throw new Error("サーバー情報の取得に失敗しました。"); } diff --git a/packages/frontend/src/routes/community/index.vue b/packages/frontend/src/routes/community/index.vue index 553dda9..9fac8c9 100644 --- a/packages/frontend/src/routes/community/index.vue +++ b/packages/frontend/src/routes/community/index.vue @@ -137,7 +137,7 @@ const isProcessing = ref(false); const channels = ref["channels"]>(); -if (!serverInfo.value.success) { +if (!serverInfo.value?.success) { throw new Error("サーバー情報の取得に失敗しました。"); } @@ -145,8 +145,8 @@ if (!serverInfo.value.isInitialized) { router.replace("/setup/initialization"); } -if (!account.value.success) { - switch (account.value.error.bad) { +if (!account.value?.success) { + switch (account.value?.error.bad) { case "client": router.replace("/signin"); break; @@ -158,7 +158,7 @@ if (!account.value.success) { (async () => { isProcessing.value = true; - if (!serverInfo.value.success) { + if (!serverInfo.value?.success) { throw new Error("サーバー情報の取得に失敗しました。"); } diff --git a/packages/frontend/src/routes/index.vue b/packages/frontend/src/routes/index.vue index 23b580a..3f54d73 100755 --- a/packages/frontend/src/routes/index.vue +++ b/packages/frontend/src/routes/index.vue @@ -7,8 +7,8 @@ import { useRouter } from "vue-router"; const router = useRouter(); -if (!account.value.success) { - switch (account.value.error.bad) { +if (!account.value?.success) { + switch (account.value?.error.bad) { case "client": router.replace("/signin"); break; diff --git a/packages/frontend/src/routes/setup/create-admin.vue b/packages/frontend/src/routes/setup/create-admin.vue index 8c76d87..36e3d6f 100644 --- a/packages/frontend/src/routes/setup/create-admin.vue +++ b/packages/frontend/src/routes/setup/create-admin.vue @@ -10,7 +10,7 @@
+ {{ passwordStrength.message }} @@ -94,6 +95,10 @@ form { font-size: 1rem; margin: auto 0; } + +.password-strength { + color: v-bind(passwordStrengthColor); +}