add updater

This commit is contained in:
aynakeya
2024-05-06 08:17:30 +08:00
parent 68c7c591ff
commit f24b3e73fb
10 changed files with 130 additions and 85 deletions

View File

@@ -114,28 +114,16 @@ func (b *bascicConfig) CreatePanel() fyne.CanvasObject {
&config.General.PlayNextOnFail,
config.General.PlayNextOnFail),
)
//checkUpdateBox := container.NewHBox(
// widget.NewLabel(i18n.T("gui.config.basic.auto_check_update")),
// component.NewCheckOneWayBinding(
// i18n.T("gui.config.basic.auto_check_update.prompt"),
// &config.General.AutoCheckUpdate,
// config.General.AutoCheckUpdate),
//)
//checkUpdateBtn := widget.NewButton(i18n.T("gui.config.basic.check_update"), func() {
// err := API.App().CheckUpdate()
// if err != nil {
// showDialogIfError(err)
// return
// }
// if API.App().LatestVersion().Version > API.App().Version().Version {
// dialog.ShowCustom(
// i18n.T("gui.update.new_version"),
// "OK",
// widget.NewRichTextFromMarkdown(API.App().LatestVersion().Info),
// MainWindow)
// }
//})
//b.panel = container.NewVBox(randomPlaylist, outputDevice, skipPlaylist, skipWhenErr, checkUpdateBox, checkUpdateBtn)
b.panel = container.NewVBox(randomPlaylist, skipWhenErr, outputDevice)
checkUpdateBox := container.NewHBox(
widget.NewLabel(i18n.T("gui.config.basic.auto_check_update")),
component.NewCheckOneWayBinding(
i18n.T("gui.config.basic.auto_check_update.prompt"),
&config.General.AutoCheckUpdate,
config.General.AutoCheckUpdate),
)
checkUpdateBtn := widget.NewButton(i18n.T("gui.config.basic.check_update"), func() {
global.EventManager.CallA(events.CheckUpdateCmd, events.CheckUpdateCmdEvent{})
})
b.panel = container.NewVBox(randomPlaylist, skipWhenErr, outputDevice, checkUpdateBox, checkUpdateBtn)
return b.panel
}

View File

@@ -78,28 +78,9 @@ func Initialize() {
dialog.ShowError(err, MainWindow)
})
checkUpdate()
MainWindow.SetFixedSize(true)
if config.General.ShowSystemTray {
setupSysTray()
}
}
//
//func checkUpdate() {
// l().Info("checking updates...")
// err := API.App().CheckUpdate()
// if err != nil {
// showDialogIfError(err)
// l().Warnf("check update failed", err)
// return
// }
// l().Infof("latest version: v%s", API.App().LatestVersion().Version)
// if API.App().LatestVersion().Version > API.App().Version().Version {
// l().Info("new update available")
// dialog.ShowCustom(
// i18n.T("gui.update.new_version"),
// "OK",
// widget.NewRichTextFromMarkdown(API.App().LatestVersion().Info),
// MainWindow)
// }
//}

31
gui/updater.go Normal file
View File

@@ -0,0 +1,31 @@
package gui
import (
"AynaLivePlayer/core/events"
"AynaLivePlayer/global"
"AynaLivePlayer/pkg/event"
"AynaLivePlayer/pkg/i18n"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
)
func checkUpdate() {
global.EventManager.RegisterA(
events.CheckUpdateResultUpdate, "gui.updater.check_update", func(event *event.Event) {
data := event.Data.(events.CheckUpdateResultUpdateEvent)
msg := data.Info.Version.String() + "\n\n\n" + data.Info.Info
if data.HasUpdate {
dialog.ShowCustom(
i18n.T("gui.update.new_version"),
"OK",
widget.NewRichTextFromMarkdown(msg),
MainWindow)
} else {
dialog.ShowCustom(
i18n.T("gui.update.already_latest_version"),
"OK",
widget.NewRichTextFromMarkdown(""),
MainWindow)
}
})
}