diff --git a/fresh.gen.ts b/fresh.gen.ts index 699af60..6f00b52 100644 --- a/fresh.gen.ts +++ b/fresh.gen.ts @@ -21,6 +21,7 @@ import * as $15 from "./routes/api/thumbnail/[id].ts"; import * as $16 from "./routes/api/token.ts"; import * as $17 from "./routes/api/user.ts"; import * as $18 from "./routes/index.tsx"; +import * as $19 from "./routes/manifest.json.ts"; import * as $$0 from "./islands/Container.tsx"; import * as $$1 from "./islands/Settings.tsx"; import * as $$2 from "./islands/TaskManager.tsx"; @@ -46,6 +47,7 @@ const manifest = { "./routes/api/token.ts": $16, "./routes/api/user.ts": $17, "./routes/index.tsx": $18, + "./routes/manifest.json.ts": $19, }, islands: { "./islands/Container.tsx": $$0, diff --git a/islands/Container.tsx b/islands/Container.tsx index 4274ea0..c0e1849 100644 --- a/islands/Container.tsx +++ b/islands/Container.tsx @@ -22,6 +22,7 @@ import Login from "../components/Login.tsx"; export type ContainerProps = { i18n: I18NMap; + lang: string; }; enum DarkMode { @@ -117,6 +118,10 @@ export default class Container extends Component {
{t("common.title")} + diff --git a/routes/index.tsx b/routes/index.tsx index ee66e6a..1e956cf 100644 --- a/routes/index.tsx +++ b/routes/index.tsx @@ -36,7 +36,7 @@ export default function Index({ data }: PageProps) { : null} - + ); diff --git a/routes/manifest.json.ts b/routes/manifest.json.ts new file mode 100644 index 0000000..8d272a5 --- /dev/null +++ b/routes/manifest.json.ts @@ -0,0 +1,47 @@ +import { Handlers } from "$fresh/server.ts"; +import { get_i18nmap, i18n_handle_request } from "../server/i18ns.ts"; +import t, { i18n_map } from "../server/i18n.ts"; + +export const handler: Handlers = { + GET(req, _ctx) { + const i18n = i18n_handle_request(req); + if (typeof i18n === "string") { + const m = get_i18nmap(i18n); + i18n_map.value = m; + const base = `/?lang=${i18n}`; + const data = { + name: t("common.title"), + lang: i18n, + start_url: base, + display: "standalone", + icons: [ + { + src: "/favicon.ico", + sizes: "64x64", + "type": "image/vnd.microsoft.icon", + }, + { + src: "/logo.svg", + sizes: "any", + "type": "image/svg+xml", + }, + ], + scope: base, + shortcuts: [ + { + name: t("task.add"), + url: `${base}#/task_manager/new`, + }, + { + name: t("common.settings"), + url: `${base}#/settings`, + }, + ], + }; + return new Response(JSON.stringify(data), { + headers: { "Content-Type": "application/manifest+json" }, + }); + } + return i18n; + }, +}; diff --git a/static/favicon.ico b/static/favicon.ico new file mode 100644 index 0000000..1cfaaa2 Binary files /dev/null and b/static/favicon.ico differ diff --git a/static/logo.svg b/static/logo.svg new file mode 100644 index 0000000..ef2fbe4 --- /dev/null +++ b/static/logo.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/static/sw.ts b/static/sw.ts index f00fcb2..324d675 100644 --- a/static/sw.ts +++ b/static/sw.ts @@ -31,6 +31,8 @@ const CACHES = [ "/common.css", "/scrollBar.css", "/preact-material-components/style.css", + "/favicon.ico", + "/logo.svg", ]; function match_url(u: URL) { diff --git a/translation/en/common.jsonc b/translation/en/common.jsonc index 3ba8470..276ab80 100644 --- a/translation/en/common.jsonc +++ b/translation/en/common.jsonc @@ -6,5 +6,6 @@ "yes": "Yes", "no": "No", "darkmode": "Dark mode", - "submit": "Submit" + "submit": "Submit", + "settings": "Settings" } diff --git a/translation/zh-cn/common.jsonc b/translation/zh-cn/common.jsonc index 805857f..ffd4d76 100644 --- a/translation/zh-cn/common.jsonc +++ b/translation/zh-cn/common.jsonc @@ -6,5 +6,6 @@ "yes": "是", "no": "否", "darkmode": "夜间模式", - "submit": "提交" + "submit": "提交", + "settings": "设置" }