Skip to content

Commit

Permalink
Load winch settings when re-opening settings tab
Browse files Browse the repository at this point in the history
  • Loading branch information
xen-42 committed Jul 12, 2024
1 parent b16ff94 commit 11c0d66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/components/appcontext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion src/components/settings/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 === "") {
Expand Down Expand Up @@ -109,7 +118,6 @@ export const Settings = (props: {path_correct?: boolean}) => {
onChange={(e) => {
const value = e.target.value;
setPath(value);

}}
value={path}
/>
Expand Down

0 comments on commit 11c0d66

Please sign in to comment.