-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import * as vscode from "vscode"; | ||
|
||
export default class SidebarProvider implements vscode.WebviewViewProvider { | ||
_view?: vscode.WebviewView; | ||
_doc?: vscode.TextDocument; | ||
|
||
constructor(private readonly _extensionUri: vscode.Uri) { } | ||
|
||
public resolveWebviewView(webviewView: vscode.WebviewView) { | ||
this._view = webviewView; | ||
|
||
webviewView.webview.options = { | ||
// Allow scripts in the webview | ||
enableScripts: true, | ||
|
||
localResourceRoots: [this._extensionUri], | ||
}; | ||
|
||
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview); | ||
|
||
// Listen for messages from the Sidebar component and execute action | ||
webviewView.webview.onDidReceiveMessage(async (data) => { | ||
switch (data.type) { | ||
// case "onSomething: { | ||
// // code here... | ||
// break; | ||
// } | ||
case "onInfo": { | ||
if (!data.value) { | ||
return; | ||
} | ||
vscode.window.showInformationMessage(data.value); | ||
break; | ||
} | ||
case "onError": { | ||
if (!data.value) { | ||
return; | ||
} | ||
vscode.window.showErrorMessage(data.value); | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
} | ||
|
||
public revive(panel: vscode.WebviewView) { | ||
this._view = panel; | ||
} | ||
|
||
private _getHtmlForWebview(webview: vscode.Webview) { | ||
const styleResetUri = webview.asWebviewUri( | ||
vscode.Uri.joinPath(this._extensionUri, "media", "reset.css") | ||
); | ||
const styleVSCodeUri = webview.asWebviewUri( | ||
vscode.Uri.joinPath(this._extensionUri, "media", "vscode.css") | ||
); | ||
const scriptUri = webview.asWebviewUri( | ||
vscode.Uri.joinPath(this._extensionUri, "out", "compiled/sidebar.js") | ||
); | ||
const styleMainUri = webview.asWebviewUri( | ||
vscode.Uri.joinPath(this._extensionUri, "out", "compiled/sidebar.css") | ||
); | ||
|
||
// Use a nonce to only allow a specific script to be run. | ||
const nonce = getNonce(); | ||
|
||
return `<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
</head> | ||
<body> | ||
<p>hahahha</p> | ||
</body> | ||
</html>`; | ||
} | ||
} | ||
|
||
function getNonce() { | ||
let text = ''; | ||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
for (let i = 0; i < 32; i++) { | ||
text += possible.charAt(Math.floor(Math.random() * possible.length)); | ||
} | ||
return text; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,5 +58,5 @@ export default () => [ | |
}), | ||
], | ||
clean: true, | ||
}), | ||
}) | ||
]; |