mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
File dropped into terminal window adds path to command line (#559)
* Added file-uri-to-path dependency * Added new rpc event to send data to session * Modified sendSessionData to use activeUid if no uid is passed to function * "will-navigate" prevented on file drop, path added to session
This commit is contained in:
parent
77a103fbf1
commit
9d65cb74c0
4 changed files with 28 additions and 6 deletions
13
app/index.js
13
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;
|
||||
|
|
|
|||
|
|
@ -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 });
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue