Skip to content

Commit

Permalink
fix: premptivly filter thumbnail fs events when generating thumbnails
Browse files Browse the repository at this point in the history
Signed-off-by: Rachel Powers <[email protected]>
  • Loading branch information
Ryex committed Sep 30, 2024
1 parent 9160de9 commit e7fb988
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions internal/gui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type App struct {

packageWatcher *fsnotify.Watcher

packageWatcherIgnoreThumbnails bool

pkgUpdateCounter int
packageUpdated binding.Int
}
Expand Down
20 changes: 15 additions & 5 deletions internal/gui/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"path/filepath"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -116,14 +117,20 @@ func (a *App) setupPackageWatcher() {
a.packageWatcher = watcher
paths := structures.NewSet[string]()
var eventTimer *time.Timer
lock := &sync.RWMutex{}
timerLock := &sync.RWMutex{}

updatePackage := func() {
lock.Lock()
defer lock.Unlock()
timerLock.Lock()
defer timerLock.Unlock()
eventTimer = nil
toUpdate := paths.AsSlice()
paths = structures.NewSet[string]()
if a.packageWatcherIgnoreThumbnails {
thumbnailPrefix := filepath.Join(a.pkg.UnpackedPath(), "thumbnails")
toUpdate = utils.Filter(toUpdate, func(path string) bool {
return !strings.HasPrefix(path, thumbnailPrefix)
})
}
if a.pkg != nil {
a.pkg.UpdateFromPaths(toUpdate)
}
Expand All @@ -140,8 +147,8 @@ func (a *App) setupPackageWatcher() {
if !event.Has(fsnotify.Chmod) {
path := event.Name
func() {
lock.Lock()
defer lock.Unlock()
timerLock.Lock()
defer timerLock.Unlock()
if eventTimer != nil {
eventTimer.Stop()
}
Expand Down Expand Up @@ -388,6 +395,7 @@ func (a *App) packPackage(path string, options ddpackage.PackOptions, genThumbna
go func() {
if genThumbnails {
taskStr.Set(lang.X("task.genthumbnails.text", "Generating thumbnails ..."))
a.packageWatcherIgnoreThumbnails = true
err := a.pkg.GenerateThumbnails(func(p float64) {
progressVal.Set(p)
})
Expand All @@ -406,6 +414,8 @@ func (a *App) packPackage(path string, options ddpackage.PackOptions, genThumbna
errDlg.Show()
return
}
a.pkg.UpdateFromPaths([]string{filepath.Join(a.pkg.UnpackedPath(), "thumbnails")})
a.packageWatcherIgnoreThumbnails = true
progressVal.Set(1.0)
}

Expand Down

0 comments on commit e7fb988

Please sign in to comment.