MCPcopy Create free account
hub / github.com/codag-megalith/codag-visualizer / WebviewManager

Class WebviewManager

frontend/src/webview.ts:17–666  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15}
16
17export class WebviewManager {
18 private panel: vscode.WebviewPanel | undefined;
19 private viewState: ViewState = {
20 selectedNodeId: null,
21 expandedWorkflowIds: [],
22 lastUpdated: Date.now()
23 };
24 private filePickerResolver: ((paths: string[] | null) => void) | null = null;
25 private pendingMessages: any[] = [];
26 private webviewReady = false;
27
28 // Cumulative batch progress tracking
29 private batchState = {
30 completed: 0,
31 total: 0,
32 startTime: 0,
33 filesAnalyzed: 0
34 };
35
36 constructor(private context: vscode.ExtensionContext) {}
37
38 /**
39 * Post message to webview, queuing if not ready yet
40 */
41 private postMessage(message: any) {
42 if (this.panel) {
43 if (this.webviewReady) {
44 this.panel.webview.postMessage(message);
45 } else {
46 this.pendingMessages.push(message);
47 }
48 } else {
49 console.log(`[Codag] Message dropped (panel closed): ${message.command}`);
50 }
51 }
52
53 /**
54 * Flush pending messages and mark webview as ready
55 */
56 private async onWebviewReady() {
57 console.log('[webview] onWebviewReady: flushing', this.pendingMessages.length, 'messages');
58 this.webviewReady = true;
59
60 // Send workspace name for export watermark (try git remote first for org/repo format)
61 const workspaceFolders = vscode.workspace.workspaceFolders;
62 if (workspaceFolders && workspaceFolders.length > 0) {
63 const workspaceRoot = workspaceFolders[0].uri.fsPath;
64 let repoName = workspaceFolders[0].name; // Fallback to folder name
65
66 // Try to get org/repo from git remote
67 try {
68 const { execSync } = require('child_process');
69 const remoteUrl = execSync('git remote get-url origin', {
70 cwd: workspaceRoot,
71 encoding: 'utf8',
72 timeout: 2000
73 }).trim();
74

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected