Skip to content

Commit

Permalink
fix: Try to fix a bug which close app when 0 stream online
Browse files Browse the repository at this point in the history
  • Loading branch information
SkYNewZ committed May 16, 2023
1 parent 8967862 commit 1fbca58
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@

<a name="v0.0.3"></a>
## [v0.0.3](https://github.com/SkYNewZ/twitch-clip/compare/v0.0.2...v0.0.3)

> 2023-05-16
### Chore

* Upgrade Go modules

### Fix

* Try to fix a bug which close app when 0 stream online


<a name="v0.0.2"></a>
## v0.0.2

> 2021-12-13
> 2022-11-15
### Feat

Expand Down
22 changes: 6 additions & 16 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (a *Application) Start(ctx context.Context) {

// Stop Application
func (a *Application) Stop() {
a.Cancel() // stop each routines
a.Cancel() // stop each routine
close(a.ClipboardListener) // stop clipboard listener
if err := a.Notifier.Close(); err != nil { // notification service
log.Errorf("fail to stop notification service: %s", err)
Expand Down Expand Up @@ -234,20 +234,13 @@ func (a *Application) HandleClipboard(ctx context.Context) {

// Refresh hide or show menu items based on currently active streams
func (a *Application) Refresh(activeStreams []*twitch.Stream) {
var wg sync.WaitGroup
wg.Add(len(a.State))
for _, item := range a.State {
go func(i *Item) {
defer wg.Done()
itemIsAnActiveStream := funk.Contains(activeStreams, func(stream *twitch.Stream) bool {
return stream.UserLogin == i.UserLogin
})

i.SetVisible(itemIsAnActiveStream)
}(item)
}
itemIsAnActiveStream := funk.Contains(activeStreams, func(stream *twitch.Stream) bool {
return stream.UserLogin == item.UserLogin
})

wg.Wait()
item.SetVisible(itemIsAnActiveStream)
}
}

func (a *Application) DisplayConnectedUser() {
Expand Down Expand Up @@ -312,9 +305,6 @@ func (a *Application) RefreshStreamsMenuItem(ctx context.Context, in <-chan []*t
case activeStreams := <-in:
log.Debugf("refreshing menu items for %d active followed streams", len(activeStreams))
menuNoActiveStreams.SetVisible(len(activeStreams) == 0)
if len(activeStreams) == 0 {
continue // no active stream, just leave here
}

for _, s := range activeStreams {
// stream already in the stream list. Refresh title and tooltip and show it
Expand Down
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package main

import "github.com/getlantern/systray"
import (
"github.com/getlantern/systray"
log "github.com/sirupsen/logrus"
)

func main() {
defer func() {
if r := recover(); r != nil {
log.Errorf("Recovered from panic: %s", r)
}
}()

app := New()
systray.Run(app.Setup, app.Stop)
}

0 comments on commit 1fbca58

Please sign in to comment.