Skip to content

Commit 15bdfaf

Browse files
Merge pull request #296 from ethereum/theia/webview
add support for theia in webview
2 parents 3f6791e + 1689cea commit 15bdfaf

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

packages/plugin/webview/src/lib/connector.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ function toKebabCase(text: string) {
1717
return text.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
1818
};
1919

20+
declare global {
21+
function acquireTheiaApi(): any;
22+
}
23+
24+
2025
/**
2126
* This Webview connector
2227
*/
@@ -26,9 +31,16 @@ export class WebviewConnector implements ClientConnector {
2631
isVscode: boolean
2732

2833
constructor(private options: PluginOptions<any>) {
29-
this.isVscode = ('acquireVsCodeApi' in window)
34+
// @todo(#295) check if we can merge this statement in `this.isVscode = acquireVsCodeApi !== undefined`
35+
this.isVscode = ('acquireVsCodeApi' in window) || acquireTheiaApi !== undefined
3036
// Check the parent source here
31-
this.source = this.isVscode ? window['acquireVsCodeApi']() : window.parent
37+
if ('acquireVsCodeApi' in window) {
38+
this.source = window['acquireVsCodeApi']()
39+
} else if (acquireTheiaApi !== undefined) {
40+
this.source = acquireTheiaApi()
41+
} else {
42+
this.source = window.parent
43+
}
3244
}
3345

3446

0 commit comments

Comments
 (0)