MCPcopy Create free account
hub / github.com/devnullvoid/pvetui / RegisterBackupCallback

Method RegisterBackupCallback

internal/ui/components/app.go:784–814  ·  view source on GitHub ↗

RegisterBackupCallback registers a callback for backup state changes. Returns a function to unregister the callback.

(callback func())

Source from the content-addressed store, hash-verified

782// RegisterBackupCallback registers a callback for backup state changes.
783// Returns a function to unregister the callback.
784func (a *App) RegisterBackupCallback(callback func()) func() {
785 return a.poller.Subscribe(func(task *taskpoller.TaskInfo) {
786 a.QueueUpdateDraw(func() {
787 if task.Status == "stopped" {
788 if task.ExitStatus == "OK" {
789 a.header.ShowSuccess(fmt.Sprintf("Backup for VM %d on %s completed successfully!", task.VMID, task.Node))
790 } else {
791 a.header.ShowError(fmt.Sprintf("Backup for VM %d on %s failed: %s", task.VMID, task.Node, task.ExitStatus))
792 }
793
794 // Introduce delay before refreshing to ensure API consistency
795 go func() {
796 // Show refreshing indicator
797 a.QueueUpdateDraw(func() {
798 a.header.ShowLoading("Refreshing backup list...")
799 })
800
801 time.Sleep(1 * time.Second)
802 a.QueueUpdateDraw(func() {
803 a.header.StopLoading()
804 a.ClearAPICache()
805 callback()
806 })
807 }()
808 } else {
809 // Running update?
810 callback()
811 }
812 })
813 })
814}

Callers 1

NewBackupManagerFunction · 0.80

Calls 7

ClearAPICacheMethod · 0.95
SubscribeMethod · 0.80
QueueUpdateDrawMethod · 0.80
ShowSuccessMethod · 0.65
ShowErrorMethod · 0.65
ShowLoadingMethod · 0.65
StopLoadingMethod · 0.65

Tested by

no test coverage detected