handleVNCOutcome centralizes UI handling for VNC connection results to avoid duplicated code.
(kind string, name string, vncURL string, err error)
| 56 | |
| 57 | // handleVNCOutcome centralizes UI handling for VNC connection results to avoid duplicated code. |
| 58 | func (a *App) handleVNCOutcome(kind string, name string, vncURL string, err error) { |
| 59 | if err != nil { |
| 60 | // Specific handling for missing xdg-open |
| 61 | if strings.Contains(err.Error(), "xdg-open not found") { |
| 62 | message := fmt.Sprintf("Cannot open browser automatically on this system.\n\nxdg-open is not installed or not available.\n\nThe VNC server is still running and ready for connection.\n\nTo connect:\n1. Copy the shortened URL below\n2. Paste it into your browser\n3. It will automatically redirect to the full VNC session\n4. Connect quickly before the session expires\n\nShortened URL:\n%s", vncURL) |
| 63 | |
| 64 | modal := CreateErrorDialogWithScrollableText("Browser Not Available", message, func() { |
| 65 | a.pages.RemovePage("vnc_error") |
| 66 | }) |
| 67 | a.pages.AddPage("vnc_error", modal, false, true) |
| 68 | a.SetFocus(modal) |
| 69 | |
| 70 | return |
| 71 | } |
| 72 | |
| 73 | // Generic error dialog |
| 74 | context := "VNC connection" |
| 75 | if kind == "node" { |
| 76 | context = fmt.Sprintf("VNC shell for %s", name) |
| 77 | } else if kind == "vm" { |
| 78 | context = fmt.Sprintf("VNC console for %s", name) |
| 79 | } |
| 80 | |
| 81 | errorModal := CreateErrorDialog("VNC Connection Error", |
| 82 | fmt.Sprintf("Failed to start %s:\n\n%s", context, err.Error()), |
| 83 | func() { |
| 84 | a.pages.RemovePage("vnc_error") |
| 85 | }) |
| 86 | a.pages.AddPage("vnc_error", errorModal, false, true) |
| 87 | |
| 88 | return |
| 89 | } |
| 90 | |
| 91 | // Success path: show fallback URL and header success |
| 92 | var title, startedHeader, headerMsg string |
| 93 | if kind == "node" { |
| 94 | title = "VNC Shell Started" |
| 95 | startedHeader = fmt.Sprintf("VNC shell started successfully for %s!", name) |
| 96 | headerMsg = fmt.Sprintf("Embedded VNC shell started for %s", name) |
| 97 | } else { |
| 98 | title = "VNC Console Started" |
| 99 | startedHeader = fmt.Sprintf("VNC console started successfully for %s!", name) |
| 100 | headerMsg = fmt.Sprintf("Embedded VNC console started for %s", name) |
| 101 | } |
| 102 | |
| 103 | message := fmt.Sprintf("%s\n\nOpening in your default browser...\n\nIf the browser doesn't open automatically, you can use this URL as a fallback:\n\n%s", startedHeader, vncURL) |
| 104 | modal := CreateSuccessDialogWithURL(title, message, func() { |
| 105 | a.pages.RemovePage("vnc_success") |
| 106 | }) |
| 107 | a.pages.AddPage("vnc_success", modal, false, true) |
| 108 | a.SetFocus(modal) |
| 109 | a.header.ShowSuccess(headerMsg) |
| 110 | } |
| 111 | |
| 112 | // connectToNodeVNC performs the actual node VNC connection using embedded noVNC client. |
| 113 | func (a *App) connectToNodeVNC(node *api.Node, vncService *vnc.Service) { |
no test coverage detected