|
1 |
| -// create a webpage and return it |
2 |
| -export function getWebviewContent(boiler: any) { |
3 |
| - return `<!DOCTYPE html> |
4 |
| - <html lang="en"> |
5 |
| - <head> |
6 |
| - <meta charset="UTF-8"> |
7 |
| - <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
8 |
| - <title>Cat Coding</title> |
9 |
| - </head> |
10 |
| - <body> |
11 |
| - Processi in Esecuzione:</br> |
12 |
| - <p id="lines-of-code-counter">0</p> |
13 |
| - |
14 |
| -
|
15 |
| - //git rebase |
16 |
| - <script> |
17 |
| - const counter = document.getElementById('lines-of-code-counter'); |
18 |
| - |
19 |
| - // Handle the message inside the webview |
20 |
| - window.addEventListener('message', event => { |
21 |
| - counter.textContent = event.data.command; |
22 |
| - const message = event.data; // The JSON data our extension sent |
23 |
| - |
24 |
| - }); |
25 |
| - </script> |
26 |
| - </body> |
27 |
| - </html>`; |
| 1 | +import * as vscode from 'vscode'; |
| 2 | +const Handlebars = require('handlebars'); |
| 3 | + |
| 4 | +let interval: NodeJS.Timeout; |
| 5 | + |
| 6 | +export class NucleoInfo { |
| 7 | + public static currentPanel: NucleoInfo | undefined; |
| 8 | + |
| 9 | + public static readonly viewType = 'nucleoInfo'; |
| 10 | + |
| 11 | + public process_list: any | undefined; |
| 12 | + private readonly _extensionUri: vscode.Uri; |
| 13 | + // delare you new variable |
| 14 | + // public VAR: any | undefined; |
| 15 | + |
| 16 | + private readonly _panel: vscode.WebviewPanel; |
| 17 | + private _disposables: vscode.Disposable[] = []; |
| 18 | + private constructor(panel: vscode.WebviewPanel, extensionUri: vscode.Uri) { |
| 19 | + this._panel = panel; |
| 20 | + this._extensionUri = extensionUri; |
| 21 | + // Set the webview's initial html content |
| 22 | + this._update(); |
| 23 | + |
| 24 | + // Listen for when the panel is disposed |
| 25 | + // This happens when the user closes the panel or when the panel is closed programmatically |
| 26 | + this._panel.onDidDispose(() => this.dispose(), null, this._disposables); |
| 27 | + |
| 28 | + // Update the content based on view changes (moved around the window) |
| 29 | + // this._panel.onDidChangeViewState( |
| 30 | + // e => { |
| 31 | + // if (this._panel.visible) { |
| 32 | + // this._update(); |
| 33 | + // } |
| 34 | + // }, |
| 35 | + // null, |
| 36 | + // this._disposables |
| 37 | + // ); |
| 38 | + |
| 39 | + // This can be useful if you need to handle input from the webview |
| 40 | + // Handle messages from the webview |
| 41 | + // this._panel.webview.onDidReceiveMessage( |
| 42 | + // message => { |
| 43 | + // switch (message.command) { |
| 44 | + // case 'alert': |
| 45 | + // vscode.window.showErrorMessage(message.text); |
| 46 | + // return; |
| 47 | + // } |
| 48 | + // }, |
| 49 | + // null, |
| 50 | + // this._disposables |
| 51 | + // ); |
| 52 | + |
| 53 | + |
| 54 | + const session = vscode.debug.activeDebugSession; |
| 55 | + const updateInfo = async () => { |
| 56 | + this.process_list = await this.customCommand(session, "process list"); |
| 57 | + // Insert you command |
| 58 | + // this.VAR = this.customCommand(session, "COMMAND"); |
| 59 | + |
| 60 | + const infoPanel = this._panel.webview; |
| 61 | + |
| 62 | + |
| 63 | + infoPanel.html = this._getHtmlForWebview(); |
| 64 | + }; |
| 65 | + |
| 66 | + interval = setInterval(updateInfo, 500); |
| 67 | + } |
| 68 | + |
| 69 | + public dispose() { |
| 70 | + // Clean up our resources |
| 71 | + NucleoInfo.currentPanel = undefined; |
| 72 | + clearInterval(interval); |
| 73 | + this._panel.dispose(); |
| 74 | + } |
| 75 | + |
| 76 | + // Update the webview |
| 77 | + private _update() { |
| 78 | + // const infoPanel = this._panel.webview; |
| 79 | + // infoPanel.html = this._getHtmlForWebview(); |
| 80 | + } |
| 81 | + |
| 82 | + |
| 83 | + public static createInfoPanel(extensionUri: vscode.Uri) { |
| 84 | + // Otherwise, create a new panel. |
| 85 | + const panel = vscode.window.createWebviewPanel( |
| 86 | + NucleoInfo.viewType, |
| 87 | + 'Info Nucleo', |
| 88 | + vscode.ViewColumn.Beside, |
| 89 | + getWebviewOptions(extensionUri), |
| 90 | + ); |
| 91 | + NucleoInfo.currentPanel = new NucleoInfo(panel, extensionUri); |
| 92 | + } |
| 93 | + |
| 94 | + // execute custom command |
| 95 | + private async customCommand(session: typeof vscode.debug.activeDebugSession, command: string, arg?: any){ |
| 96 | + if(session) { |
| 97 | + const sTrace = await session.customRequest('stackTrace', { threadId: 1 }); |
| 98 | + if(sTrace.stackFrames[0] === undefined){ |
| 99 | + return; |
| 100 | + } |
| 101 | + const frameId = sTrace.stackFrames[0].id; |
| 102 | + |
| 103 | + // Build and exec the command |
| 104 | + const text = '-exec ' + command; |
| 105 | + let result = session.customRequest('evaluate', {expression: text, frameId: frameId, context:'hover'}).then((response) => { |
| 106 | + return response.result; |
| 107 | + }); |
| 108 | + return result |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | + private formatProcessList(){ |
| 113 | + let processListJson = JSON.parse(this.process_list); |
| 114 | + |
| 115 | + let source = ` |
| 116 | + <div> |
| 117 | + <h3 id="palle">Processi in esecuzione:</h3> |
| 118 | + {{#each process}} |
| 119 | + {{#each this}} |
| 120 | + <p>{{@key}}: {{this}}</p> |
| 121 | + {{/each}} |
| 122 | + {{/each}} |
| 123 | + </div> |
| 124 | + `; |
| 125 | + |
| 126 | + let template = Handlebars.compile(source); |
| 127 | + return template(processListJson); |
| 128 | + } |
| 129 | + |
| 130 | + private _getHtmlForWebview() { |
| 131 | + const scriptPathOnDisk = vscode.Uri.joinPath(this._extensionUri, 'src/webview', 'main.js'); |
| 132 | + |
| 133 | + // And the uri we use to load this script in the webview |
| 134 | + const scriptUri = this._panel.webview.asWebviewUri(scriptPathOnDisk); |
| 135 | + |
| 136 | + |
| 137 | + // Local path to css styles |
| 138 | + const styleResetPath = vscode.Uri.joinPath(this._extensionUri, 'src/webview', 'reset.css'); |
| 139 | + const stylesPathMainPath = vscode.Uri.joinPath(this._extensionUri, 'src/webview', 'vscode.css'); |
| 140 | + |
| 141 | + // Uri to load styles into webview |
| 142 | + const stylesResetUri = this._panel.webview.asWebviewUri(styleResetPath); |
| 143 | + const stylesMainUri = this._panel.webview.asWebviewUri(stylesPathMainPath); |
| 144 | + |
| 145 | + console.log("uwu"); |
| 146 | + console.log(scriptUri); |
| 147 | + let sourceDocument = ` |
| 148 | + <!DOCTYPE html> |
| 149 | + <html lang="en"> |
| 150 | + <head> |
| 151 | + <meta charset="UTF-8"> |
| 152 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 153 | + <link href="${stylesResetUri}" rel="stylesheet"> |
| 154 | + <link href="${stylesMainUri}" rel="stylesheet"> |
| 155 | + <title>Info Nucleo</title> |
| 156 | + </head> |
| 157 | + <body> |
| 158 | + {{{processList}}} |
| 159 | +
|
| 160 | + <script src="${scriptUri}"></script> |
| 161 | + </body> |
| 162 | + </html> |
| 163 | + `; |
| 164 | + |
| 165 | + let template = Handlebars.compile(sourceDocument); |
| 166 | + return template({ processList: this.formatProcessList() }); |
| 167 | + } |
28 | 168 | }
|
29 | 169 |
|
30 |
| -// execute custom command |
31 |
| -// export async function executeCustomCommand(session: typeof vscode.debug.activeDebugSession, command: string, arg?: any){ |
32 |
| -// if(session === undefined){ |
33 |
| -// console.log("session not valid or undefined"); |
34 |
| -// return; |
35 |
| -// } |
36 |
| -// const sTrace = await session.customRequest('stackTrace', { threadId: 1 }); |
37 |
| -// const frameId = sTrace.stackFrames[0].id; |
38 |
| - |
39 |
| -// // build and exec the command, in this case info registers |
40 |
| -// const text = '-exec ' + command; |
41 |
| -// // const arg : DebugProtocol.EvaluateArguments = {expression: text, frameId: frameId, context:'hover'}; |
42 |
| -// session.customRequest('evaluate', {expression: text, frameId: frameId, context:'hover'}).then((response) => { |
43 |
| -// console.log("------------------EVAL----------------"); |
44 |
| -// console.log(response.result); |
45 |
| -// console.log("----------------END EVAL--------------"); |
46 |
| -// return response.result; |
47 |
| -// }); |
48 |
| -// } |
| 170 | + |
| 171 | + |
| 172 | +function getWebviewOptions(extensionUri: vscode.Uri): vscode.WebviewOptions { |
| 173 | + return { |
| 174 | + // Enable javascript in the webview |
| 175 | + enableScripts: true, |
| 176 | + }; |
| 177 | +} |
0 commit comments