fix config loader

This commit is contained in:
Zhang Minghan 2024-01-03 14:06:50 +08:00
parent 11a4f3dd2f
commit 6dae6c448e
3 changed files with 20 additions and 11 deletions

View File

@ -232,3 +232,14 @@ export function updateFavicon(url: string) {
const link = document.querySelector("link[rel*='icon']"); const link = document.querySelector("link[rel*='icon']");
return link && link.setAttribute("href", url); 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;
}

View File

@ -1,4 +1,4 @@
import { updateFavicon } from "@/utils/dom.ts"; import { updateDocumentTitle, updateFavicon } from "@/utils/dom.ts";
export let appName = export let appName =
localStorage.getItem("app_name") || localStorage.getItem("app_name") ||
@ -20,7 +20,7 @@ export const deeptrainAppName = import.meta.env.VITE_DEEPTRAIN_APP || "chatnio";
export const deeptrainApiEndpoint = export const deeptrainApiEndpoint =
import.meta.env.VITE_DEEPTRAIN_API_ENDPOINT || "https://api.deeptrain.net"; import.meta.env.VITE_DEEPTRAIN_API_ENDPOINT || "https://api.deeptrain.net";
document.title = appName; updateDocumentTitle(appName);
updateFavicon(appLogo); updateFavicon(appLogo);
export function getDev(): boolean { export function getDev(): boolean {
@ -65,22 +65,18 @@ export function setAppName(name: string): void {
/** /**
* set the app name in localStorage * set the app name in localStorage
*/ */
name = name.trim(); name = name.trim() || "Chat Nio";
if (name.length === 0) return;
localStorage.setItem("app_name", name); localStorage.setItem("app_name", name);
appName = name; appName = name;
document.title = name; updateDocumentTitle(name);
} }
export function setAppLogo(logo: string): void { export function setAppLogo(logo: string): void {
/** /**
* set the app logo in localStorage * set the app logo in localStorage
*/ */
logo = logo.trim(); logo = logo.trim() || "/favicon.ico";
if (logo.length === 0) return;
localStorage.setItem("app_logo", logo); localStorage.setItem("app_logo", logo);
appLogo = logo; appLogo = logo;

View File

@ -13,8 +13,8 @@ type ApiInfo struct {
} }
type generalState struct { type generalState struct {
Title string `json:"title" mapstructure:"title"` Title string `json:"title" mapstructure:"title,omitempty"`
Logo string `json:"logo" mapstructure:"logo"` Logo string `json:"logo" mapstructure:"logo,omitempty"`
Backend string `json:"backend" mapstructure:"backend"` Backend string `json:"backend" mapstructure:"backend"`
} }
@ -52,6 +52,8 @@ func (c *SystemConfig) SaveConfig() error {
// fix: import cycle not allowed // fix: import cycle not allowed
{ {
viper.Set("system.general.backend", c.GetBackend()) 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() return viper.WriteConfig()
} }