refactor: Add sync process
This commit is contained in:
@@ -33,18 +33,6 @@ export const CurrentChat = writable(null) as Writable<Chat>
|
|||||||
export const CurrentUsername = writable('') as Writable<string>
|
export const CurrentUsername = writable('') as Writable<string>
|
||||||
export const CurrentUserIcon = writable('') as Writable<string>
|
export const CurrentUserIcon = writable('') as Writable<string>
|
||||||
export const CurrentShowMemoryLimit = writable(false) as Writable<boolean>
|
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 ShowVN = writable(false)
|
||||||
export const SettingsMenuIndex = writable(-1)
|
export const SettingsMenuIndex = writable(-1)
|
||||||
export const CurrentVariablePointer = writable({} as {[key:string]: string|number|boolean})
|
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(){
|
async function preInit(){
|
||||||
await sleep(1)
|
await sleep(1)
|
||||||
|
trySync()
|
||||||
function updateCurrentCharacter(){
|
function updateCurrentCharacter(){
|
||||||
|
|
||||||
const db = get(DataBase)
|
const db = get(DataBase)
|
||||||
|
|||||||
Reference in New Issue
Block a user