This repository was archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Add rebuild button and command #123
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,52 @@ | ||
function startReloadUI() { | ||
const div = document.createElement("div") | ||
div.className = "msgbox-overlay" | ||
div.style.opacity = 1 | ||
div.style.textAlign = "center" | ||
div.innerHTML = `<div class="msgbox"> | ||
<div class="msg">Reloading container</div> | ||
</div>` | ||
document.querySelector(".monaco-workbench").appendChild(div) | ||
} | ||
|
||
function removeElementsByClass(className) { | ||
let elements = document.getElementsByClassName(className); | ||
for (let e of elements) { | ||
e.parentNode.removeChild(e) | ||
(function() { | ||
function startReloadUI() { | ||
const div = document.createElement("div") | ||
div.className = "msgbox-overlay" | ||
div.style.opacity = 1 | ||
div.style.textAlign = "center" | ||
div.innerHTML = `<div class="msgbox"> | ||
<div class="msg">Rebuilding container</div> | ||
</div>` | ||
// Prevent keypresses. | ||
document.body.onkeydown = ev => { | ||
ev.stopPropagation() | ||
} | ||
document.querySelector(".monaco-workbench").appendChild(div) | ||
} | ||
|
||
function removeElementsByClass(className) { | ||
let elements = document.getElementsByClassName(className); | ||
for (let e of elements) { | ||
e.parentNode.removeChild(e) | ||
} | ||
} | ||
} | ||
|
||
function stopReloadUI() { | ||
removeElementsByClass("msgbox-overlay") | ||
} | ||
function stopReloadUI() { | ||
removeElementsByClass("msgbox-overlay") | ||
} | ||
|
||
let tty | ||
window.addEventListener("ide-ready", () => { | ||
window.ide.workbench.onFileSaved((ev) => { | ||
if (!ev.endsWith(".sail/Dockerfile")) { | ||
let tty | ||
let rebuilding | ||
function rebuild() { | ||
if (rebuilding) { | ||
return | ||
} | ||
rebuilding = true | ||
|
||
const srv = window.ide.workbench.terminalService | ||
const tsrv = window.ide.workbench.terminalService | ||
|
||
if (tty == null) { | ||
tty = srv.createTerminal({ | ||
tty = tsrv.createTerminal({ | ||
name: "sail", | ||
isRendererOnly: true, | ||
}, false) | ||
} else { | ||
tty.clear() | ||
} | ||
let oldTTY = srv.getActiveInstance() | ||
srv.setActiveInstance(tty) | ||
let oldTTY = tsrv.getActiveInstance() | ||
tsrv.setActiveInstance(tty) | ||
// Show the panel and focus it to prevent the user from editing the Dockerfile. | ||
srv.showPanel(true) | ||
tsrv.showPanel(true) | ||
|
||
startReloadUI() | ||
|
||
|
@@ -52,11 +58,31 @@ window.addEventListener("ide-ready", () => { | |
} | ||
ws.onclose = (ev) => { | ||
if (ev.code === 1000) { | ||
srv.setActiveInstance(oldTTY) | ||
tsrv.setActiveInstance(oldTTY) | ||
} else { | ||
alert("reload failed; please see logs in sail terminal") | ||
} | ||
stopReloadUI() | ||
rebuilding = false | ||
} | ||
} | ||
|
||
window.addEventListener("ide-ready", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the changes are. |
||
class rebuildAction extends window.ide.workbench.action { | ||
run() { | ||
rebuild() | ||
} | ||
} | ||
|
||
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 container", "sail"); | ||
|
||
const statusBarService = window.ide.workbench.statusbarService | ||
statusBarService.addEntry({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can just leave it there. |
||
text: "rebuild", | ||
tooltip: "Rebuild sail container", | ||
command: "sail.rebuild" | ||
}, 0) | ||
}) | ||
}) | ||
}()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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" | ||
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" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why wrap this all in a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The global variables become scoped to the file. This is what Webpack and other module loaders due for the browser to isolate modules.