diff --git a/packages/core/src/stepFunctions/workflowStudio/handleMessage.ts b/packages/core/src/stepFunctions/workflowStudio/handleMessage.ts index a3bc6a38d3a..83c921e1170 100644 --- a/packages/core/src/stepFunctions/workflowStudio/handleMessage.ts +++ b/packages/core/src/stepFunctions/workflowStudio/handleMessage.ts @@ -14,6 +14,7 @@ import { FileChangeEventTrigger, SyncFileRequestMessage, ApiCallRequestMessage, + UnsupportedMessage, } from './types' import { submitFeedback } from '../../feedback/vue/submitFeedback' import { placeholder } from '../../shared/vscode/commands2' @@ -56,13 +57,21 @@ export async function handleMessage(message: Message, context: WebviewContext) { case Command.API_CALL: apiCallMessageHandler(message as ApiCallRequestMessage, context) break + default: + void handleUnsupportedMessage(context, message) + break } } else if (messageType === MessageType.BROADCAST) { switch (command) { case Command.LOAD_STAGE: void loadStageMessageHandler(context) break + default: + void handleUnsupportedMessage(context, message) + break } + } else { + void handleUnsupportedMessage(context, message) } } @@ -206,3 +215,18 @@ function apiCallMessageHandler(request: ApiCallRequestMessage, context: WebviewC const apiHandler = new WorkflowStudioApiHandler(globals.awsContext.getCredentialDefaultRegion(), context) apiHandler.performApiCall(request).catch((error) => logger.error('%s API call failed: %O', request.apiName, error)) } + +/** + * Handles unsupported or unrecognized messages by sending a response to the webview. Ensures compatibility with future + * commands and message types, preventing issues if the user has an outdated extension version. + * @param context The context object containing information about the webview environment + * @param command The command received from the webview + * @param messageType The type of the message received + */ +async function handleUnsupportedMessage(context: WebviewContext, originalMessage: Message) { + await context.panel.webview.postMessage({ + messageType: MessageType.RESPONSE, + command: Command.UNSUPPORTED_COMMAND, + originalMessage, + } as UnsupportedMessage) +} diff --git a/packages/core/src/stepFunctions/workflowStudio/types.ts b/packages/core/src/stepFunctions/workflowStudio/types.ts index 01748b8a1b0..68392956476 100644 --- a/packages/core/src/stepFunctions/workflowStudio/types.ts +++ b/packages/core/src/stepFunctions/workflowStudio/types.ts @@ -41,6 +41,7 @@ export enum Command { OPEN_FEEDBACK = 'OPEN_FEEDBACK', CLOSE_WFS = 'CLOSE_WFS', API_CALL = 'API_CALL', + UNSUPPORTED_COMMAND = 'UNSUPPORTED_COMMAND', } export type FileWatchInfo = { @@ -61,6 +62,10 @@ export interface FileChangedMessage extends Message { trigger: FileChangeEventTrigger } +export interface UnsupportedMessage extends Message { + originalMessage: Message +} + export interface InitResponseMessage extends Omit { isSuccess: boolean failureReason?: string diff --git a/packages/core/src/stepFunctions/workflowStudio/workflowStudioEditorProvider.ts b/packages/core/src/stepFunctions/workflowStudio/workflowStudioEditorProvider.ts index 9d8748db589..b08be09cc46 100644 --- a/packages/core/src/stepFunctions/workflowStudio/workflowStudioEditorProvider.ts +++ b/packages/core/src/stepFunctions/workflowStudio/workflowStudioEditorProvider.ts @@ -6,11 +6,10 @@ import * as vscode from 'vscode' import { getLogger } from '../../shared/logger/logger' import request from '../../shared/request' -import fs from '../../shared/fs/fs' import { getClientId } from '../../shared/telemetry/util' import { telemetry } from '../../shared/telemetry/telemetry' import globals from '../../shared/extensionGlobals' -import { getRandomString, getStringHash } from '../../shared/utilities/textUtilities' +import { getStringHash } from '../../shared/utilities/textUtilities' import { ToolkitError } from '../../shared/errors' import { getTabSizeSetting } from '../../shared/utilities/editorUtilities' import { WorkflowStudioEditor } from './workflowStudioEditor' @@ -80,7 +79,7 @@ export class WorkflowStudioEditorProvider implements vscode.CustomTextEditorProv * @private */ private getWebviewContent = async () => { - let htmlFileSplit = this.webviewHtml.split('') + const htmlFileSplit = this.webviewHtml.split('') // Set asset source to CDN const source = isLocalDev ? localhost : cdn @@ -93,20 +92,8 @@ export class WorkflowStudioEditorProvider implements vscode.CustomTextEditorProv const isDarkMode = theme === vscode.ColorThemeKind.Dark || theme === vscode.ColorThemeKind.HighContrast const tabSizeTag = `` const darkModeTag = `` - let html = `${htmlFileSplit[0]} ${baseTag} ${localeTag} ${darkModeTag} ${tabSizeTag} ${htmlFileSplit[1]}` - const nonce = getRandomString() - const localDevURL = isLocalDev ? localhost : '' - htmlFileSplit = html.split("script-src 'self'") - - html = `${htmlFileSplit[0]} script-src 'self' 'nonce-${nonce}' ${localDevURL} ${htmlFileSplit[1]}` - htmlFileSplit = html.split('') - - const script = await fs.readFileText( - vscode.Uri.joinPath(globals.context.extensionUri, 'resources', 'js', 'vsCodeExtensionInterface.js') - ) - - return `${htmlFileSplit[0]} ${htmlFileSplit[1]}` + return `${htmlFileSplit[0]} ${baseTag} ${localeTag} ${darkModeTag} ${tabSizeTag} ${htmlFileSplit[1]}` } /** diff --git a/packages/toolkit/package.json b/packages/toolkit/package.json index 42f4b9089a9..7fabb480239 100644 --- a/packages/toolkit/package.json +++ b/packages/toolkit/package.json @@ -4151,6 +4151,12 @@ "mac": "cmd+shift+v", "when": "editorTextFocus && editorLangId == asl || editorTextFocus && editorLangId == asl-yaml" }, + { + "command": "noop", + "key": "ctrl+z", + "mac": "cmd+z", + "when": "aws.stepFunctions.isWorkflowStudioFocused" + }, { "command": "aws.samcli.sync", "key": "ctrl+shift+s",