From cbc244293a68caaaf97241789e783a899c9d257d Mon Sep 17 00:00:00 2001 From: Adam Driscoll Date: Mon, 22 Jul 2024 07:19:55 -0500 Subject: [PATCH] Handle Persistent Terminal Sessions --- vscode/powershellprotools/package.json | 2 +- vscode/powershellprotools/src/extension.ts | 23 +++++++++++++++++-- .../src/services/powershellservice.ts | 9 ++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/vscode/powershellprotools/package.json b/vscode/powershellprotools/package.json index cc61739..db63c70 100644 --- a/vscode/powershellprotools/package.json +++ b/vscode/powershellprotools/package.json @@ -2,7 +2,7 @@ "name": "powershellprotools", "displayName": "PowerShell Pro Tools", "description": "Powerful extensions for PowerShell development.", - "version": "2024.7.4", + "version": "2024.7.5", "publisher": "ironmansoftware", "repository": { "type": "git", diff --git a/vscode/powershellprotools/src/extension.ts b/vscode/powershellprotools/src/extension.ts index e7e28c3..442e329 100644 --- a/vscode/powershellprotools/src/extension.ts +++ b/vscode/powershellprotools/src/extension.ts @@ -5,7 +5,7 @@ import { convertToUdElement } from './commands/convertToUdElement'; import { profile, clearProfiling } from './commands/profile'; import { showWinFormDesigner } from './commands/formsDesigner'; import { generateWinForm } from './commands/generateWinForm'; -import { PowerShellService } from './services/powershellservice'; +import { PowerShellService, SessionStatus } from './services/powershellservice'; import { Container } from './container'; import { showDataGrid } from './commands/showDataGrid'; import { statusBarItemMenu } from './commands/statusBarItemMenu'; @@ -48,7 +48,7 @@ export interface IPowerShellExtensionClient { export async function activate(context: vscode.ExtensionContext) { - powerShellService = new PowerShellService(context); + var service = powerShellService = new PowerShellService(context); context.subscriptions.push(showDataGrid(context)); context.subscriptions.push(packageAsExe()); context.subscriptions.push(convertToUdElement()); @@ -72,6 +72,25 @@ export async function activate(context: vscode.ExtensionContext) { return; } + const configuration: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("terminal.integrated"); + var persistentSessions = configuration.get("enablePersistentSessions"); + if (persistentSessions) { + var result = await vscode.window.showErrorMessage("PowerShell Pro Tools requires the terminal.integrated.enablePersistentSessions setting to be disabled.", "Disable", "Learn About Persistent Sessions"); + if (result == "Learn About Persistent Sessions") { + vscode.env.openExternal(vscode.Uri.parse("https://code.visualstudio.com/docs/terminal/advanced#_persistent-sessions")); + } + else if (result == "Disable") { + await configuration.update("enablePersistentSessions", false, true); + vscode.window.showInformationMessage("Persistent sessions have been disabled. Please reload the window for the changes to take effect."); + } + else { + vscode.window.showErrorMessage("PowerShell Pro Tools did not start because Persistent Terminal Sessions is enabled."); + service.setSessionStatus(SessionStatus.Disabled); + } + + return; + } + if (!extension.isActive) { await extension.activate(); const powerShellExtensionClient = extension!.exports as IPowerShellExtensionClient; diff --git a/vscode/powershellprotools/src/services/powershellservice.ts b/vscode/powershellprotools/src/services/powershellservice.ts index dc720a2..c129fcd 100644 --- a/vscode/powershellprotools/src/services/powershellservice.ts +++ b/vscode/powershellprotools/src/services/powershellservice.ts @@ -13,7 +13,8 @@ const fs = require('fs'); export enum SessionStatus { Initializing, Failed, - Connected + Connected, + Disabled } export class PowerShellService { @@ -59,7 +60,7 @@ export class PowerShellService { this.setSessionStatus(SessionStatus.Initializing); } - private setSessionStatus(status: SessionStatus): void { + setSessionStatus(status: SessionStatus): void { // Set color and icon for 'Running' by default let statusIconText = "$(sync) PowerShell Pro Tools"; let statusColor = "#f3fc74"; @@ -73,6 +74,10 @@ export class PowerShellService { statusIconText = "$(alert) PowerShell Pro Tools"; statusColor = "#fcc174"; toolTip = "PowerShell Pro Tools failed to connect. Check out the Output channel for PowerShell Pro Tools for more information."; + } else if (status === SessionStatus.Disabled) { + statusIconText = "$(circle-slash) PowerShell Pro Tools"; + statusColor = "#fcc174"; + toolTip = "PowerShell Pro Tools is disabled because Persistent Terminal Sessions is enabled. Please disable Persistent Terminal Sessions and reload the window."; } this.statusBarItem.color = statusColor;