From e4abb094fe58071cee99c9265e03cfa2d21c569c Mon Sep 17 00:00:00 2001 From: Alhadis Date: Sun, 11 Feb 2018 00:14:43 +1100 Subject: [PATCH] Add self-reminder to delete awkward IPC hackery --- lib/ipc.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/ipc.js b/lib/ipc.js index 6a6df88..d6fd5d8 100644 --- a/lib/ipc.js +++ b/lib/ipc.js @@ -3,23 +3,27 @@ const {remote, ipcRenderer} = require("electron"); const EVENT_CLOSE_PROJECT = "atom-mocha:close-project"; const EVENT_JUMP_TO_FILE = "atom-mocha:jump-to-file"; -const VAR_CMD_MANAGER = 'AtomMochaCmdManager'; +const VAR_CMD_MANAGER = "AtomMochaCmdManager"; +/** + * TODO: Torch this file and use Atom's core URI handlers. + * See: atom/atom#15935, BinaryMuse/atom-mocha-test-runner#12 + */ class IPC{ - + init(projectPath){ global[ VAR_CMD_MANAGER ] = {}; this.projectPath = projectPath; this.injectHooks(); } - - + + jumpToFile(path, row, column){ ipcRenderer.send(EVENT_JUMP_TO_FILE, path, row, column); } - - + + /** * Install the `jumpToFile` command in project's window. * @@ -29,19 +33,19 @@ class IPC{ injectHooks(){ const path = this.projectPath.replace(/\\/g, "\\\\").replace(/"/g, '\\"'); const code = this.getInjectedCode(path); - + for(const item of remote.webContents.getAllWebContents()) if("window" === item.getType()) item.executeJavaScript(code); } - - + + getInjectedCode(path){ return `if(global.atom && null == global.${ VAR_CMD_MANAGER } && -1 !== global.atom.project.getPaths().indexOf("${ path }")){ const {remote, ipcRenderer} = require("electron"); const {Range} = require("atom"); - + const ${ VAR_CMD_MANAGER } = { handleJump(event, ...args){ ${ VAR_CMD_MANAGER }.jumpToFile(...args); @@ -56,7 +60,7 @@ class IPC{ }); } }; - + global.${ VAR_CMD_MANAGER } = ${ VAR_CMD_MANAGER }; remote.ipcMain.on("${ EVENT_JUMP_TO_FILE }", ${ VAR_CMD_MANAGER }.handleJump); window.addEventListener("beforeunload", () => {