diff --git a/app/index.js b/app/index.js index e0879f42..e4dda1f4 100644 --- a/app/index.js +++ b/app/index.js @@ -3,6 +3,8 @@ const createRPC = require('./rpc'); const createMenu = require('./menu'); const uuid = require('uuid'); const { resolve } = require('path'); +const { parse: parseUrl } = require('url'); +const fileUriToPath = require('file-uri-to-path'); const isDev = require('electron-is-dev'); const AutoUpdater = require('./auto-updater'); const toHex = require('convert-css-color-name-to-hex'); @@ -246,6 +248,17 @@ app.on('ready', () => { } }); + // If file is dropped onto the terminal window, navigate event is prevented + // and his path is added to active session. + win.webContents.on('will-navigate', (event, url) => { + var protocol = typeof url === 'string' && parseUrl(url).protocol; + if (protocol === 'file:') { + event.preventDefault(); + let path = fileUriToPath(url).replace(/ /g, '\\ '); + rpc.emit('session data send', { data: path }); + } + }); + // expose internals to extension authors win.rpc = rpc; win.sessions = sessions; diff --git a/lib/actions/sessions.js b/lib/actions/sessions.js index 7e70bafc..0e368358 100644 --- a/lib/actions/sessions.js +++ b/lib/actions/sessions.js @@ -172,12 +172,16 @@ export function resizeSession (uid, cols, rows) { } export function sendSessionData (uid, data) { - return { - type: SESSION_USER_DATA, - data, - effect () { - rpc.emit('data', { uid, data }); - } + return function (dispatch, getState) { + dispatch({ + type: SESSION_USER_DATA, + data, + effect () { + // If no uid is passed, data is sended to the active session. + const targetUid = uid || getState().sessions.activeUid; + rpc.emit('data', { uid: targetUid, data }); + } + }); }; } diff --git a/lib/index.js b/lib/index.js index f4aa38f3..caa9a6ee 100644 --- a/lib/index.js +++ b/lib/index.js @@ -56,6 +56,10 @@ rpc.on('session data', ({ uid, data }) => { store_.dispatch(sessionActions.addSessionData(uid, data)); }); +rpc.on('session data send', ({ uid, data }) => { + store_.dispatch(sessionActions.sendSessionData(uid, data)); +}); + rpc.on('session title', ({ uid, title }) => { store_.dispatch(sessionActions.setSessionProcessTitle(uid, title)); }); diff --git a/package.json b/package.json index 47ba4bbb..0687e0cc 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "aphrodite-simple": "0.4.1", "color": "0.11.3", "electron-mocha": "^3.0.0", + "file-uri-to-path": "0.0.2", "hterm-umdjs": "1.1.3", "json-loader": "0.5.4", "mocha": "^3.0.0",