diff --git a/app/src/conf.ts b/app/src/conf.ts index 61a812f..5552116 100644 --- a/app/src/conf.ts +++ b/app/src/conf.ts @@ -32,7 +32,7 @@ export const supportModelConvertor: Record = { "Claude-2": "claude-1", "Claude-2-100k": "claude-2", // not claude-2-100k "SparkDesk 讯飞星火": "spark-desk", - "Palm2": "chat-bison-001", + Palm2: "chat-bison-001", }; export function login() { @@ -41,5 +41,3 @@ export function login() { axios.defaults.baseURL = rest_api; axios.defaults.headers.post["Content-Type"] = "application/json"; - -console.debug(`chatnio application (version: ${version})`); diff --git a/app/src/routes/ApiKey.tsx b/app/src/routes/ApiKey.tsx index 9b83541..71dec29 100644 --- a/app/src/routes/ApiKey.tsx +++ b/app/src/routes/ApiKey.tsx @@ -15,11 +15,13 @@ import { dialogSelector, setDialog, keySelector, + getApiKey, } from "../store/api.ts"; -import {Input} from "../components/ui/input.tsx"; -import {Copy, ExternalLink} from "lucide-react"; -import {useToast} from "../components/ui/use-toast.ts"; -import {copyClipboard} from "../utils.ts"; +import { Input } from "../components/ui/input.tsx"; +import { Copy, ExternalLink } from "lucide-react"; +import { useToast } from "../components/ui/use-toast.ts"; +import { copyClipboard, useEffectAsync } from "../utils.ts"; +import { selectInit } from "../store/auth.ts"; function Package() { const { t } = useTranslation(); @@ -27,6 +29,11 @@ function Package() { const open = useSelector(dialogSelector); const key = useSelector(keySelector); const { toast } = useToast(); + const init = useSelector(selectInit); + + useEffectAsync(async () => { + if (init) await getApiKey(dispatch); + }, [init]); async function copyKey() { await copyClipboard(key); diff --git a/app/src/service.ts b/app/src/service.ts index 6ddd8c7..c97718d 100644 --- a/app/src/service.ts +++ b/app/src/service.ts @@ -1,18 +1,23 @@ // @ts-ignore import { registerSW } from "virtual:pwa-register"; +import { version } from "./conf.ts"; export const updateSW = registerSW({ onRegisteredSW(url: string, registration: ServiceWorkerRegistration) { if (!(!registration.installing && navigator)) return; if ("connection" in navigator && !navigator.onLine) return; + console.debug( + "[service] checking for update (current version: %s)", + version, + ); fetch(url, { headers: { "Service-Worker": "script", "Cache-Control": "no-cache" }, cache: "no-store", }).then(async (resp) => { if (resp?.status === 200) { await registration.update(); - if (registration.onupdatefound) console.debug("update found"); + if (registration.onupdatefound) console.debug("[service] update found"); } }); }, diff --git a/app/src/store/api.ts b/app/src/store/api.ts index 2ae3b98..2f1d2d4 100644 --- a/app/src/store/api.ts +++ b/app/src/store/api.ts @@ -34,7 +34,7 @@ export default apiSlice.reducer; export const dialogSelector = (state: any): boolean => state.api.dialog; export const keySelector = (state: any): string => state.api.key; -export const getPackage = async (dispatch: AppDispatch) => { +export const getApiKey = async (dispatch: AppDispatch) => { const response = await getKey(); if (response.status) dispatch(setKey(response.key)); };