refactor: Add sync process

This commit is contained in:
kwaroran
2024-06-24 01:41:26 +09:00
parent 6e9940df2d
commit 94b1fe4d32

View File

@@ -33,18 +33,6 @@ export const CurrentChat = writable(null) as Writable<Chat>
export const CurrentUsername = writable('') as Writable<string>
export const CurrentUserIcon = writable('') as Writable<string>
export const CurrentShowMemoryLimit = writable(false) as Writable<boolean>
try {
let db = get(DataBase)
let currentChar = get(selectedCharID)
let currentCharacter = db.characters ? (db.characters[currentChar]) : null
let currentChat = currentCharacter ? (currentCharacter.chats[currentCharacter.chatPage]) : null
CurrentCharacter.set(structuredClone(currentCharacter))
CurrentSimpleCharacter.set(createSimpleCharacter(currentCharacter))
CurrentChat.set(structuredClone(currentChat))
CurrentUsername.set(db.username)
CurrentUserIcon.set(db.userIcon)
CurrentShowMemoryLimit.set(db.showMemoryLimit)
} catch (error) {}
export const ShowVN = writable(false)
export const SettingsMenuIndex = writable(-1)
export const CurrentVariablePointer = writable({} as {[key:string]: string|number|boolean})
@@ -70,9 +58,26 @@ function createSimpleCharacter(char:character|groupChat){
}
function trySync(){
try {
let db = get(DataBase)
let currentChar = get(selectedCharID)
let currentCharacter = db.characters ? (db.characters[currentChar]) : null
let currentChat = currentCharacter ? (currentCharacter.chats[currentCharacter.chatPage]) : null
CurrentCharacter.set(structuredClone(currentCharacter))
CurrentSimpleCharacter.set(createSimpleCharacter(currentCharacter))
CurrentChat.set(structuredClone(currentChat))
CurrentUsername.set(db.username)
CurrentUserIcon.set(db.userIcon)
CurrentShowMemoryLimit.set(db.showMemoryLimit)
} catch (error) {}
}
trySync()
async function preInit(){
await sleep(1)
await sleep(1)
trySync()
function updateCurrentCharacter(){
const db = get(DataBase)