vscode#WebviewView TypeScript Examples
The following examples show how to use
vscode#WebviewView.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: webview.ts From cloudmusic-vscode with MIT License | 5 votes |
private static _view?: WebviewView;
Example #2
Source File: trivy_helpview.ts From trivy-vscode-extension with Apache License 2.0 | 5 votes |
resolveWebviewView(webviewView: WebviewView, _context: WebviewViewResolveContext<unknown>, _token: CancellationToken): void | Thenable<void> {
this.view = webviewView.webview;
this.update(null);
}
Example #3
Source File: webviewView.ts From vscode-todo-md with MIT License | 5 votes |
private _view?: WebviewView;
Example #4
Source File: webview.ts From cloudmusic-vscode with MIT License | 4 votes |
resolveWebviewView(
webview: WebviewView
// context: WebviewViewResolveContext
// token: CancellationToken
): void {
const extUri = AccountViewProvider.context.extensionUri;
AccountViewProvider._view = webview;
webview.title = i18n.word.account;
webview.webview.options = {
enableScripts: true,
localResourceRoots: [extUri, Uri.file(SETTING_DIR)],
};
webview.webview.onDidReceiveMessage((msg: ProviderCMsg) => {
switch (msg.command) {
case "pageLoaded":
AccountViewProvider.master();
AccountViewProvider.account([...AccountManager.accounts.values()]);
AccountViewProvider.metadata();
AccountViewProvider.wasmVolume(
AccountViewProvider.context.globalState.get(VOLUME_KEY, 85)
);
AccountViewProvider.wasmSpeed(
AccountViewProvider.context.globalState.get(SPEED_KEY, 1)
);
if (State.wasm) {
const audioUri = Uri.joinPath(extUri, "media", "audio");
workspace.fs.readDirectory(audioUri).then((items) => {
const files = items
.filter(([name]) => name.startsWith("silent"))
.map(([name]) =>
webview.webview
.asWebviewUri(Uri.joinPath(audioUri, name))
.toString()
);
const msg: ProviderSMsg = { command: "test", files };
void webview.webview.postMessage(msg);
}, console.error);
State.downInit(); // 3
}
break;
case "account":
AccountManager.accountQuickPick(msg.userId);
break;
case "end":
if (State.repeat) IPC.load();
else void commands.executeCommand("cloudmusic.next");
break;
case "load":
IPC.loaded();
break;
case "position":
IPC.position(msg.pos);
break;
case "playing":
IPC.playing(msg.playing);
break;
default:
void commands.executeCommand(`cloudmusic.${msg.command}`);
break;
}
});
const js = webview.webview
.asWebviewUri(Uri.joinPath(extUri, "dist", "provider.js"))
.toString();
const css = webview.webview
.asWebviewUri(Uri.joinPath(extUri, "dist", "style.css"))
.toString();
webview.webview.html = `
<!DOCTYPE html>
<html
lang="en"
${window.activeColorTheme.kind === ColorThemeKind.Light ? "" : 'class="dark"'}
>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>${i18n.word.account}</title>
<link rel="stylesheet" type="text/css" href=${css} />
</head>
<body>
<div id="root"></div>
</body>
<script>window.enablePlayer=${State.wasm ? "true" : "false"}</script>
<script type="module" src=${js} nonce=${getNonce()}></script>
</html>`;
}
Example #5
Source File: webviewView.ts From vscode-todo-md with MIT License | 4 votes |
public resolveWebviewView(
webviewView: WebviewView,
context: WebviewViewResolveContext,
_token: CancellationToken,
) {
this._view = webviewView;
const localResourceRoots = [
this._extensionUri,
];
if ($config.webview.customCSSPath) {
localResourceRoots.push(Uri.file(path.dirname($config.webview.customCSSPath)));
}
webviewView.webview.options = {
enableScripts: true,
enableCommandUris: true,
localResourceRoots,
};
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
webviewView.webview.onDidReceiveMessage(async (message: MessageFromWebview) => {
switch (message.type) {
// ──── Needs to update everything ────────────────────────────
case 'webviewLoaded': {
this.sendEverything();
break;
}
case 'toggleDone': {
await toggleDoneAtLine(await getActiveOrDefaultDocument(), message.value);
await updateEverything();
break;
}
case 'toggleTaskCollapse': {
await toggleTaskCollapse(await getActiveOrDefaultDocument(), message.value);
await updateEverything();
break;
}
case 'editTask': {
await editTask(await getActiveOrDefaultDocument(), message.value);
await updateEverything();
break;
}
case 'startTask': {
await startTaskAtLine(message.value, await getActiveOrDefaultDocument());
await updateEverything();
break;
}
case 'toggleTaskCollapseRecursive': {
await toggleTaskCollapseRecursive(await getActiveOrDefaultDocument(), message.value);
await updateEverything();
break;
}
case 'incrementCount': {
await incrementCountForTask(await getActiveOrDefaultDocument(), message.value, getTaskAtLineExtension(message.value)!);
await updateEverything();
break;
}
case 'decrementCount': {
await decrementCountForTask(await getActiveOrDefaultDocument(), message.value, getTaskAtLineExtension(message.value)!);
await updateEverything();
break;
}
case 'deleteTask': {
await tryToDeleteTask(await getActiveOrDefaultDocument(), message.value);
await updateEverything();
break;
}
case 'editTaskRawText': {
await editTaskRawText(await getActiveOrDefaultDocument(), message.value.lineNumber, message.value.newRawText);
await updateEverything();
break;
}
// ──── No need to update everything ──────────────────────────
case 'showNotification': {
window.showInformationMessage(message.value);
break;
}
case 'goToTask': {
revealTask(message.value);
break;
}
case 'updateWebviewTitle': {
this.updateTitle(message.value);
break;
}
case 'followLink': {
followLink(message.value);
break;
}
case 'setDueDate': {
openSetDueDateInputbox(await getActiveOrDefaultDocument(), [message.value]);
break;
}
}
});
/**
* Update webview on it's visibility change (only when it becomes visible).
*/
webviewView.onDidChangeVisibility(e => {
if (webviewView.visible === true) {
this.sendEverything();
}
});
}