Fix store making vite crash on hmr
This commit is contained in:
101
src/ts/alert.ts
101
src/ts/alert.ts
@@ -4,8 +4,9 @@ import { language } from "../lang"
|
||||
import { isNodeServer, isTauri } from "./storage/globalApi"
|
||||
import { Capacitor } from "@capacitor/core"
|
||||
import { getDatabase, type MessageGenerationInfo } from "./storage/database.svelte"
|
||||
import { alertStore as alertStoreImported } from "./stores"
|
||||
|
||||
interface alertData{
|
||||
export interface alertData{
|
||||
type: 'error'|'normal'|'none'|'ask'|'wait'|'selectChar'
|
||||
|'input'|'toast'|'wait2'|'markdown'|'select'|'login'
|
||||
|'tos'|'cardexport'|'requestdata'|'addchar'|'hypaV2'|'selectModule'
|
||||
@@ -14,16 +15,16 @@ interface alertData{
|
||||
submsg?: string
|
||||
}
|
||||
|
||||
|
||||
export const alertStore = writable({
|
||||
type: 'none',
|
||||
msg: 'n',
|
||||
} as alertData)
|
||||
type AlertGenerationInfoStoreData = {
|
||||
genInfo: MessageGenerationInfo,
|
||||
idx: number
|
||||
}
|
||||
export const alertGenerationInfoStore = writable<AlertGenerationInfoStoreData>(null)
|
||||
export const alertStore = {
|
||||
set: (d:alertData) => {
|
||||
alertStoreImported.set(d)
|
||||
}
|
||||
}
|
||||
|
||||
export function alertError(msg:string){
|
||||
console.error(msg)
|
||||
@@ -55,7 +56,7 @@ export function alertError(msg:string){
|
||||
(!isTauri && !isNodeServer && !Capacitor.isNativePlatform()) ? language.errors.networkFetchWeb : language.errors.networkFetch
|
||||
}
|
||||
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'error',
|
||||
'msg': msg,
|
||||
'submsg': submsg
|
||||
@@ -63,19 +64,19 @@ export function alertError(msg:string){
|
||||
}
|
||||
|
||||
export function alertNormal(msg:string){
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'normal',
|
||||
'msg': msg
|
||||
})
|
||||
}
|
||||
|
||||
export async function alertNormalWait(msg:string){
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'normal',
|
||||
'msg': msg
|
||||
})
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
@@ -83,73 +84,73 @@ export async function alertNormalWait(msg:string){
|
||||
}
|
||||
|
||||
export async function alertAddCharacter() {
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'addchar',
|
||||
'msg': language.addCharacter
|
||||
})
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
}
|
||||
|
||||
return get(alertStore).msg
|
||||
return get(alertStoreImported).msg
|
||||
}
|
||||
|
||||
export async function alertChatOptions() {
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'chatOptions',
|
||||
'msg': language.chatOptions
|
||||
})
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
}
|
||||
|
||||
return parseInt(get(alertStore).msg)
|
||||
return parseInt(get(alertStoreImported).msg)
|
||||
}
|
||||
|
||||
export async function alertLogin(){
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'login',
|
||||
'msg': 'login'
|
||||
})
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
}
|
||||
|
||||
return get(alertStore).msg
|
||||
return get(alertStoreImported).msg
|
||||
}
|
||||
|
||||
export async function alertSelect(msg:string[]){
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'select',
|
||||
'msg': msg.join('||')
|
||||
})
|
||||
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
}
|
||||
|
||||
return get(alertStore).msg
|
||||
return get(alertStoreImported).msg
|
||||
}
|
||||
|
||||
export async function alertErrorWait(msg:string){
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'wait2',
|
||||
'msg': msg
|
||||
})
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
@@ -157,25 +158,25 @@ export async function alertErrorWait(msg:string){
|
||||
}
|
||||
|
||||
export function alertMd(msg:string){
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'markdown',
|
||||
'msg': msg
|
||||
})
|
||||
}
|
||||
|
||||
export function doingAlert(){
|
||||
return get(alertStore).type !== 'none' && get(alertStore).type !== 'toast'
|
||||
return get(alertStoreImported).type !== 'none' && get(alertStoreImported).type !== 'toast'
|
||||
}
|
||||
|
||||
export function alertToast(msg:string){
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'toast',
|
||||
'msg': msg
|
||||
})
|
||||
}
|
||||
|
||||
export function alertWait(msg:string){
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'wait',
|
||||
'msg': msg
|
||||
})
|
||||
@@ -184,61 +185,61 @@ export function alertWait(msg:string){
|
||||
|
||||
|
||||
export function alertClear(){
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'none',
|
||||
'msg': ''
|
||||
})
|
||||
}
|
||||
|
||||
export async function alertSelectChar(){
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'selectChar',
|
||||
'msg': ''
|
||||
})
|
||||
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
}
|
||||
|
||||
return get(alertStore).msg
|
||||
return get(alertStoreImported).msg
|
||||
}
|
||||
|
||||
export async function alertConfirm(msg:string){
|
||||
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'ask',
|
||||
'msg': msg
|
||||
})
|
||||
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
}
|
||||
|
||||
return get(alertStore).msg === 'yes'
|
||||
return get(alertStoreImported).msg === 'yes'
|
||||
}
|
||||
|
||||
export async function alertCardExport(type:string = ''){
|
||||
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'cardexport',
|
||||
'msg': '',
|
||||
'submsg': type
|
||||
})
|
||||
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
}
|
||||
|
||||
return JSON.parse(get(alertStore).msg) as {
|
||||
return JSON.parse(get(alertStoreImported).msg) as {
|
||||
type: string,
|
||||
type2: string,
|
||||
}
|
||||
@@ -250,19 +251,19 @@ export async function alertTOS(){
|
||||
return true
|
||||
}
|
||||
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'tos',
|
||||
'msg': 'tos'
|
||||
})
|
||||
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
}
|
||||
|
||||
if(get(alertStore).msg === 'yes'){
|
||||
if(get(alertStoreImported).msg === 'yes'){
|
||||
localStorage.setItem('tos2', 'true')
|
||||
return true
|
||||
}
|
||||
@@ -272,48 +273,48 @@ export async function alertTOS(){
|
||||
|
||||
export async function alertInput(msg:string){
|
||||
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'input',
|
||||
'msg': msg
|
||||
})
|
||||
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
}
|
||||
|
||||
return get(alertStore).msg
|
||||
return get(alertStoreImported).msg
|
||||
}
|
||||
|
||||
export async function alertModuleSelect(){
|
||||
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'selectModule',
|
||||
'msg': ''
|
||||
})
|
||||
|
||||
while(true){
|
||||
if (get(alertStore).type === 'none'){
|
||||
if (get(alertStoreImported).type === 'none'){
|
||||
break
|
||||
}
|
||||
await sleep(10)
|
||||
await sleep(20)
|
||||
}
|
||||
|
||||
return get(alertStore).msg
|
||||
return get(alertStoreImported).msg
|
||||
}
|
||||
|
||||
export function alertRequestData(info:AlertGenerationInfoStoreData){
|
||||
alertGenerationInfoStore.set(info)
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'requestdata',
|
||||
'msg': info.genInfo.generationId ?? 'none'
|
||||
})
|
||||
}
|
||||
|
||||
export function showHypaV2Alert(){
|
||||
alertStore.set({
|
||||
alertStoreImported.set({
|
||||
'type': 'hypaV2',
|
||||
'msg': ""
|
||||
})
|
||||
|
||||
@@ -8,6 +8,7 @@ import { convertExternalLorebook } from "./lorebook.svelte"
|
||||
import { decodeRPack, encodeRPack } from "../rpack/rpack_bg"
|
||||
import { convertImage } from "../parser.svelte"
|
||||
import { Capacitor } from "@capacitor/core"
|
||||
import { HideIconStore, moduleBackgroundEmbedding } from "../stores"
|
||||
|
||||
export interface RisuModule{
|
||||
name: string
|
||||
@@ -392,4 +393,39 @@ export async function applyModule() {
|
||||
setCurrentCharacter(currentChar)
|
||||
|
||||
alertNormal(language.successApplyModule)
|
||||
}
|
||||
|
||||
let lastGlobalEnabledModules: string[] = []
|
||||
let lastChatEnabledModules: string[] = []
|
||||
let characterHideIcon = false
|
||||
|
||||
function onModuleUpdate(){
|
||||
if(!Array.isArray(lastGlobalEnabledModules)){
|
||||
lastGlobalEnabledModules = []
|
||||
}
|
||||
if(!Array.isArray(lastChatEnabledModules)){
|
||||
lastChatEnabledModules = []
|
||||
}
|
||||
|
||||
const m = getModules()
|
||||
|
||||
let moduleHideIcon = false
|
||||
let backgroundEmbedding = ''
|
||||
m.forEach((module) => {
|
||||
if(!module){
|
||||
return
|
||||
}
|
||||
|
||||
if(module.hideIcon){
|
||||
moduleHideIcon = true
|
||||
}
|
||||
if(module.backgroundEmbedding){
|
||||
backgroundEmbedding += '\n' + module.backgroundEmbedding + '\n'
|
||||
}
|
||||
})
|
||||
|
||||
if(backgroundEmbedding){
|
||||
moduleBackgroundEmbedding.set(backgroundEmbedding)
|
||||
}
|
||||
HideIconStore.set(characterHideIcon || moduleHideIcon)
|
||||
}
|
||||
@@ -15,7 +15,6 @@ import type { OobaChatCompletionRequestParams } from '../model/ooba';
|
||||
export const DBState = $state({
|
||||
db: {} as any as Database
|
||||
})
|
||||
export const loadedStore = writable(false)
|
||||
export let appVer = "137.1.0"
|
||||
export let webAppSubVer = '-svelte5-exp'
|
||||
|
||||
|
||||
@@ -13,10 +13,10 @@ import { v4 as uuidv4, v4 } from 'uuid';
|
||||
import { appDataDir, join } from "@tauri-apps/api/path";
|
||||
import { get } from "svelte/store";
|
||||
import {open} from '@tauri-apps/plugin-shell'
|
||||
import { loadedStore, setDatabase, type Database, defaultSdDataFunc, getDatabase } from "./database.svelte";
|
||||
import { setDatabase, type Database, defaultSdDataFunc, getDatabase } from "./database.svelte";
|
||||
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
|
||||
import { checkRisuUpdate } from "../update";
|
||||
import { MobileGUI, botMakerMode, selectedCharID } from "../stores";
|
||||
import { MobileGUI, botMakerMode, selectedCharID, loadedStore } from "../stores";
|
||||
import { loadPlugins } from "../plugins/plugins";
|
||||
import { alertConfirm, alertError, alertNormal, alertNormalWait, alertSelect, alertTOS, alertWait } from "../alert";
|
||||
import { checkDriverInit, syncDrive } from "../drive/drive";
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { writable, type Writable } from "svelte/store";
|
||||
import { getDatabase, type Chat, type character, type groupChat } from "./storage/database.svelte";
|
||||
import type { character, groupChat } from "./storage/database.svelte";
|
||||
import type { simpleCharacterArgument } from "./parser.svelte";
|
||||
import { sleep } from "./util";
|
||||
import { getModules } from "./process/modules";
|
||||
import type { alertData } from "./alert";
|
||||
|
||||
function updateSize(){
|
||||
SizeStore.set({
|
||||
@@ -16,6 +15,9 @@ export const SizeStore = writable({
|
||||
w: 0,
|
||||
h: 0
|
||||
})
|
||||
|
||||
const t = 'https://raw.githubusercontent.com/ProjectAliceDev/ProjectAliceDev.github.io/master/'
|
||||
export const loadedStore = writable(false)
|
||||
export const DynamicGUI = writable(false)
|
||||
export const sideBarClosing = writable(false)
|
||||
export const sideBarStore = writable(window.innerWidth > 1024)
|
||||
@@ -30,9 +32,6 @@ export const openPersonaList = writable(false)
|
||||
export const MobileGUI = writable(false)
|
||||
export const MobileGUIStack = writable(0)
|
||||
export const MobileSideBar = writable(0)
|
||||
//optimization
|
||||
export const CurrentShowMemoryLimit = writable(false) as Writable<boolean>
|
||||
|
||||
export const ShowVN = writable(false)
|
||||
export const SettingsMenuIndex = writable(-1)
|
||||
export const ReloadGUIPointer = writable(0)
|
||||
@@ -46,12 +45,10 @@ export const SafeModeStore = writable(false)
|
||||
export const MobileSearch = writable('')
|
||||
export const CharConfigSubMenu = writable(0)
|
||||
export const CustomGUISettingMenuStore = writable(false)
|
||||
|
||||
let lastGlobalEnabledModules: string[] = []
|
||||
let lastChatEnabledModules: string[] = []
|
||||
let moduleHideIcon = false
|
||||
let characterHideIcon = false
|
||||
|
||||
export const alertStore = writable({
|
||||
type: 'none',
|
||||
msg: 'n',
|
||||
} as alertData)
|
||||
|
||||
CustomCSSStore.subscribe((css) => {
|
||||
console.log(css)
|
||||
@@ -86,50 +83,5 @@ export function createSimpleCharacter(char:character|groupChat){
|
||||
|
||||
}
|
||||
|
||||
function trySync(){
|
||||
try {
|
||||
let db = getDatabase()
|
||||
CurrentShowMemoryLimit.set(db.showMemoryLimit)
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
trySync()
|
||||
|
||||
async function preInit(){
|
||||
await sleep(1)
|
||||
}
|
||||
|
||||
function onModuleUpdate(){
|
||||
if(!Array.isArray(lastGlobalEnabledModules)){
|
||||
lastGlobalEnabledModules = []
|
||||
}
|
||||
if(!Array.isArray(lastChatEnabledModules)){
|
||||
lastChatEnabledModules = []
|
||||
}
|
||||
|
||||
const m = getModules()
|
||||
|
||||
let moduleHideIcon = false
|
||||
let backgroundEmbedding = ''
|
||||
m.forEach((module) => {
|
||||
if(!module){
|
||||
return
|
||||
}
|
||||
|
||||
if(module.hideIcon){
|
||||
moduleHideIcon = true
|
||||
}
|
||||
if(module.backgroundEmbedding){
|
||||
backgroundEmbedding += '\n' + module.backgroundEmbedding + '\n'
|
||||
}
|
||||
})
|
||||
|
||||
if(backgroundEmbedding){
|
||||
moduleBackgroundEmbedding.set(backgroundEmbedding)
|
||||
}
|
||||
HideIconStore.set(characterHideIcon || moduleHideIcon)
|
||||
}
|
||||
|
||||
updateSize()
|
||||
window.addEventListener("resize", updateSize);
|
||||
preInit()
|
||||
window.addEventListener("resize", updateSize);
|
||||
Reference in New Issue
Block a user