migrate to Fyne 2.6 - WIP - updates for new threading model
This commit is contained in:
+72
-62
@@ -88,48 +88,7 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
|
||||
|
||||
m.BottomPanel = NewBottomPanel(app.PlaybackManager, app.ImageManager, m.Controller)
|
||||
app.PlaybackManager.OnSongChange(func(item mediaprovider.MediaItem, _ *mediaprovider.Track) {
|
||||
if item == nil {
|
||||
m.Window.SetTitle(displayAppName)
|
||||
return
|
||||
}
|
||||
meta := item.Metadata()
|
||||
artistDisp := ""
|
||||
if tr, ok := item.(*mediaprovider.Track); ok {
|
||||
artistDisp = " – " + strings.Join(tr.ArtistNames, ", ")
|
||||
}
|
||||
m.Window.SetTitle(fmt.Sprintf("%s%s · %s", meta.Name, artistDisp, displayAppName))
|
||||
if m.App.Config.Application.ShowTrackChangeNotification {
|
||||
if runtime.GOOS == "linux" {
|
||||
if notifySend, err := exec.LookPath("notify-send"); err == nil {
|
||||
go func() {
|
||||
args := []string{
|
||||
"--app-name", "supersonic",
|
||||
"--urgency", "low",
|
||||
"--expire-time", "10000",
|
||||
// replace previous notification
|
||||
"--hint", "string:x-canonical-private-synchronous:supersonic-track",
|
||||
meta.Name, strings.TrimPrefix(artistDisp, " – "),
|
||||
}
|
||||
|
||||
app.ImageManager.GetCoverThumbnail(meta.CoverArtID)
|
||||
if path, err := app.ImageManager.GetCoverArtPath(meta.CoverArtID); err == nil {
|
||||
args = append([]string{"--icon", path}, args...)
|
||||
}
|
||||
|
||||
if out, err := exec.Command(notifySend, args...).CombinedOutput(); err != nil {
|
||||
log.Printf("notify-send error: %s %s", strings.TrimSpace(string(out)), err)
|
||||
}
|
||||
}()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Once Fyne issue #2935 is resolved, show album cover
|
||||
fyne.CurrentApp().SendNotification(&fyne.Notification{
|
||||
Title: meta.Name,
|
||||
Content: strings.TrimPrefix(artistDisp, " – "),
|
||||
})
|
||||
}
|
||||
fyne.Do(func() { m.UpdateOnTrackChange(item) })
|
||||
})
|
||||
app.ServerManager.OnServerConnected(func() {
|
||||
go m.RunOnServerConnectedTasks(app, displayAppName)
|
||||
@@ -200,6 +159,51 @@ func NewMainWindow(fyneApp fyne.App, appName, displayAppName, appVersion string,
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *MainWindow) UpdateOnTrackChange(item mediaprovider.MediaItem) {
|
||||
if item == nil {
|
||||
m.Window.SetTitle(res.DisplayName)
|
||||
return
|
||||
}
|
||||
meta := item.Metadata()
|
||||
artistDisp := ""
|
||||
if tr, ok := item.(*mediaprovider.Track); ok {
|
||||
artistDisp = " – " + strings.Join(tr.ArtistNames, ", ")
|
||||
}
|
||||
m.Window.SetTitle(fmt.Sprintf("%s%s · %s", meta.Name, artistDisp, res.DisplayName))
|
||||
if m.App.Config.Application.ShowTrackChangeNotification {
|
||||
if runtime.GOOS == "linux" {
|
||||
if notifySend, err := exec.LookPath("notify-send"); err == nil {
|
||||
go func() {
|
||||
args := []string{
|
||||
"--app-name", "supersonic",
|
||||
"--urgency", "low",
|
||||
"--expire-time", "10000",
|
||||
// replace previous notification
|
||||
"--hint", "string:x-canonical-private-synchronous:supersonic-track",
|
||||
meta.Name, strings.TrimPrefix(artistDisp, " – "),
|
||||
}
|
||||
|
||||
app.ImageManager.GetCoverThumbnail(meta.CoverArtID)
|
||||
if path, err := app.ImageManager.GetCoverArtPath(meta.CoverArtID); err == nil {
|
||||
args = append([]string{"--icon", path}, args...)
|
||||
}
|
||||
|
||||
if out, err := exec.Command(notifySend, args...).CombinedOutput(); err != nil {
|
||||
log.Printf("notify-send error: %s %s", strings.TrimSpace(string(out)), err)
|
||||
}
|
||||
}()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Once Fyne issue #2935 is resolved, show album cover
|
||||
fyne.CurrentApp().SendNotification(&fyne.Notification{
|
||||
Title: meta.Name,
|
||||
Content: artistDisp,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MainWindow) DesiredSize() fyne.Size {
|
||||
w := float32(m.App.Config.Application.WindowWidth)
|
||||
if w <= 1 {
|
||||
@@ -229,10 +233,6 @@ func (m *MainWindow) StartupPage() controller.Route {
|
||||
|
||||
func (m *MainWindow) RunOnServerConnectedTasks(app *backend.App, displayAppName string) {
|
||||
time.Sleep(1 * time.Millisecond) // ensure this runs after sync tasks
|
||||
m.BrowsingPane.EnableNavigationButtons()
|
||||
m.Router.NavigateTo(m.StartupPage())
|
||||
_, canRate := m.App.ServerManager.Server.(mediaprovider.SupportsRating)
|
||||
m.BottomPanel.NowPlaying.DisableRating = !canRate
|
||||
|
||||
if app.Config.Application.SavePlayQueue {
|
||||
go func() {
|
||||
@@ -242,12 +242,19 @@ func (m *MainWindow) RunOnServerConnectedTasks(app *backend.App, displayAppName
|
||||
}()
|
||||
}
|
||||
|
||||
_, supportsRadio := m.App.ServerManager.Server.(mediaprovider.RadioProvider)
|
||||
if supportsRadio {
|
||||
m.radioBtn.Show()
|
||||
} else {
|
||||
m.radioBtn.Hide()
|
||||
}
|
||||
fyne.Do(func() {
|
||||
m.BrowsingPane.EnableNavigationButtons()
|
||||
m.Router.NavigateTo(m.StartupPage())
|
||||
_, canRate := m.App.ServerManager.Server.(mediaprovider.SupportsRating)
|
||||
m.BottomPanel.NowPlaying.DisableRating = !canRate
|
||||
|
||||
_, supportsRadio := m.App.ServerManager.Server.(mediaprovider.RadioProvider)
|
||||
if supportsRadio {
|
||||
m.radioBtn.Show()
|
||||
} else {
|
||||
m.radioBtn.Hide()
|
||||
}
|
||||
})
|
||||
|
||||
m.App.SaveConfigFile()
|
||||
|
||||
@@ -257,17 +264,20 @@ func (m *MainWindow) RunOnServerConnectedTasks(app *backend.App, displayAppName
|
||||
}
|
||||
|
||||
// check if launching new version, else if found available update on startup
|
||||
if l := app.Config.Application.LastLaunchedVersion; app.VersionTag() != l {
|
||||
if !app.IsFirstLaunch() {
|
||||
m.ShowWhatsNewDialog()
|
||||
fyne.Do(func() {
|
||||
if l := app.Config.Application.LastLaunchedVersion; app.VersionTag() != l {
|
||||
if !app.IsFirstLaunch() {
|
||||
m.ShowWhatsNewDialog()
|
||||
}
|
||||
m.App.Config.Application.LastLaunchedVersion = app.VersionTag()
|
||||
} else if t := app.UpdateChecker.VersionTagFound(); t != "" && t != app.Config.Application.LastCheckedVersion {
|
||||
if t != app.VersionTag() {
|
||||
m.ShowNewVersionDialog(displayAppName, t)
|
||||
}
|
||||
m.App.Config.Application.LastCheckedVersion = t
|
||||
}
|
||||
m.App.Config.Application.LastLaunchedVersion = app.VersionTag()
|
||||
} else if t := app.UpdateChecker.VersionTagFound(); t != "" && t != app.Config.Application.LastCheckedVersion {
|
||||
if t != app.VersionTag() {
|
||||
m.ShowNewVersionDialog(displayAppName, t)
|
||||
}
|
||||
m.App.Config.Application.LastCheckedVersion = t
|
||||
}
|
||||
})
|
||||
|
||||
// register callback for the ongoing periodic update check
|
||||
m.App.UpdateChecker.OnUpdatedVersionFound = func() {
|
||||
t := m.App.UpdateChecker.VersionTagFound()
|
||||
|
||||
Reference in New Issue
Block a user