Skip to content

Resolve failed launch on CodeAlly #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
filter events by source=coderoad
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Nov 21, 2021
commit 335a9c72f625111f4898735e76a11ac5bc5219c1
5 changes: 5 additions & 0 deletions src/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class Channel implements Channel {

// receive from webview
public receive = async (action: T.Action): Promise<void> => {
if (action.source !== 'coderoad') {
// filter out events from other extensions
return
}

// action may be an object.type or plain string
const actionType: string = typeof action === 'string' ? action : action.type

Expand Down
6 changes: 5 additions & 1 deletion src/services/webview/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ const createReactWebView = ({ extensionPath, channel }: ReactWebViewProps): Outp

// Handle messages from the webview
const receive = channel.receive
const send = (action: T.Action) => panel.webview.postMessage(action)
const send = (action: T.Action) =>
panel.webview.postMessage({
...action,
source: 'coderoad', // filter events on client by source. origin is not reliable
})

panel.webview.onDidReceiveMessage(receive, null, disposables)

Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface Position {
// current tutorial state

export interface Action {
source?: 'coderoad' // filter received actions by this
type: string
payload?: any
meta?: any
Expand Down
16 changes: 10 additions & 6 deletions web-app/src/services/state/useStateMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ declare let acquireVsCodeApi: any
const editor = acquireVsCodeApi()
const editorSend = (action: T.Action) => {
logger(`TO EXT: "${action.type}"`)
return editor.postMessage(action)
return editor.postMessage({
...action,
source: 'coderoad', // filter events by source on editor side
})
}

// router finds first state match of <Route path='' />
Expand All @@ -31,14 +34,15 @@ const useStateMachine = (): Output => {
// event bus listener
React.useEffect(() => {
const listener = 'message'
// propograte channel event to state machine
// propagate channel event to state machine
const handler = (event: any) => {
// ensure events are coming from coderoad webview
if (!event.origin.match(/^vscode-webview/)) {
return
}
// NOTE: must call event.data, cannot destructure. VSCode acts odd
const action = event.data

if (action.source !== 'coderoad') {
// filter out events from other extensions
return
}
sendWithLog(action)
}
window.addEventListener(listener, handler)
Expand Down