(feature): uncheck mark if error appears

This commit is contained in:
TheDevisi
2026-04-11 11:45:23 +03:00
parent 4940ee1c1e
commit 4dbcae32f2
3 changed files with 15 additions and 3 deletions

View File

@@ -14,6 +14,7 @@ type Program struct {
App fyne.App
ParentWindow fyne.Window
RunString string
RunCheck *widget.Check
Config *Config
Cmd *exec.Cmd
}
@@ -47,7 +48,7 @@ func (p *Program) Run() {
p.settingsWindow()
})
runCheck := widget.NewCheck("Run", func(b bool) {
p.RunCheck = widget.NewCheck("Run", func(b bool) {
if b {
log("Run enabled")
p.olcrtcRun()
@@ -59,7 +60,7 @@ func (p *Program) Run() {
w.SetContent(container.NewBorder(
settingsBtn,
runCheck, nil, nil,
p.RunCheck, nil, nil,
))
log("Window created and running...")
w.ShowAndRun()

View File

@@ -12,6 +12,7 @@ func (p *Program) olcrtcRun() {
if p.RunString == "" {
log("ERROR: Run string is empty. Please configure settings first.")
p.showError(fmt.Errorf("run string is empty - please configure settings"))
p.MarkUncheck()
return
}
@@ -21,12 +22,14 @@ func (p *Program) olcrtcRun() {
log("ERROR: Failed to start olcrtc: %v", err)
p.showError(err)
p.Cmd = nil
p.MarkUncheck()
} else {
log("olcrtc process started (PID: %d)", p.Cmd.Process.Pid)
go func() {
err := p.Cmd.Wait()
err = p.Cmd.Wait()
if err != nil {
log("olcrtc process exited with error: %v", err)
p.MarkUncheck()
} else {
log("olcrtc process exited successfully")
}

View File

@@ -3,6 +3,7 @@ package main
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/theme"
@@ -68,3 +69,10 @@ func (p *Program) buildRunString(conferenceId, encryptionKey, socksPort, dns str
func (p *Program) showError(err error) {
dialog.ShowError(err, p.ParentWindow)
}
// fyne.Do used here to execute function in the main context frame
// we can just paste p.RunCheck.SetChecked(false) and that'll work. but if so
// there'll be a bunch of warnings(thread safety)
func (p *Program) MarkUncheck() {
fyne.Do(func() { p.RunCheck.SetChecked(false) })
}