Thanks to visit codestin.com
Credit goes to github.com

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

Commit 10bf740

Browse files
committed
Prevent keypresses while reload occurs
Also prevent rebuild while rebuild is in progress, just in case.
1 parent 45af165 commit 10bf740

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

sail.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
div.style.opacity = 1
66
div.style.textAlign = "center"
77
div.innerHTML = `<div class="msgbox">
8-
<div class="msg">Reloading container</div>
8+
<div class="msg">Rebuilding container</div>
99
</div>`
10+
// Prevent keypresses.
11+
document.body.onkeydown = ev => {
12+
ev.stopPropagation()
13+
}
1014
document.querySelector(".monaco-workbench").appendChild(div)
1115
}
1216

@@ -22,7 +26,13 @@
2226
}
2327

2428
let tty
29+
let rebuilding
2530
function rebuild() {
31+
if (rebuilding) {
32+
return
33+
}
34+
rebuilding = true
35+
2636
const tsrv = window.ide.workbench.terminalService
2737

2838
if (tty == null) {
@@ -53,6 +63,7 @@
5363
alert("reload failed; please see logs in sail terminal")
5464
}
5565
stopReloadUI()
66+
rebuilding = false
5667
}
5768
}
5869

@@ -63,15 +74,15 @@
6374
}
6475
}
6576

66-
window.ide.workbench.actionsRegistry.registerWorkbenchAction(new window.ide.workbench.syncActionDescriptor(rebuildAction, "sail.rebuild", "Rebuild sail container", {
77+
window.ide.workbench.actionsRegistry.registerWorkbenchAction(new window.ide.workbench.syncActionDescriptor(rebuildAction, "sail.rebuild", "Rebuild container", {
6778
primary: ((1 << 11) >>> 0) | 48 // That's cmd + R. See vscode source for the magic numbers.
68-
}), "sail: Rebuild", "sail");
79+
}), "sail: Rebuild container", "sail");
6980

7081
const statusBarService = window.ide.workbench.statusbarService
7182
statusBarService.addEntry({
7283
text: "rebuild",
73-
tooltip: "press super+r to rebuild",
84+
tooltip: "Rebuild sail container",
7485
command: "sail.rebuild"
7586
}, 0)
7687
})
77-
}())
88+
}())

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() {\n 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\n function removeElementsByClass(className) {\n let elements = document.getElementsByClassName(className);\n for (let e of elements) {\n e.parentNode.removeChild(e)\n }\n }\n\n function stopReloadUI() {\n removeElementsByClass(\"msgbox-overlay\")\n }\n\n let tty\n function 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\n window.addEventListener(\"ide-ready\", () => {\n class rebuildAction extends window.ide.workbench.action {\n run() {\n rebuild()\n }\n }\n\n window.ide.workbench.actionsRegistry.registerWorkbenchAction(new window.ide.workbench.syncActionDescriptor(rebuildAction, \"sail.rebuild\", \"Rebuild sail container\", {\n primary: ((1 << 11) >>> 0) | ((1 << 10) >>> 0) | 48 // That's cmd + shift + R. See vscode source.\n }), \"sail: Rebuild\", \"sail\");\n\n const statusBarService = window.ide.workbench.statusbarService\n statusBarService.addEntry({\n text: \"rebuild\",\n tooltip: \"press super+alt+r to rebuild\",\n command: \"sail.rebuild\"\n }, 0)\n })\n}())"
4+
const sailJS = "(function() {\n 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\">Rebuilding container</div>\n </div>`\n // Prevent keypresses.\n document.body.onkeydown = ev => {\n ev.stopPropagation()\n }\n document.querySelector(\".monaco-workbench\").appendChild(div)\n }\n\n function removeElementsByClass(className) {\n let elements = document.getElementsByClassName(className);\n for (let e of elements) {\n e.parentNode.removeChild(e)\n }\n }\n\n function stopReloadUI() {\n removeElementsByClass(\"msgbox-overlay\")\n }\n\n let tty\n let rebuilding\n function rebuild() {\n if (rebuilding) {\n return\n }\n rebuilding = true\n\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 rebuilding = false\n }\n }\n\n window.addEventListener(\"ide-ready\", () => {\n class rebuildAction extends window.ide.workbench.action {\n run() {\n rebuild()\n }\n }\n\n window.ide.workbench.actionsRegistry.registerWorkbenchAction(new window.ide.workbench.syncActionDescriptor(rebuildAction, \"sail.rebuild\", \"Rebuild container\", {\n primary: ((1 << 11) >>> 0) | 48 // That's cmd + R. See vscode source for the magic numbers.\n }), \"sail: Rebuild container\", \"sail\");\n\n const statusBarService = window.ide.workbench.statusbarService\n statusBarService.addEntry({\n text: \"rebuild\",\n tooltip: \"Rebuild sail container\",\n command: \"sail.rebuild\"\n }, 0)\n })\n}())\n"

0 commit comments

Comments
 (0)