Fixed bug that caused crash when using start all/stop all button when chat bot not initialized; changed chat bot message active state to only use wails events

This commit is contained in:
tyler 2024-02-10 11:01:53 -05:00
parent 5c3fa663a1
commit cdbaf8ff14
2 changed files with 13 additions and 4 deletions

10
app.go
View file

@ -339,6 +339,10 @@ func (a *App) LoginChatBot(cid string, username string, password string, streamU
}
func (a *App) StopAllChatBot(cid string) error {
if a.cb == nil {
return fmt.Errorf("Chat bot not initialized.")
}
err := a.cb.StopAllMessages()
if err != nil {
a.logError.Println("error stopping all chat bot messages:", err)
@ -349,6 +353,10 @@ func (a *App) StopAllChatBot(cid string) error {
}
func (a *App) StartAllChatBot(cid string) error {
if a.cb == nil {
return fmt.Errorf("Chat bot not initialized.")
}
err := a.cb.StartAllMessages()
if err != nil {
a.logError.Println("error starting all chat bot messages:", err)
@ -365,7 +373,7 @@ func (a *App) UpdateChatBotUrl(cid string, streamUrl string) error {
defer a.cfgMu.Unlock()
if a.cb == nil {
return fmt.Errorf("Chat bot not initalized.")
return fmt.Errorf("Chat bot not initialized.")
}
err := a.resetChatBot()

View file

@ -65,7 +65,8 @@ function StreamChatBot(props) {
export default StreamChatBot;
function StreamChatItem(props) {
const [active, setActive] = useState(props.isMessageActive(props.chat.id));
// const [active, setActive] = useState(props.isMessageActive(props.chat.id));
const [active, setActive] = useState(false);
const [error, setError] = useState('');
const [filename, setFilename] = useState(props.chat.text_file);
@ -75,13 +76,13 @@ function StreamChatItem(props) {
setFilename(name);
});
}
setActive(props.isMessageActive(props.chat.id));
// setActive(props.isMessageActive(props.chat.id));
}, [props]);
const changeActive = (bool) => {
// console.log('ChangeActive:', bool);
// props.chat.active = bool;
props.activateMessage(props.chat.id, bool);
// props.activateMessage(props.chat.id, bool);
setActive(bool);
};