NewApp creates a new application instance with all UI components.
(ctx context.Context, client *api.Client, cfg *config.Config, configPath string, initialGroup string)
| 152 | |
| 153 | // NewApp creates a new application instance with all UI components. |
| 154 | func NewApp(ctx context.Context, client *api.Client, cfg *config.Config, configPath string, initialGroup string) *App { |
| 155 | uiLogger := models.GetUILogger() |
| 156 | uiLogger.Debug("Creating new App instance") |
| 157 | |
| 158 | // Get the shared logger for VNC service |
| 159 | sharedLogger := models.GetUILogger() |
| 160 | |
| 161 | // Convert interface to concrete logger type for VNC service |
| 162 | var vncLogger *logger.Logger |
| 163 | if loggerAdapter, ok := sharedLogger.(*adapters.LoggerAdapter); ok { |
| 164 | vncLogger = loggerAdapter.GetInternalLogger() |
| 165 | } |
| 166 | |
| 167 | ctx, cancel := context.WithCancel(ctx) |
| 168 | poller := taskpoller.New(ctx, uiLogger) |
| 169 | |
| 170 | app := &App{ |
| 171 | Application: tview.NewApplication(), |
| 172 | client: client, |
| 173 | config: *cfg, |
| 174 | configPath: configPath, |
| 175 | vncService: vnc.NewServiceWithLogger(client, vncLogger), |
| 176 | pages: tview.NewPages(), |
| 177 | autoRefreshEnabled: false, |
| 178 | ctx: ctx, |
| 179 | cancel: cancel, |
| 180 | logger: uiLogger, |
| 181 | plugins: make(map[string]Plugin), |
| 182 | pluginRegistry: newPluginRegistry(), |
| 183 | poller: poller, |
| 184 | guestSelections: make(map[string]struct{}), |
| 185 | } |
| 186 | |
| 187 | uiLogger.Debug("Initializing UI components") |
| 188 | |
| 189 | // Initialize TaskManager |
| 190 | app.taskManager = taskmanager.NewTaskManager(func(nodeName string) (*api.Client, error) { |
| 191 | if !app.isGroupMode { |
| 192 | return app.client, nil |
| 193 | } |
| 194 | |
| 195 | // In group mode, find the node in global state |
| 196 | var targetNode *api.Node |
| 197 | for _, n := range models.GlobalState.OriginalNodes { |
| 198 | if n.Name == nodeName { |
| 199 | targetNode = n |
| 200 | break |
| 201 | } |
| 202 | } |
| 203 | if targetNode == nil { |
| 204 | return nil, fmt.Errorf("node %s not found in group state", nodeName) |
| 205 | } |
| 206 | |
| 207 | return app.getClientForNode(targetNode) |
| 208 | }, func() { |
| 209 | app.QueueUpdateDraw(func() { |
| 210 | if app.tasksList != nil { |
| 211 | app.tasksList.Refresh() |
no test coverage detected