11import { CancelFn } from "@/lib/tsutils" ;
22import { useEffect } from "react" ;
3- import { CreateCustomCharacter , CreatePlaylist , DeleteCharacter , DeleteModById , DeletePlaylistById , DeleteTextureById , InsertTag , InsertTagForAllModsByCharacterIds , RenameMod , RenameTexture , SelectCharactersByGame , SelectCharacterWithModsTagsAndTextures , SelectClosestCharacter , SelectModById , SelectModsByCharacterName , SelectModsByGbId , SelectPlaylistWithModsAndTags , UpdateDisableAllModsByGame , UpdateModEnabledById , UpdateModGbId , UpdateModImages , UpdateModsEnabledFromSlice , UpdatePlaylistName , UpdateTextureEnabledById } from "wailsjs/go/dbh/DbHelper" ;
3+ import { CreateCustomCharacter , CreatePlaylist , DeleteCharacter , DeleteModById , DeletePlaylistById , DeleteTag , DeleteTextureById , InsertTag , InsertTagForAllModsByCharacterIds , RenameMod , RenameTexture , SelectCharactersByGame , SelectCharacterWithModsTagsAndTextures , SelectClosestCharacter , SelectModById , SelectModsByCharacterName , SelectModsByGbId , SelectPlaylistWithModsAndTags , SelectTagsByModId , UpdateDisableAllModsByGame , UpdateModEnabledById , UpdateModGbId , UpdateModImages , UpdateModsEnabledFromSlice , UpdatePlaylistName , UpdateTextureEnabledById } from "wailsjs/go/dbh/DbHelper" ;
44import { SplitTexture } from "wailsjs/go/main/App" ;
5- import { EventsEmit , EventsOn , LogDebug } from "wailsjs/runtime/runtime" ;
5+ import { EventsEmit , EventsOn , LogDebug , LogError } from "wailsjs/runtime/runtime" ;
66
77
88type DBKey = "characters" | "mods" | "tags" | "playlist" | "all"
@@ -11,20 +11,31 @@ const DBEvent = "DB_EVENT"
1111type DBEventData = DBKey [ ]
1212
1313const subscribeToDbUpdates = ( key : DBKey [ ] | DBKey , callback : ( ) => void , runOnStart : boolean = false ) : CancelFn => {
14+ const runCallbackCatching = ( ) => {
15+ try {
16+ callback ( )
17+ } catch ( e : any ) {
18+ if ( e instanceof Error ) {
19+ LogError ( "subscribe listener failed with unhandled Error: " + e . message ) ;
20+ } else {
21+ LogError ( "subscribe listener failed with unknown error" + e ) ;
22+ }
23+ }
24+ }
1425
1526 if ( runOnStart ) {
16- callback ( )
27+ runCallbackCatching ( )
1728 }
1829
1930 return EventsOn ( DBEvent , ( keys : DBEventData ) => {
2031 LogDebug ( "received DBEVENT event keys=" + keys )
2132 if ( typeof key === 'string' ) {
2233 if ( key === "all" || keys . includes ( key ) ) {
23- callback ( )
34+ runCallbackCatching ( )
2435 }
2536 } else {
2637 if ( key . any ( ( k ) => k === "all" || keys . includes ( k ) ) ) {
27- callback ( )
38+ runCallbackCatching ( )
2839 }
2940 }
3041 } )
@@ -43,8 +54,8 @@ const broadcastCharacterUpdate = () => EventsEmit(DBEvent, ["characters"])
4354const broadcastModsUpdate = ( ) => EventsEmit ( DBEvent , [ "mods" ] )
4455const broadcastTagsUpdate = ( ) => EventsEmit ( DBEvent , [ "tags" ] )
4556const broadcastPlaylistUpdate = ( ) => EventsEmit ( DBEvent , [ "playlist" ] )
46- //const broadcastMultiUpdate = (keys: DBKey[]) => EventsEmit(DBEvent, keys)
4757
58+ //const broadcastMultiUpdate = (keys: DBKey[]) => EventsEmit(DBEvent, keys)
4859const DB = {
4960 onValueChangedListener : subscribeToDbUpdates ,
5061 deleteMod : async ( id : number ) => {
@@ -121,6 +132,12 @@ const DB = {
121132 } ,
122133 updatePlaylistName : ( id : number , name : string ) => {
123134 return UpdatePlaylistName ( id , name ) . then ( broadcastPlaylistUpdate )
135+ } ,
136+ selectTagsByModId : ( modId : number ) => {
137+ return SelectTagsByModId ( modId )
138+ } ,
139+ deleteTag : ( modId : number , name : string ) => {
140+ return DeleteTag ( name , modId ) . then ( broadcastTagsUpdate )
124141 }
125142}
126143
0 commit comments