tui: fix model state persistence when model store is not ready
This commit is contained in:
@@ -113,8 +113,16 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const file = Bun.file(path.join(Global.Path.state, "model.json"))
|
const file = Bun.file(path.join(Global.Path.state, "model.json"))
|
||||||
|
const state = {
|
||||||
|
pending: false,
|
||||||
|
}
|
||||||
|
|
||||||
function save() {
|
function save() {
|
||||||
|
if (!modelStore.ready) {
|
||||||
|
state.pending = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
state.pending = false
|
||||||
Bun.write(
|
Bun.write(
|
||||||
file,
|
file,
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
@@ -135,6 +143,7 @@ export const { use: useLocal, provider: LocalProvider } = createSimpleContext({
|
|||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setModelStore("ready", true)
|
setModelStore("ready", true)
|
||||||
|
if (state.pending) save()
|
||||||
})
|
})
|
||||||
|
|
||||||
const args = useArgs()
|
const args = useArgs()
|
||||||
|
|||||||
Reference in New Issue
Block a user