Fix mute sound issue. Clean up code

This commit is contained in:
Alex Ballas
2024-05-10 01:26:13 +03:00
parent caf9fa8fc5
commit 169884232f
13 changed files with 71 additions and 69 deletions

View File

@@ -55,10 +55,8 @@ func main() {
os.Exit(0) os.Exit(0)
} }
if err != nil { fmt.Fprintf(os.Stderr, "Encountered error(s): %s\n", err)
fmt.Fprintf(os.Stderr, "Encountered error(s): %s\n", err) os.Exit(1)
os.Exit(1)
}
} }
} }

View File

@@ -1 +1 @@
1.16.0 1.16.1

View File

@@ -1 +1 @@
1.16.0 1.16.1

View File

@@ -12,7 +12,7 @@ import (
"strings" "strings"
"time" "time"
fyne "fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas" "fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/dialog"
@@ -90,7 +90,7 @@ func checkVersion(s *NewScreen) {
} }
client := &http.Client{ client := &http.Client{
Timeout: time.Duration(3 * time.Second), Timeout: 3 * time.Second,
CheckRedirect: func(req *http.Request, via []*http.Request) error { CheckRedirect: func(req *http.Request, via []*http.Request) error {
return errRedirectChecker return errRedirectChecker
}, },
@@ -105,12 +105,12 @@ func checkVersion(s *NewScreen) {
defer response.Body.Close() defer response.Body.Close()
if errors.Is(err, errRedirectChecker) { if errors.Is(err, errRedirectChecker) {
url, err := response.Location() responceUrl, err := response.Location()
if err != nil { if err != nil {
dialog.ShowError(errVersionGet, s.Current) dialog.ShowError(errVersionGet, s.Current)
return return
} }
str := strings.Trim(filepath.Base(url.Path), "v") str := strings.Trim(filepath.Base(responceUrl.Path), "v")
str = strings.ReplaceAll(str, ".", "") str = strings.ReplaceAll(str, ".", "")
chversion, err := strconv.Atoi(str) chversion, err := strconv.Atoi(str)
if err != nil { if err != nil {
@@ -120,7 +120,7 @@ func checkVersion(s *NewScreen) {
switch { switch {
case chversion > currversion: case chversion > currversion:
dialog.ShowInformation("Version checker", "New version: "+strings.Trim(filepath.Base(url.Path), "v"), s.Current) dialog.ShowInformation("Version checker", "New version: "+strings.Trim(filepath.Base(responceUrl.Path), "v"), s.Current)
return return
default: default:
dialog.ShowInformation("Version checker", "No new version", s.Current) dialog.ShowInformation("Version checker", "No new version", s.Current)

View File

@@ -35,7 +35,7 @@ func muteAction(screen *NewScreen) {
return return
} }
if screen.MuteUnmute.Icon == theme.VolumeUpIcon() { if screen.MuteUnmute.Icon == theme.VolumeMuteIcon() {
unmuteAction(screen) unmuteAction(screen)
return return
} }
@@ -476,9 +476,9 @@ func skipNextAction(screen *NewScreen) {
return return
} }
name, path := getNextMedia(screen) name, nextMediaPath := getNextMedia(screen)
screen.MediaText.Text = name screen.MediaText.Text = name
screen.mediafile = path screen.mediafile = nextMediaPath
screen.MediaText.Refresh() screen.MediaText.Refresh()
if !screen.CustomSubsCheck.Checked { if !screen.CustomSubsCheck.Checked {
@@ -614,7 +614,7 @@ func queueNext(screen *NewScreen, clear bool) (*soapcalls.TVPayload, error) {
} }
fname, fpath := getNextMedia(screen) fname, fpath := getNextMedia(screen)
_, spath := getNextPossibleSubs(fname, screen) _, spath := getNextPossibleSubs(fname)
var mediaType string var mediaType string
var isSeek bool var isSeek bool

View File

@@ -30,7 +30,7 @@ func muteAction(screen *NewScreen) {
return return
} }
if screen.MuteUnmute.Icon == theme.VolumeUpIcon() { if screen.MuteUnmute.Icon == theme.VolumeDownIcon() {
unmuteAction(screen) unmuteAction(screen)
return return
} }

View File

@@ -12,7 +12,7 @@ import (
"strings" "strings"
"sync" "sync"
fyne "fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/app" "fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding" "fyne.io/fyne/v2/data/binding"
@@ -101,8 +101,8 @@ func Start(ctx context.Context, s *NewScreen) {
s.Hotkeys = true s.Hotkeys = true
tabs.OnSelected = func(t *container.TabItem) { tabs.OnSelected = func(t *container.TabItem) {
theme := fyne.CurrentApp().Preferences().StringWithFallback("Theme", "Default") currentTheme := fyne.CurrentApp().Preferences().StringWithFallback("Theme", "Default")
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{theme}) fyne.CurrentApp().Settings().SetTheme(go2tvTheme{currentTheme})
if t.Text == "Go2TV" { if t.Text == "Go2TV" {
s.Hotkeys = true s.Hotkeys = true
@@ -201,21 +201,18 @@ func (p *NewScreen) Fini() {
func InitFyneNewScreen(v string) *NewScreen { func InitFyneNewScreen(v string) *NewScreen {
go2tv := app.NewWithID("com.alexballas.go2tv") go2tv := app.NewWithID("com.alexballas.go2tv")
w := go2tv.NewWindow("Go2TV") w := go2tv.NewWindow("Go2TV")
currentdir, err := os.Getwd() currentDir, err := os.Getwd()
if err != nil { if err != nil {
currentdir = "" currentDir = ""
} }
theme := fyne.CurrentApp().Preferences().StringWithFallback("Theme", "Default")
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{theme})
dw := &debugWriter{ dw := &debugWriter{
ring: ring.New(1000), ring: ring.New(1000),
} }
return &NewScreen{ return &NewScreen{
Current: w, Current: w,
currentmfolder: currentdir, currentmfolder: currentDir,
mediaFormats: []string{".mp4", ".avi", ".mkv", ".mpeg", ".mov", ".webm", ".m4v", ".mpv", ".dv", ".mp3", ".flac", ".wav", ".m4a", ".jpg", ".jpeg", ".png"}, mediaFormats: []string{".mp4", ".avi", ".mkv", ".mpeg", ".mov", ".webm", ".m4v", ".mpv", ".dv", ".mp3", ".flac", ".wav", ".m4a", ".jpg", ".jpeg", ".png"},
version: v, version: v,
Debug: dw, Debug: dw,
@@ -304,13 +301,13 @@ func getNextMedia(screen *NewScreen) (string, string) {
} }
func autoSelectNextSubs(v string, screen *NewScreen) { func autoSelectNextSubs(v string, screen *NewScreen) {
name, path := getNextPossibleSubs(v, screen) name, path := getNextPossibleSubs(v)
screen.SubsText.Text = name screen.SubsText.Text = name
screen.subsfile = path screen.subsfile = path
screen.SubsText.Refresh() screen.SubsText.Refresh()
} }
func getNextPossibleSubs(v string, screen *NewScreen) (string, string) { func getNextPossibleSubs(v string) (string, string) {
var name, path string var name, path string
possibleSub := v[0:len(v)- possibleSub := v[0:len(v)-

View File

@@ -10,7 +10,7 @@ import (
"strings" "strings"
"sync" "sync"
fyne "fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/app" "fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog" "fyne.io/fyne/v2/dialog"

View File

@@ -527,24 +527,24 @@ func refreshDevList(s *NewScreen, data *[]devType) {
} }
for range refreshDevices.C { for range refreshDevices.C {
datanew, _ := getDevices(2) newDevices, _ := getDevices(2)
outer: outer:
for _, old := range *data { for _, old := range *data {
oldAddress, _ := url.Parse(old.addr) oldAddress, _ := url.Parse(old.addr)
for _, new := range datanew { for _, device := range newDevices {
newAddress, _ := url.Parse(new.addr) newAddress, _ := url.Parse(device.addr)
if newAddress.Host == oldAddress.Host { if newAddress.Host == oldAddress.Host {
continue outer continue outer
} }
} }
if utils.HostPortIsAlive(oldAddress.Host) { if utils.HostPortIsAlive(oldAddress.Host) {
datanew = append(datanew, old) newDevices = append(newDevices, old)
} }
sort.Slice(datanew, func(i, j int) bool { sort.Slice(newDevices, func(i, j int) bool {
return (datanew)[i].name < (datanew)[j].name return (newDevices)[i].name < (newDevices)[j].name
}) })
} }
@@ -552,14 +552,14 @@ func refreshDevList(s *NewScreen, data *[]devType) {
// one of the already selected devices // one of the already selected devices
var includes bool var includes bool
u, _ := url.Parse(s.controlURL) u, _ := url.Parse(s.controlURL)
for _, d := range datanew { for _, d := range newDevices {
n, _ := url.Parse(d.addr) n, _ := url.Parse(d.addr)
if n.Host == u.Host { if n.Host == u.Host {
includes = true includes = true
} }
} }
*data = datanew *data = newDevices
if !includes && !utils.HostPortIsAlive(u.Host) { if !includes && !utils.HostPortIsAlive(u.Host) {
s.controlURL = "" s.controlURL = ""

View File

@@ -20,15 +20,21 @@ type go2tvTheme struct {
Theme string Theme string
} }
var _ fyne.Theme = go2tvTheme{} var (
var SystemVariant fyne.ThemeVariant = 999 _ fyne.Theme = go2tvTheme{}
var once sync.Once SystemVariant fyne.ThemeVariant = 999
signalSystemVariantChange = make(chan struct{})
once sync.Once
)
func (m go2tvTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color { func (m go2tvTheme) Color(name fyne.ThemeColorName, variant fyne.ThemeVariant) color.Color {
switch m.Theme { switch m.Theme {
case "GrabVariant": case "GrabVariant":
once.Do(func() { once.Do(func() {
SystemVariant = variant SystemVariant = variant
go func() {
signalSystemVariantChange <- struct{}{}
}()
}) })
case "Dark": case "Dark":
@@ -84,15 +90,15 @@ func settingsWindow(s *NewScreen) fyne.CanvasObject {
switch themeName { switch themeName {
case "Light": case "Light":
dropdown.PlaceHolder = "Light" dropdown.PlaceHolder = "Light"
parseTheme("Light")
case "Dark": case "Dark":
dropdown.PlaceHolder = "Dark" dropdown.PlaceHolder = "Dark"
parseTheme("Dark")
case "GrabVariant", "Default": case "GrabVariant", "Default":
fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"GrabVariant"}) fyne.CurrentApp().Settings().SetTheme(go2tvTheme{"GrabVariant"})
// Wait for SystemVariant to get the correct variant from the command above // Wait for the SystemVariant variable to change
for SystemVariant == 999 { <-signalSystemVariantChange
time.Sleep(time.Millisecond)
}
switch SystemVariant { switch SystemVariant {
case theme.VariantDark: case theme.VariantDark:

View File

@@ -174,7 +174,7 @@ func (p *TVPayload) setAVTransportSoapCall() error {
return fmt.Errorf("setAVTransportSoapCall parse error: %w", err) return fmt.Errorf("setAVTransportSoapCall parse error: %w", err)
} }
xml, err := setAVTransportSoapBuild(p) xmlData, err := setAVTransportSoapBuild(p)
if err != nil { if err != nil {
p.Log().Error().Str("Method", "setAVTransportSoapCall").Str("Action", "setAVTransportSoapBuild").Err(err).Msg("") p.Log().Error().Str("Method", "setAVTransportSoapCall").Str("Action", "setAVTransportSoapBuild").Err(err).Msg("")
return fmt.Errorf("setAVTransportSoapCall soap build error: %w", err) return fmt.Errorf("setAVTransportSoapCall soap build error: %w", err)
@@ -185,7 +185,7 @@ func (p *TVPayload) setAVTransportSoapCall() error {
retryClient.Logger = nil retryClient.Logger = nil
client := retryClient.StandardClient() client := retryClient.StandardClient()
req, err := http.NewRequestWithContext(p.ctx, "POST", parsedURLtransport.String(), bytes.NewReader(xml)) req, err := http.NewRequestWithContext(p.ctx, "POST", parsedURLtransport.String(), bytes.NewReader(xmlData))
if err != nil { if err != nil {
p.Log().Error().Str("Method", "setAVTransportSoapCall").Str("Action", "Prepare POST").Err(err).Msg("") p.Log().Error().Str("Method", "setAVTransportSoapCall").Str("Action", "Prepare POST").Err(err).Msg("")
return fmt.Errorf("setAVTransportSoapCall POST error: %w", err) return fmt.Errorf("setAVTransportSoapCall POST error: %w", err)
@@ -207,7 +207,7 @@ func (p *TVPayload) setAVTransportSoapCall() error {
p.Log().Debug(). p.Log().Debug().
Str("Method", "setAVTransportSoapCall").Str("Action", "Request"). Str("Method", "setAVTransportSoapCall").Str("Action", "Request").
RawJSON("Headers", headerBytesReq). RawJSON("Headers", headerBytesReq).
Msg(string(xml)) Msg(string(xmlData))
res, err := client.Do(req) res, err := client.Do(req)
if err != nil { if err != nil {
@@ -247,7 +247,7 @@ func (p *TVPayload) setNextAVTransportSoapCall(clear bool) error {
return fmt.Errorf("setNextAVTransportSoapCall parse error: %w", err) return fmt.Errorf("setNextAVTransportSoapCall parse error: %w", err)
} }
xml, err := setNextAVTransportSoapBuild(p, clear) xmlData, err := setNextAVTransportSoapBuild(p, clear)
if err != nil { if err != nil {
p.Log().Error().Str("Method", "setNextAVTransportSoapCall").Str("Action", "setNextAVTransportSoapBuild").Err(err).Msg("") p.Log().Error().Str("Method", "setNextAVTransportSoapCall").Str("Action", "setNextAVTransportSoapBuild").Err(err).Msg("")
return fmt.Errorf("setNextAVTransportSoapCall soap build error: %w", err) return fmt.Errorf("setNextAVTransportSoapCall soap build error: %w", err)
@@ -255,7 +255,7 @@ func (p *TVPayload) setNextAVTransportSoapCall(clear bool) error {
client := &http.Client{} client := &http.Client{}
req, err := http.NewRequestWithContext(p.ctx, "POST", parsedURLtransport.String(), bytes.NewReader(xml)) req, err := http.NewRequestWithContext(p.ctx, "POST", parsedURLtransport.String(), bytes.NewReader(xmlData))
if err != nil { if err != nil {
p.Log().Error().Str("Method", "setNextAVTransportSoapCall").Str("Action", "Prepare POST").Err(err).Msg("") p.Log().Error().Str("Method", "setNextAVTransportSoapCall").Str("Action", "Prepare POST").Err(err).Msg("")
return fmt.Errorf("setNextAVTransportSoapCall POST error: %w", err) return fmt.Errorf("setNextAVTransportSoapCall POST error: %w", err)
@@ -277,7 +277,7 @@ func (p *TVPayload) setNextAVTransportSoapCall(clear bool) error {
p.Log().Debug(). p.Log().Debug().
Str("Method", "setNextAVTransportSoapCall").Str("Action", "Request"). Str("Method", "setNextAVTransportSoapCall").Str("Action", "Request").
RawJSON("Headers", headerBytesReq). RawJSON("Headers", headerBytesReq).
Msg(string(xml)) Msg(string(xmlData))
res, err := client.Do(req) res, err := client.Do(req)
if err != nil { if err != nil {
@@ -318,17 +318,17 @@ func (p *TVPayload) PlayPauseStopSoapCall(action string) error {
return fmt.Errorf("AVTransportActionSoapCall parse error: %w", err) return fmt.Errorf("AVTransportActionSoapCall parse error: %w", err)
} }
var xml []byte var xmlData []byte
retry := false retry := false
switch action { switch action {
case "Play": case "Play":
xml, err = playSoapBuild() xmlData, err = playSoapBuild()
case "Stop": case "Stop":
xml, err = stopSoapBuild() xmlData, err = stopSoapBuild()
retry = true retry = true
case "Pause": case "Pause":
xml, err = pauseSoapBuild() xmlData, err = pauseSoapBuild()
} }
if err != nil { if err != nil {
p.Log().Error().Str("Method", "AVTransportActionSoapCall").Str("Action", "Action Error").Err(err).Msg("") p.Log().Error().Str("Method", "AVTransportActionSoapCall").Str("Action", "Action Error").Err(err).Msg("")
@@ -344,7 +344,7 @@ func (p *TVPayload) PlayPauseStopSoapCall(action string) error {
client = retryClient.StandardClient() client = retryClient.StandardClient()
} }
req, err := http.NewRequestWithContext(p.ctx, "POST", parsedURLtransport.String(), bytes.NewReader(xml)) req, err := http.NewRequestWithContext(p.ctx, "POST", parsedURLtransport.String(), bytes.NewReader(xmlData))
if err != nil { if err != nil {
p.Log().Error().Str("Method", "AVTransportActionSoapCall").Str("Action", "Prepare POST").Err(err).Msg("") p.Log().Error().Str("Method", "AVTransportActionSoapCall").Str("Action", "Prepare POST").Err(err).Msg("")
return fmt.Errorf("AVTransportActionSoapCall POST error: %w", err) return fmt.Errorf("AVTransportActionSoapCall POST error: %w", err)
@@ -366,7 +366,7 @@ func (p *TVPayload) PlayPauseStopSoapCall(action string) error {
p.Log().Debug(). p.Log().Debug().
Str("Method", "AVTransportActionSoapCall").Str("Action", action+" Request"). Str("Method", "AVTransportActionSoapCall").Str("Action", action+" Request").
RawJSON("Headers", headerBytesReq). RawJSON("Headers", headerBytesReq).
Msg(string(xml)) Msg(string(xmlData))
res, err := client.Do(req) res, err := client.Do(req)
if err != nil { if err != nil {
@@ -407,10 +407,9 @@ func (p *TVPayload) SeekSoapCall(reltime string) error {
return fmt.Errorf("SeekSoapCall parse error: %w", err) return fmt.Errorf("SeekSoapCall parse error: %w", err)
} }
var xml []byte var xmlData []byte
retry := false
xml, err = seekSoapBuild(reltime) xmlData, err = seekSoapBuild(reltime)
if err != nil { if err != nil {
p.Log().Error().Str("Method", "SeekSoapCall").Str("Action", "Action Error").Err(err).Msg("") p.Log().Error().Str("Method", "SeekSoapCall").Str("Action", "Action Error").Err(err).Msg("")
return fmt.Errorf("SeekSoapCall action error: %w", err) return fmt.Errorf("SeekSoapCall action error: %w", err)
@@ -418,14 +417,14 @@ func (p *TVPayload) SeekSoapCall(reltime string) error {
client := &http.Client{} client := &http.Client{}
if retry { //if retry {
retryClient := retryablehttp.NewClient() // retryClient := retryablehttp.NewClient()
retryClient.RetryMax = 3 // retryClient.RetryMax = 3
retryClient.Logger = nil // retryClient.Logger = nil
client = retryClient.StandardClient() // client = retryClient.StandardClient()
} //}
req, err := http.NewRequestWithContext(p.ctx, "POST", parsedURLtransport.String(), bytes.NewReader(xml)) req, err := http.NewRequestWithContext(p.ctx, "POST", parsedURLtransport.String(), bytes.NewReader(xmlData))
if err != nil { if err != nil {
p.Log().Error().Str("Method", "SeekSoapCall").Str("Action", "Prepare POST").Err(err).Msg("") p.Log().Error().Str("Method", "SeekSoapCall").Str("Action", "Prepare POST").Err(err).Msg("")
return fmt.Errorf("SeekSoapCall POST error: %w", err) return fmt.Errorf("SeekSoapCall POST error: %w", err)
@@ -447,7 +446,7 @@ func (p *TVPayload) SeekSoapCall(reltime string) error {
p.Log().Debug(). p.Log().Debug().
Str("Method", "SeekSoapCall").Str("Action", "Seek Request"). Str("Method", "SeekSoapCall").Str("Action", "Seek Request").
RawJSON("Headers", headerBytesReq). RawJSON("Headers", headerBytesReq).
Msg(string(xml)) Msg(string(xmlData))
res, err := client.Do(req) res, err := client.Do(req)
if err != nil { if err != nil {

View File

@@ -60,7 +60,7 @@ func NewTVPayload(o *Options) (*TVPayload, error) {
}, nil }, nil
} }
func (tv *TVPayload) ListenAddress() string { func (p *TVPayload) ListenAddress() string {
url, _ := url.Parse(tv.MediaURL) mediaUrl, _ := url.Parse(p.MediaURL)
return url.Host return mediaUrl.Host
} }

View File

@@ -124,6 +124,8 @@ func DMRextractor(ctx context.Context, dmrurl string) (*DMRextracted, error) {
if service.ID == "urn:upnp-org:serviceId:ConnectionManager" { if service.ID == "urn:upnp-org:serviceId:ConnectionManager" {
ex.ConnectionManagerURL = parsedURL.Scheme + "://" + parsedURL.Host + service.ControlURL ex.ConnectionManagerURL = parsedURL.Scheme + "://" + parsedURL.Host + service.ControlURL
_, err = url.ParseRequestURI(ex.ConnectionManagerURL)
if err != nil { if err != nil {
return nil, fmt.Errorf("DMRextractor invalid ConnectionManagerURL: %w", err) return nil, fmt.Errorf("DMRextractor invalid ConnectionManagerURL: %w", err)
} }