const vscode = require('vscode'); function activate(context) { context.subscriptions.push( vscode.window.registerWebviewPanelSerializer('myWebviewType', new MyWebviewSerializer()) ); context.subscriptions.push( vscode.commands.registerCommand('myExtension.openWebview', () => { openWebview(context); }) ); } class MyWebviewSerializer { async deserializeWebviewPanel(panel, state) { console.log("Restoring WebView", state); panel.webview.options = { enableScripts: true, localResourceRoots: [] }; const url = state?.url || 'https://example.com'; // Fallback URL panel.webview.html = getWebviewContent(url); } } function openWebview(context) { const url = vscode.workspace.getConfiguration().get('itk.lastUrl') || 'https://example.com'; const panel = vscode.window.createWebviewPanel( 'myWebviewType', 'My Webview', vscode.ViewColumn.One, { enableScripts: true, localResourceRoots: [] } ); panel.webview.html = getWebviewContent(url); panel.onDidDispose(() => { vscode.workspace.getConfiguration().update('itk.lastUrl', url, vscode.ConfigurationTarget.Global); }, null, context.subscriptions); } function getWebviewContent(url) { return ` WebView `; } function deactivate() {} function initWelcome(context, defaultUrl) { context.subscriptions.push( vscode.commands.registerCommand('itk.openWelcomeFrame', () => { openWelcomeFrame(); }) ); } function initTests(context, defaultUrl) { context.subscriptions.push( vscode.commands.registerCommand('itk.openTests', () => { openTestsFrame(); }) ); } function openWelcomeFrame() { runFrame({ url: 'https://itrum.ru', name: 'ITK Welcome Frame', id: 'itkWelcomeFrame' }) } function openTestsFrame() { runFrame({ url: 'https://itrum.ru', name: 'ITK Tests', id: 'itkTests' }) } function runFrame({ url, name, id} , groupId) { const panel = vscode.window.createWebviewPanel( id, // Identifies the webview name, // Title of the panel vscode.ViewColumn.One, // Show in the first column { enableScripts: true, // Allows JavaScript execution localResourceRoots: [] // Define where local resources can be loaded from (if needed) } ); panel.reveal(vscode.ViewColumn.One + groupId - 1); console.log('groupId', groupId) // Set HTML content for the Webview panel.webview.html = getWebviewContent(url); } function getWebviewContent(url) { return ` ITK Academy `; } function initFrame(context) { context.subscriptions.push( vscode.window.registerWebviewPanelSerializer('myWebviewType', new MyWebviewSerializer()) ); } function getTemplate() { return ` Cat Coding

Welcome to ITK.academy!!!!!

This is a custom welcome view.

You can add your own HTML content here.

`; } module.exports = { initWelcome, getTemplate, initTests, initFrame, openWelcomeFrame, openTestsFrame, runFrame };