show dialog on later version found

This commit is contained in:
Drew Weymouth
2023-03-30 19:19:01 -07:00
parent 8d13575000
commit d59352cd4d
4 changed files with 96 additions and 17 deletions
+28 -4
View File
@@ -2,6 +2,7 @@ package ui
import (
"fmt"
"log"
"supersonic/backend"
"supersonic/res"
"supersonic/ui/browsing"
@@ -10,7 +11,9 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/widget"
"github.com/dweymouth/go-subsonic/subsonic"
)
@@ -79,6 +82,14 @@ func NewMainWindow(fyneApp fyne.App, appName, appVersion string, app *backend.Ap
app.ServerManager.OnServerConnected(func() {
m.BrowsingPane.EnableNavigationButtons()
m.Router.NavigateTo(HomePage)
// check if found new version on startup
if t := app.UpdateChecker.VersionTagFound(); t != "" && t != app.Config.Application.LastCheckedVersion {
m.ShowNewVersionDialog(appName, t)
}
// register callback for the ongoing periodic update check
m.App.UpdateChecker.OnUpdatedVersionFound = func() {
m.ShowNewVersionDialog(appName, m.App.UpdateChecker.VersionTagFound())
}
})
app.ServerManager.OnLogout(func() {
m.BrowsingPane.DisableNavigationButtons()
@@ -94,6 +105,22 @@ func NewMainWindow(fyneApp fyne.App, appName, appVersion string, app *backend.Ap
return m
}
func (m *MainWindow) ShowNewVersionDialog(appName, versionTag string) {
contentStr := fmt.Sprintf("A new version of %s (%s) is available",
appName, versionTag)
m.Controller.QueueShowModalFunc(func() {
dialog.ShowCustomConfirm("A new version is available",
"Go to release page", "Skip this version",
widget.NewLabel(contentStr), func(show bool) {
if show {
fyne.CurrentApp().OpenURL(m.App.UpdateChecker.LatestReleaseURL())
}
m.App.Config.Application.LastCheckedVersion = versionTag
log.Printf("reset version: %s", m.App.Config.Application.LastCheckedVersion)
}, m.Window)
})
}
func (m *MainWindow) addNavigationButtons() {
m.BrowsingPane.AddNavigationButton(res.ResHeadphonesInvertPng, func() {
m.Router.NavigateTo(controller.NowPlayingRoute())
@@ -153,10 +180,7 @@ func (m *MainWindow) addShortcuts() {
m.Canvas().SetOnTypedKey(func(e *fyne.KeyEvent) {
switch e.Name {
case fyne.KeyEscape:
if m.Controller.EscapablePopUp != nil {
m.Controller.EscapablePopUp.Hide()
m.Controller.EscapablePopUp = nil
}
m.Controller.CloseEscapablePopUp()
case fyne.KeySpace:
m.App.Player.PlayPause()
}