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
Next Next commit
Use actions registry
  • Loading branch information
nhooyr committed May 20, 2019
commit 45af165709996e846b02258f58d6f7803be2cd6b
26 changes: 12 additions & 14 deletions sail.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,21 @@
}

window.addEventListener("ide-ready", () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 sail container", {
primary: ((1 << 11) >>> 0) | 48 // That's cmd + R. See vscode source for the magic numbers.
}), "sail: Rebuild", "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+alt+r to rebuild",
command: "rebuild-sail-container"
tooltip: "press super+r to rebuild",
Copy link
Member

Choose a reason for hiding this comment

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

ctrl or cmd now, but since the user can customize keybindings it might be better not to display this text at all. There is probably a way to get the current keybinding but I'm not sure off the top of my head how you'd access that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point

command: "sail.rebuild"
}, 0)

const commandRegistry = window.ide.workbench.commandRegistry
commandRegistry.registerCommand({
id: "rebuild-sail-container",
handler: (accessor, args) => {
rebuild()
},
description: {
description: "Rebuild sail container",
args: []
}
})
})
}())
Copy link
Member

Choose a reason for hiding this comment

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

Not really any of my business, but I am curious about the loss of the newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

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 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 }, 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}())"
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}())"