From 11c0d66ec7c3fb0c667ef3dbad090b57cc8fe2fd Mon Sep 17 00:00:00 2001 From: xen-42 Date: Fri, 12 Jul 2024 02:04:03 -0400 Subject: [PATCH] Load winch settings when re-opening settings tab --- src/components/appcontext.tsx | 12 +++++++----- src/components/settings/settings.tsx | 10 +++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/components/appcontext.tsx b/src/components/appcontext.tsx index 023ee80..8a1fcc2 100644 --- a/src/components/appcontext.tsx +++ b/src/components/appcontext.tsx @@ -176,11 +176,13 @@ export const AppProvider = (props: React.PropsWithChildren) => { } const updateWinchConfig = () => { - invoke("update_winch_config", { - "json": JSON.stringify(state.winchConfig, null, 2), - dredgePath: state.dredgePath}) - .then(reloadMods) - .catch(genericHandleError); + if (state.winchConfig != null) { + invoke("update_winch_config", { + "json": JSON.stringify(state.winchConfig, null, 2), + dredgePath: state.dredgePath}) + .then(reloadMods) + .catch(genericHandleError); + } } // fetch dredge path on mount diff --git a/src/components/settings/settings.tsx b/src/components/settings/settings.tsx index 69f40f2..dba06c6 100644 --- a/src/components/settings/settings.tsx +++ b/src/components/settings/settings.tsx @@ -14,8 +14,17 @@ export const Settings = (props: {path_correct?: boolean}) => { const context = useContext(AppContext); + const [shouldCheckWinchConfig, setshouldCheckWinchConfig] = useState(true); const [path, setPath] = useState(""); + // Opening the settings tab will try reloading everything: Checks if winch config has been setup by the modloader yet + useEffect(() => { + if (context.state.winchConfig == null && shouldCheckWinchConfig) { + context?.reloadMods() + } + setshouldCheckWinchConfig(false); + }); + // Fetch DREDGE path from context; only called once on load useEffect(() => { if (path === "") { @@ -109,7 +118,6 @@ export const Settings = (props: {path_correct?: boolean}) => { onChange={(e) => { const value = e.target.value; setPath(value); - }} value={path} />