feat: check the server on launch and remember the selected model
The chat showed 'Server offline' until the user opened Settings, and the selected model was forgotten on every restart. useAutoConnect fetches the models once after the persisted settings are restored; activeModelId is now persisted.
This commit is contained in:
1 parent
1a3ce9ccec
commit
541aefd7e4
5 files changed
+72
-2
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useAppStore } from '../store/useAppStore';
|
||||
import { useLMStudio } from './useLMStudio';
|
||||
|
||||
/**
|
||||
* Checks the server once when the app opens, after the saved settings have been
|
||||
* restored, so the connection badge and model list are not stale until the user
|
||||
* visits Settings.
|
||||
*/
|
||||
export function useAutoConnect() {
|
||||
const { fetchModels } = useLMStudio();
|
||||
|
||||
useEffect(() => {
|
||||
const { persist } = useAppStore;
|
||||
if (persist.hasHydrated()) {
|
||||
void fetchModels();
|
||||
return;
|
||||
}
|
||||
return persist.onFinishHydration(() => void fetchModels());
|
||||
// Mount only: later checks are triggered by the user (model selector, Settings).
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
}
|
||||
Reference in new issue
Block a user