// The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode in your code below const vscode = require('vscode'); const openFilesAndURLs = require('./openFilesAndUrls.js') const {initFrame, runFrame, getCurrentPreviewState} = require('./openFrame.js') const {updateCount, initTreeView} = require('./updateCount.js') // const savedTabsPath = // const path = require('path'); // This method is called when your extension is activated // Your extension is activated the very first time the command is executed /** * * @param {vscode.ExtensionContext} context */ console.log("ITK LOGS!!!!!") let _context; function activate(context) { console.log('Congratulations, your extension "itk" is now active!'); initTreeView(context); initCmdInVsCodeTerminal(context) initOpenChromeUrl(context) initCloseTabs(context) // initHtml(context, getTemplate()) // initWelcome(context) // initTests(context) initFrame(context) initFileChanges(context) initGetTabs(context) startAction(context); } async function startAction(context) { _context = context; updateCount(123) // runFrame('https://itrum.ru') // openFilesAndURLs({beforeFn: closeAllTabs}) // openFilesAndURLs({beforeFn: () => {}}) // openHtml() // openWelcomeFrame() // openTestsFrame() // setTimeout(() => { // getTabs(); // }) // openTabsDirectly() // openUrlInChrome(); } function initFileChanges(context) { let disposable = vscode.window.onDidChangeVisibleTextEditors(backupTabs); context.subscriptions.push(disposable); // Add to subscriptions to prevent memory leaks } async function backupTabs() { let v = await getTabs() writeFile('./../files/backupTabs.js', `module.exports = ${JSON.stringify(v, null, 4)}`) } global.backupTabs = backupTabs; function writeFile(relPath, content) { const filePath = path.join(__dirname, relPath); fs.writeFileSync(filePath, content); } async function openStartTabs(groups) { const openPromises = []; const workspaceFolder = vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders[0]; let columnIndex = 1; // Start from the first column groups.forEach((group, index) => { group.forEach((file) => { if (file.url) { // If the object contains a URL, open it in a Webview (iframe) // openPromises.push( runFrame(file)); runFrame(file, columnIndex + index) } else if (file.relPath) { // Resolve the file path relative to the workspace folder const filePath = vscode.Uri.joinPath(workspaceFolder.uri, file.relPath); // Open the file in a new tab (in a new column, if needed) openPromises.push(vscode.workspace.openTextDocument(filePath) .then(doc => { // If it's the first file of a group, open it in the first column const columnToUse = columnIndex + index; // Show the document in the appropriate column vscode.window.showTextDocument(doc, { viewColumn: columnToUse, preview: false }); // Move to the next column after opening each file })); } }); }); } function initGetTabs(context) { let disposable = vscode.commands.registerCommand('itk.getTabs', () => getTabs()); context.subscriptions.push(disposable); } function getTabs() { const tabGroups = vscode.window.tabGroups.all; if (tabGroups.length === 0) { vscode.window.showInformationMessage('No open tabs found.'); return; } let tabInfo = []; const workspaceFolder = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath; // Get workspace folder tabGroups.forEach((group, index) => { let curTabsInGroup = [] group.tabs.forEach(tab => { let filePath = ""; if (tab.input instanceof vscode.TabInputText) { filePath = tab.input.uri.fsPath; } let relativePath = ""; if (filePath) { relativePath = path.relative(workspaceFolder, filePath); // Use path.relative } curTabsInGroup.push({ group: tab.group.viewColumn, label: tab.label, isActive: tab.isActive, isPinned: tab.isPinned, absPath: filePath, relPath: relativePath, }); }); tabInfo.push(curTabsInGroup) }); vscode.window.showInformationMessage(`Opened Tabs:\n${tabInfo.join('\n')}`); return {tabs: tabInfo, preview: getCurrentPreviewState()}; } function initOpenChromeUrl(context) { let disposable = vscode.commands.registerCommand('itk.openUrlInBrowser', async () => { openUrlInChrome() }); context.subscriptions.push(disposable); } async function openUrlInChrome() { let url = 'https://new.csb.app'; // if (url) { // try { // new URL(url); // Validate URL // } catch (error) { // vscode.window.showErrorMessage("Invalid URL: " + error.message); // return; // } // // Dynamic import: // try { // const open = await import('open'); // Correct way to import ES module // await open.default(url); // Use open.default to call the function // } catch (error) { // vscode.window.showErrorMessage("Could not open URL: " + error.message); // console.error("Open URL Error:", error); // } // } } function initCloseTabs(context) { let disposable = vscode.commands.registerCommand('itk.closeAllTabs', closeAllTabs); context.subscriptions.push(disposable); } async function closeAllTabs() { try { await vscode.commands.executeCommand('workbench.action.closeAllEditors'); } catch (e) { vscode.window.showInformationMessage("Tabs Closing Error"); } } function initCmdInVsCodeTerminal(context) { const disposable = vscode.commands.registerCommand('itk.openTabs', () => restoreBackupTabs()); context.subscriptions.push(disposable); } function restoreBackupTabs() { setTimeout(() => { vscode.window.showInformationMessage('Tabs Restored From backup'); }, 500) } // This method is called when your extension is deactivated function deactivate() { console.log("ITK DEACTIVE") } module.exports = { activate, deactivate }