From ffe4b471e927ed516b3c9fd48e81714323ce9b00 Mon Sep 17 00:00:00 2001 From: kwaroran Date: Mon, 24 Jun 2024 01:09:35 +0900 Subject: [PATCH] chore: Update svelte/store imports and initialize writable values --- src/main.ts | 1 + src/ts/stores.ts | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main.ts b/src/main.ts index f5d95a04..958a7f29 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,6 @@ import "./styles.css"; import "core-js/actual" +import "./ts/storage/database" import App from "./App.svelte"; import { loadData } from "./ts/storage/globalApi"; import { initHotkey } from "./ts/hotkey"; diff --git a/src/ts/stores.ts b/src/ts/stores.ts index 7809fa19..b7cdbdc0 100644 --- a/src/ts/stores.ts +++ b/src/ts/stores.ts @@ -1,5 +1,5 @@ -import { get, writable } from "svelte/store"; -import { DataBase, type character, type groupChat } from "./storage/database"; +import { get, writable, type Writable } from "svelte/store"; +import { DataBase, type Chat, type character, type groupChat } from "./storage/database"; import { isEqual } from "lodash"; import type { simpleCharacterArgument } from "./parser"; @@ -30,12 +30,20 @@ let db = get(DataBase) let currentChar = get(selectedCharID) let currentCharacter = db.characters ? (db.characters[currentChar]) : null let currentChat = currentCharacter ? (currentCharacter.chats[currentCharacter.chatPage]) : null -export const CurrentCharacter = writable(structuredClone(currentCharacter)) -export const CurrentSimpleCharacter = writable(createSimpleCharacter(currentCharacter)) -export const CurrentChat = writable(structuredClone(currentChat)) -export const CurrentUsername = writable(db.username) -export const CurrentUserIcon = writable(db.userIcon) -export const CurrentShowMemoryLimit = writable(db.showMemoryLimit) +export const CurrentCharacter = writable(null) as Writable +export const CurrentSimpleCharacter = writable(null) as Writable +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 { + 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})