forked from cerebral/overmind
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDevtoolsPanel.ts
More file actions
113 lines (97 loc) · 2.88 KB
/
DevtoolsPanel.ts
File metadata and controls
113 lines (97 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import * as vscode from 'vscode'
import * as path from 'path'
import { log } from './utils/Logger'
export class DevtoolsPanel {
public static currentPanel: DevtoolsPanel | undefined
public static viewType = 'overmindDevtools'
// keeps track of location for overmind-devetools js bundle
public static scriptFile: any = null
private readonly _panel: vscode.WebviewPanel
private _disposables: vscode.Disposable[] = []
private constructor(panel: vscode.WebviewPanel, extensionPath: string) {
this._panel = panel
this.update()
this._panel.onDidDispose(() => this.dispose(), null, this._disposables)
this._panel.onDidChangeViewState(
(e) => {
if (this._panel.visible) {
this.update()
}
},
null,
this._disposables
)
this._panel.webview.onDidReceiveMessage(
(message) => {
switch (message.command) {
case 'alert':
vscode.window.showErrorMessage(message.text)
}
},
null,
this._disposables
)
}
dispose(): any {
DevtoolsPanel.currentPanel = undefined
this._panel.dispose()
while (this._disposables.length) {
const x = this._disposables.pop()
if (x) {
x.dispose()
}
}
}
private update() {
log('Extension.update')
this._panel.webview.html = this.getHtmlForWevbiew()
}
private getHtmlForWevbiew(): string {
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<link
href="https://fonts.googleapis.com/css?family=Source+Code+Pro"
rel="stylesheet"
/>
<link
href="https://fonts.googleapis.com/css?family=Nunito:400,700"
rel="stylesheet"
/>
</head>
<body>
<script type="text/javascript" src="http://localhost:8080/bundle.js"></script>
</body>
</html>
`
}
static createOrShow(extensionPath: string) {
const column = vscode.window.activeTextEditor
? vscode.window.activeTextEditor.viewColumn
: undefined
if (DevtoolsPanel.currentPanel) {
DevtoolsPanel.currentPanel._panel.reveal(column)
return
}
const panel = vscode.window.createWebviewPanel(
DevtoolsPanel.viewType,
'Overmind',
column || vscode.ViewColumn.One,
{
enableScripts: true,
retainContextWhenHidden: true,
localResourceRoots: [
vscode.Uri.file(path.join(extensionPath, 'devtoolsDist')),
],
}
)
DevtoolsPanel.currentPanel = new DevtoolsPanel(panel, extensionPath)
}
static revive(webViewPanel: vscode.WebviewPanel, extensionPath: string) {
DevtoolsPanel.currentPanel = new DevtoolsPanel(webViewPanel, extensionPath)
}
}