Skip to content
This repository was archived by the owner on Apr 28, 2020. It is now read-only.

Commit 8aa7b57

Browse files
committed
Add rebuild button and command
1 parent b0380e4 commit 8aa7b57

File tree

2 files changed

+52
-34
lines changed

2 files changed

+52
-34
lines changed

sail.js

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,61 @@ function stopReloadUI() {
2020
removeElementsByClass("msgbox-overlay")
2121
}
2222

23-
let tty
24-
window.addEventListener("ide-ready", () => {
25-
window.ide.workbench.onFileSaved((ev) => {
26-
if (!ev.endsWith(".sail/Dockerfile")) {
27-
return
28-
}
23+
function rebuild() {
24+
const tsrv = window.ide.workbench.terminalService
2925

30-
const srv = window.ide.workbench.terminalService
26+
if (tty == null) {
27+
tty = tsrv.createTerminal({
28+
name: "sail",
29+
isRendererOnly: true,
30+
}, false)
31+
} else {
32+
tty.clear()
33+
}
34+
let oldTTY = tsrv.getActiveInstance()
35+
tsrv.setActiveInstance(tty)
36+
// Show the panel and focus it to prevent the user from editing the Dockerfile.
37+
tsrv.showPanel(true)
3138

32-
if (tty == null) {
33-
tty = srv.createTerminal({
34-
name: "sail",
35-
isRendererOnly: true,
36-
}, false)
39+
startReloadUI()
40+
41+
const ws = new WebSocket("ws://" + location.host + "/sail/api/v1/reload")
42+
ws.onmessage = (ev) => {
43+
const msg = JSON.parse(ev.data)
44+
const out = atob(msg.v).replace(/\n/g, "\n\r")
45+
tty.write(out)
46+
}
47+
ws.onclose = (ev) => {
48+
if (ev.code === 1000) {
49+
tsrv.setActiveInstance(oldTTY)
3750
} else {
38-
tty.clear()
39-
}
40-
let oldTTY = srv.getActiveInstance()
41-
srv.setActiveInstance(tty)
42-
// Show the panel and focus it to prevent the user from editing the Dockerfile.
43-
srv.showPanel(true)
44-
45-
startReloadUI()
46-
47-
const ws = new WebSocket("ws://" + location.host + "/sail/api/v1/reload")
48-
ws.onmessage = (ev) => {
49-
const msg = JSON.parse(ev.data)
50-
const out = atob(msg.v).replace(/\n/g, "\n\r")
51-
tty.write(out)
51+
alert("reload failed; please see logs in sail terminal")
5252
}
53-
ws.onclose = (ev) => {
54-
if (ev.code === 1000) {
55-
srv.setActiveInstance(oldTTY)
56-
} else {
57-
alert("reload failed; please see logs in sail terminal")
58-
}
59-
stopReloadUI()
53+
stopReloadUI()
54+
}
55+
}
56+
57+
let tty
58+
window.addEventListener("ide-ready", () => {
59+
const statusBarService = window.ide.workbench.statusbarService
60+
statusBarService.addEntry({
61+
text: "rebuild",
62+
tooltip: "press super+alt+r to rebuild",
63+
command: "rebuild-sail-container"
64+
// showBeak: true <- what does this do?
65+
}, 0)
66+
67+
const commandRegistry = window.ide.workbench.commandRegistry
68+
commandRegistry.registerCommand({
69+
id: "rebuild-sail-container",
70+
handler: (accessor, args) => {
71+
rebuild()
72+
},
73+
description: {
74+
description: "Rebuild sail container",
75+
args: []
6076
}
6177
})
78+
79+
const
6280
})

sail.js.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package main
22

33
//go:generate go run sail.js_gen.go
4-
const sailJS = "function startReloadUI() {\n const div = document.createElement(\"div\")\n div.className = \"msgbox-overlay\"\n div.style.opacity = 1\n div.style.textAlign = \"center\"\n div.innerHTML = `<div class=\"msgbox\">\n<div class=\"msg\">Reloading container</div>\n</div>`\n document.querySelector(\".monaco-workbench\").appendChild(div)\n}\n\nfunction removeElementsByClass(className) {\n let elements = document.getElementsByClassName(className);\n for (let e of elements) {\n e.parentNode.removeChild(e)\n }\n}\n\nfunction stopReloadUI() {\n removeElementsByClass(\"msgbox-overlay\")\n}\n\nlet tty\nwindow.addEventListener(\"ide-ready\", () => {\n window.ide.workbench.onFileSaved((ev) => {\n if (!ev.endsWith(\".sail/Dockerfile\")) {\n return\n }\n\n const srv = window.ide.workbench.terminalService\n\n if (tty == null) {\n tty = srv.createTerminal({\n name: \"sail\",\n isRendererOnly: true,\n }, false)\n } else {\n tty.clear()\n }\n let oldTTY = srv.getActiveInstance()\n srv.setActiveInstance(tty)\n // Show the panel and focus it to prevent the user from editing the Dockerfile.\n srv.showPanel(true)\n\n startReloadUI()\n\n const ws = new WebSocket(\"ws://\" + location.host + \"/sail/api/v1/reload\")\n ws.onmessage = (ev) => {\n const msg = JSON.parse(ev.data)\n const out = atob(msg.v).replace(/\\n/g, \"\\n\\r\")\n tty.write(out)\n }\n ws.onclose = (ev) => {\n if (ev.code === 1000) {\n srv.setActiveInstance(oldTTY)\n } else {\n alert(\"reload failed; please see logs in sail terminal\")\n }\n stopReloadUI()\n }\n })\n})\n"
4+
const sailJS = "function startReloadUI() {\n const div = document.createElement(\"div\")\n div.className = \"msgbox-overlay\"\n div.style.opacity = 1\n div.style.textAlign = \"center\"\n div.innerHTML = `<div class=\"msgbox\">\n<div class=\"msg\">Reloading container</div>\n</div>`\n document.querySelector(\".monaco-workbench\").appendChild(div)\n}\n\nfunction removeElementsByClass(className) {\n let elements = document.getElementsByClassName(className);\n for (let e of elements) {\n e.parentNode.removeChild(e)\n }\n}\n\nfunction stopReloadUI() {\n removeElementsByClass(\"msgbox-overlay\")\n}\n\nfunction rebuild() {\n const tsrv = window.ide.workbench.terminalService\n\n if (tty == null) {\n tty = tsrv.createTerminal({\n name: \"sail\",\n isRendererOnly: true,\n }, false)\n } else {\n tty.clear()\n }\n let oldTTY = tsrv.getActiveInstance()\n tsrv.setActiveInstance(tty)\n // Show the panel and focus it to prevent the user from editing the Dockerfile.\n tsrv.showPanel(true)\n\n startReloadUI()\n\n const ws = new WebSocket(\"ws://\" + location.host + \"/sail/api/v1/reload\")\n ws.onmessage = (ev) => {\n const msg = JSON.parse(ev.data)\n const out = atob(msg.v).replace(/\\n/g, \"\\n\\r\")\n tty.write(out)\n }\n ws.onclose = (ev) => {\n if (ev.code === 1000) {\n tsrv.setActiveInstance(oldTTY)\n } else {\n alert(\"reload failed; please see logs in sail terminal\")\n }\n stopReloadUI()\n }\n}\n\nlet tty\nwindow.addEventListener(\"ide-ready\", () => {\n const statusBarService = window.ide.workbench.statusbarService\n statusBarService.addEntry({\n text: \"rebuild\",\n tooltip: \"press super+alt+r to rebuild\",\n command: \"rebuild-sail-container\"\n // showBeak: true <- what does this do?\n }, 0)\n\n const commandRegistry = window.ide.workbench.commandRegistry\n commandRegistry.registerCommand({\n id: \"rebuild-sail-container\",\n handler: (accessor, args) => {\n rebuild()\n },\n description: {\n description: \"Rebuild sail container\",\n args: []\n }\n })\n})\n"

0 commit comments

Comments
 (0)