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,12 +55,10 @@ func main() {
os.Exit(0)
}
if err != nil {
fmt.Fprintf(os.Stderr, "Encountered error(s): %s\n", err)
os.Exit(1)
}
}
}
func run() error {
var absMediaFile, mediaType string

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -60,7 +60,7 @@ func NewTVPayload(o *Options) (*TVPayload, error) {
}, nil
}
func (tv *TVPayload) ListenAddress() string {
url, _ := url.Parse(tv.MediaURL)
return url.Host
func (p *TVPayload) ListenAddress() string {
mediaUrl, _ := url.Parse(p.MediaURL)
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" {
ex.ConnectionManagerURL = parsedURL.Scheme + "://" + parsedURL.Host + service.ControlURL
_, err = url.ParseRequestURI(ex.ConnectionManagerURL)
if err != nil {
return nil, fmt.Errorf("DMRextractor invalid ConnectionManagerURL: %w", err)
}