Fix regression that prevented pinned items to update while window is open

This commit is contained in:
Raphael Ludwig 2022-02-14 20:59:48 +01:00
parent 058f8684aa
commit 165b925da2
No known key found for this signature in database
GPG Key ID: BCDF96FED07B1844
2 changed files with 42 additions and 38 deletions

76
main.go
View File

@ -101,7 +101,7 @@ var (
status string
ignore string
desktopTrigger bool
pinnedTrigger bool
pinnedItemsChanged chan interface{} = make(chan interface{}, 1)
)
func defaultStringIfBlank(s, fallback string) string {
@ -494,47 +494,49 @@ func main() {
// Check if showing the window has been requested (SIGUSR1)
go func() {
for {
<-showWindowChannel
select {
case <-showWindowChannel:
log.Debug("Showing window")
glib.TimeoutAdd(0, func() bool {
if win != nil && !win.IsVisible() {
log.Debug("SHOW WINDOW")
glib.TimeoutAdd(0, func() bool {
if win != nil && !win.IsVisible() {
// Refresh files before displaying the root window
// some .desktop file changed
if desktopTrigger {
log.Debug(".desktop file changed")
desktopFiles = listDesktopFiles()
status = parseDesktopFiles(desktopFiles)
appFlowBox = setUpAppsFlowBox(nil, "")
desktopTrigger = false
}
// Refresh files before displaying the root window
// some .desktop file changed
if desktopTrigger {
log.Debug(".desktop file changed")
desktopFiles = listDesktopFiles()
status = parseDesktopFiles(desktopFiles)
appFlowBox = setUpAppsFlowBox(nil, "")
desktopTrigger = false
}
// pinned file changed
if pinnedTrigger {
log.Debug("pinned file changed")
pinnedTrigger = false
pinned, _ = loadTextFile(pinnedFile)
pinnedFlowBox = setUpPinnedFlowBox()
}
// Show window and focus the search box
win.ShowAll()
if fileSearchResultWrapper != nil {
fileSearchResultWrapper.Hide()
}
// focus 1st element
b := appFlowBox.GetChildAtIndex(0)
if b != nil {
button, err := b.GetChild()
if err == nil {
button.ToWidget().GrabFocus()
// Show window and focus the search box
win.ShowAll()
if fileSearchResultWrapper != nil {
fileSearchResultWrapper.Hide()
}
// focus 1st element
b := appFlowBox.GetChildAtIndex(0)
if b != nil {
button, err := b.GetChild()
if err == nil {
button.ToWidget().GrabFocus()
}
}
}
}
return false
})
return false
})
case <-pinnedItemsChanged:
glib.TimeoutAdd(0, func() bool {
log.Debug("pinned file changed")
pinned, _ = loadTextFile(pinnedFile)
pinnedFlowBox = setUpPinnedFlowBox()
return false
})
}
}
}()

View File

@ -41,7 +41,9 @@ func watchFiles() {
event.Op.String() == "RENAME") {
desktopTrigger = true
} else if event.Name == pinnedFile {
pinnedTrigger = true
// TODO: This can be used to propagate information about the changed file to the
// GUI to avoid recreating everything
pinnedItemsChanged <- struct{}{}
}
case err := <-watcher.Errors: