Skip to content

Commit 13ea00f

Browse files
Use localStorage config if available, fallback to server config if empty; reset button always reloads from server
1 parent 34ddd7b commit 13ea00f

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

tools/server/public/index.html.gz

137 Bytes
Binary file not shown.

tools/server/webui/src/components/SettingDialog.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { useState } from 'react';
22
import { useAppContext } from '../utils/app.context';
3-
import { CONFIG_INFO } from '../utils/initConfig';
4-
import { isDev } from '../utils/initConfig';
3+
import { CONFIG_INFO, getServerDefaultConfig, isDev } from '../utils/initConfig';
54
import StorageUtils from '../utils/storage';
65
import { classNames, isBoolean, isNumeric, isString } from '../utils/misc';
76
import {
@@ -272,9 +271,17 @@ export default function SettingDialog({
272271
// clone the config object to prevent direct mutation
273272
const [localConfig, setLocalConfig] = useState<AppConfig>({ ...config });
274273

275-
const resetConfig = () => {
276-
if (window.confirm('Are you sure you want to reset all settings?')) {
277-
setLocalConfig({ ...config });
274+
const resetConfig = async () => {
275+
if (!window.confirm('Reset all settings from server defaults?')) return;
276+
277+
try {
278+
const cfg = await getServerDefaultConfig(config.apiKey);
279+
StorageUtils.setConfig(cfg);
280+
setLocalConfig({ ...cfg });
281+
console.info('[Config] Reset from server config');
282+
} catch (err) {
283+
console.error('[Config] Failed to fetch server defaults:', err);
284+
alert('Failed to fetch server default config.');
278285
}
279286
};
280287

tools/server/webui/src/utils/app.context.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,19 @@ export const AppContextProvider = ({
106106
.then(async (props) => {
107107
console.debug('Server props:', props);
108108
setServerProps(props);
109-
const cfg = await getServerDefaultConfig(config.apiKey);
110-
StorageUtils.setConfig(cfg);
111-
setConfig(cfg);
109+
110+
const hasUserConfig =
111+
localStorage.getItem('config') &&
112+
Object.keys(JSON.parse(localStorage.getItem('config') || '{}')).length > 0;
113+
114+
if (!hasUserConfig) {
115+
const cfg = await getServerDefaultConfig(config.apiKey);
116+
StorageUtils.setConfig(cfg);
117+
setConfig(cfg);
118+
console.info('[Config] Loaded from server (no local config found)');
119+
} else {
120+
console.info('[Config] Using localStorage config');
121+
}
112122
})
113123
.catch((err) => {
114124
console.error(err);

0 commit comments

Comments
 (0)