Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/core/src/stepFunctions/workflowStudio/handleMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
FileChangeEventTrigger,
SyncFileRequestMessage,
ApiCallRequestMessage,
UnsupportedMessage,
} from './types'
import { submitFeedback } from '../../feedback/vue/submitFeedback'
import { placeholder } from '../../shared/vscode/commands2'
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
5 changes: 5 additions & 0 deletions packages/core/src/stepFunctions/workflowStudio/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -61,6 +62,10 @@ export interface FileChangedMessage extends Message {
trigger: FileChangeEventTrigger
}

export interface UnsupportedMessage extends Message {
originalMessage: Message
}

export interface InitResponseMessage extends Omit<FileChangedMessage, 'trigger'> {
isSuccess: boolean
failureReason?: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -80,7 +79,7 @@ export class WorkflowStudioEditorProvider implements vscode.CustomTextEditorProv
* @private
*/
private getWebviewContent = async () => {
let htmlFileSplit = this.webviewHtml.split('<head>')
const htmlFileSplit = this.webviewHtml.split('<head>')

// Set asset source to CDN
const source = isLocalDev ? localhost : cdn
Expand All @@ -93,20 +92,8 @@ export class WorkflowStudioEditorProvider implements vscode.CustomTextEditorProv
const isDarkMode = theme === vscode.ColorThemeKind.Dark || theme === vscode.ColorThemeKind.HighContrast
const tabSizeTag = `<meta name='tab-size' content='${getTabSizeSetting()}'>`
const darkModeTag = `<meta name='dark-mode' content='${isDarkMode}'>`
let html = `${htmlFileSplit[0]} <head> ${baseTag} ${localeTag} ${darkModeTag} ${tabSizeTag} ${htmlFileSplit[1]}`

const nonce = getRandomString()
const localDevURL = isLocalDev ? localhost : ''
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this part no longer relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually never used this for WFS integration as we never added custom scripts on webview side - I think I originally implemented it the same way as it was for Threat composer editor (code).

Our integration works fine without this extra code, similar to how InfraComposer integration works (code)

htmlFileSplit = html.split("script-src 'self'")

html = `${htmlFileSplit[0]} script-src 'self' 'nonce-${nonce}' ${localDevURL} ${htmlFileSplit[1]}`
htmlFileSplit = html.split('<body>')

const script = await fs.readFileText(
vscode.Uri.joinPath(globals.context.extensionUri, 'resources', 'js', 'vsCodeExtensionInterface.js')
)

return `${htmlFileSplit[0]} <body> <script nonce='${nonce}'>${script}</script> ${htmlFileSplit[1]}`
return `${htmlFileSplit[0]} <head> ${baseTag} ${localeTag} ${darkModeTag} ${tabSizeTag} ${htmlFileSplit[1]}`
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/toolkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading