From 4de77784c9ee5bf787e7bda41aae84d81edff78a Mon Sep 17 00:00:00 2001
From: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
Date: Sun, 21 Jan 2024 11:50:05 +0900
Subject: enhance(sw): オフライン表示のデザインを改善 (#13052)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
* enhance(sw): オフライン表示のデザインを改善
* Update Changelog
* fix
* fix
* fix
* 言語が取得できなかった場合のフォールバックを追加
* (change) translation key
---
packages/sw/src/sw.ts | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
(limited to 'packages/sw/src')
diff --git a/packages/sw/src/sw.ts b/packages/sw/src/sw.ts
index b79fd8ce7a..f423eaca20 100644
--- a/packages/sw/src/sw.ts
+++ b/packages/sw/src/sw.ts
@@ -6,6 +6,7 @@
import { get } from 'idb-keyval';
import * as Misskey from 'misskey-js';
import type { PushNotificationDataMap } from '@/types.js';
+import type { I18n, Locale } from '@/scripts/i18n.js';
import { createEmptyNotification, createNotification } from '@/scripts/create-notification.js';
import { swLang } from '@/scripts/lang.js';
import * as swos from '@/scripts/operations.js';
@@ -26,8 +27,15 @@ globalThis.addEventListener('activate', ev => {
);
});
-function offlineContentHTML(): string {
- return `Offline. Service Worker @${_VERSION_} `;
+async function offlineContentHTML() {
+ const i18n = await (swLang.i18n ?? swLang.fetchLocale()) as Partial>;
+ const messages = {
+ title: i18n.ts?._offlineScreen?.title ?? 'Offline - Could not connect to server',
+ header: i18n.ts?._offlineScreen?.header ?? 'Could not connect to server',
+ reload: i18n.ts?.reload ?? 'Reload',
+ };
+
+ return `${messages.title}${messages.header}
v${_VERSION_}
`;
}
globalThis.addEventListener('fetch', ev => {
@@ -43,8 +51,9 @@ globalThis.addEventListener('fetch', ev => {
if (!isHTMLRequest) return;
ev.respondWith(
fetch(ev.request)
- .catch(() => {
- return new Response(offlineContentHTML(), {
+ .catch(async () => {
+ const html = await offlineContentHTML();
+ return new Response(html, {
status: 200,
headers: {
'content-type': 'text/html',
--
cgit v1.2.3-freya