From 94b1fe4d32eec72e6b9caf23bd478678ed4241c3 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Mon, 24 Jun 2024 01:41:26 +0900 Subject: [PATCH] refactor: Add sync process --- src/ts/stores.ts | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/ts/stores.ts b/src/ts/stores.ts index 46ff593e..61e15a89 100644 --- a/src/ts/stores.ts +++ b/src/ts/stores.ts @@ -33,18 +33,6 @@ export const CurrentChat = writable(null) as Writable export const CurrentUsername = writable('') as Writable export const CurrentUserIcon = writable('') as Writable export const CurrentShowMemoryLimit = writable(false) as Writable -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)