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.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Prevent keypresses while reload occurs
Also prevent rebuild while rebuild is in progress, just in case.
  • Loading branch information
nhooyr committed May 20, 2019
commit 10bf740fbb6d0d573859a33d20fc5fb47ff3ecdc
21 changes: 16 additions & 5 deletions sail.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
div.style.opacity = 1
div.style.textAlign = "center"
div.innerHTML = `<div class="msgbox">
<div class="msg">Reloading container</div>
<div class="msg">Rebuilding container</div>
</div>`
// Prevent keypresses.
document.body.onkeydown = ev => {
ev.stopPropagation()
}
document.querySelector(".monaco-workbench").appendChild(div)
}

Expand All @@ -22,7 +26,13 @@
}

let tty
let rebuilding
function rebuild() {
if (rebuilding) {
return
}
rebuilding = true

const tsrv = window.ide.workbench.terminalService

if (tty == null) {
Expand Down Expand Up @@ -53,6 +63,7 @@
alert("reload failed; please see logs in sail terminal")
}
stopReloadUI()
rebuilding = false
}
}

Expand All @@ -63,15 +74,15 @@
}
}

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

const statusBarService = window.ide.workbench.statusbarService
statusBarService.addEntry({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want to only show this when we detect a change to the Dockerfile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just leave it there.

text: "rebuild",
tooltip: "press super+r to rebuild",
tooltip: "Rebuild sail container",
command: "sail.rebuild"
}, 0)
})
}())
}())
2 changes: 1 addition & 1 deletion sail.js.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main

//go:generate go run sail.js_gen.go
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}())"
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"