* Flush pending messages and mark webview as ready
()
| 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 | |
| 75 | // Parse org/repo from various URL formats: |
| 76 | // https://github.com/org/repo.git |
| 77 | // git@github.com:org/repo.git |
| 78 | // https://github.com/org/repo |
| 79 | const match = remoteUrl.match(/[:/]([^/]+)\/([^/]+?)(\.git)?$/); |
| 80 | if (match) { |
| 81 | const org = match[1]; |
| 82 | const repo = match[2]; |
| 83 | repoName = `${org}/${repo}`; |
| 84 | } |
| 85 | } catch (e) { |
| 86 | // Not a git repo or no remote, use folder name |
| 87 | } |
| 88 | |
| 89 | this.panel?.webview.postMessage({ |
| 90 | command: 'setWorkspaceName', |
| 91 | name: repoName |
| 92 | }); |
| 93 | } |
| 94 | |
| 95 | this.pendingMessages.forEach(msg => { |
| 96 | console.log('[webview] Sending queued message:', msg.command); |
| 97 | this.panel?.webview.postMessage(msg); |
| 98 | }); |
| 99 | this.pendingMessages = []; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Reset ready state when HTML is replaced |
no test coverage detected