Skip to content

Commit

Permalink
Add self-reminder to delete awkward IPC hackery
Browse files Browse the repository at this point in the history
  • Loading branch information
Alhadis committed Feb 10, 2018
1 parent d2e82ec commit e4abb09
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions lib/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
Expand All @@ -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", () => {
Expand Down

0 comments on commit e4abb09

Please sign in to comment.