diff --git a/app/src/utils/dom.ts b/app/src/utils/dom.ts index 2689190..bd063b7 100644 --- a/app/src/utils/dom.ts +++ b/app/src/utils/dom.ts @@ -232,3 +232,14 @@ export function updateFavicon(url: string) { const link = document.querySelector("link[rel*='icon']"); return link && link.setAttribute("href", url); } + +export function updateDocumentTitle(title: string) { + /** + * Update document title + * @param title Document title + * @example + * updateDocumentTitle("Hello world!"); + */ + + document.title = title; +} diff --git a/app/src/utils/env.ts b/app/src/utils/env.ts index 8d94d19..9ad3364 100644 --- a/app/src/utils/env.ts +++ b/app/src/utils/env.ts @@ -1,4 +1,4 @@ -import { updateFavicon } from "@/utils/dom.ts"; +import { updateDocumentTitle, updateFavicon } from "@/utils/dom.ts"; export let appName = localStorage.getItem("app_name") || @@ -20,7 +20,7 @@ export const deeptrainAppName = import.meta.env.VITE_DEEPTRAIN_APP || "chatnio"; export const deeptrainApiEndpoint = import.meta.env.VITE_DEEPTRAIN_API_ENDPOINT || "https://api.deeptrain.net"; -document.title = appName; +updateDocumentTitle(appName); updateFavicon(appLogo); export function getDev(): boolean { @@ -65,22 +65,18 @@ export function setAppName(name: string): void { /** * set the app name in localStorage */ - name = name.trim(); - if (name.length === 0) return; - + name = name.trim() || "Chat Nio"; localStorage.setItem("app_name", name); appName = name; - document.title = name; + updateDocumentTitle(name); } export function setAppLogo(logo: string): void { /** * set the app logo in localStorage */ - logo = logo.trim(); - if (logo.length === 0) return; - + logo = logo.trim() || "/favicon.ico"; localStorage.setItem("app_logo", logo); appLogo = logo; diff --git a/channel/system.go b/channel/system.go index 1c104db..fe50950 100644 --- a/channel/system.go +++ b/channel/system.go @@ -13,8 +13,8 @@ type ApiInfo struct { } type generalState struct { - Title string `json:"title" mapstructure:"title"` - Logo string `json:"logo" mapstructure:"logo"` + Title string `json:"title" mapstructure:"title,omitempty"` + Logo string `json:"logo" mapstructure:"logo,omitempty"` Backend string `json:"backend" mapstructure:"backend"` } @@ -52,6 +52,8 @@ func (c *SystemConfig) SaveConfig() error { // fix: import cycle not allowed { viper.Set("system.general.backend", c.GetBackend()) + viper.Set("system.general.title", c.General.Title) + viper.Set("system.general.logo", c.General.Logo) } return viper.WriteConfig() }