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']");
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 =
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;

View File

@ -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()
}