From 092ba2ba0f19747de15760894be9e9164b856544 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Wed, 2 Mar 2016 16:13:04 -0800 Subject: [PATCH] don't override paste command in dev tools --- index.js | 60 ++++++++++++++++++++++++++++----------------------- main/index.js | 6 ++++++ 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/index.js b/index.js index 9131d9f4..0911a165 100644 --- a/index.js +++ b/index.js @@ -80,8 +80,38 @@ function createMainWindow () { return win } +function addTorrentFromPaste () { + var torrentIds = electron.clipboard.readText().split('\n') + console.log(torrentIds) + torrentIds.forEach(function (torrentId) { + torrentId = torrentId.trim() + if (torrentId.length === 0) return + mainWindow.send('action', 'addTorrent', torrentId) + }) +} + +function toggleDevTools (win) { + win = win || electron.BrowserWindow.getFocusedWindow() + + if (win) { + win.toggleDevTools() + } +} + +function reloadWindow (win) { + win = win || electron.BrowserWindow.getFocusedWindow() + + if (win) { + startTime = Date.now() + win.webContents.reloadIgnoringCache() + } +} + electron.ipcMain.on('action', function (event, action, ...args) { debug('action %s', action) + if (action === 'addTorrentFromPaste') { + addTorrentFromPaste() + } }) var template = [ @@ -147,14 +177,7 @@ var template = [ { label: 'Paste', accelerator: 'CmdOrCtrl+V', - click: function () { - var torrentIds = electron.clipboard.readText().split('\n') - torrentIds.forEach(function (torrentId) { - torrentId = torrentId.trim() - if (torrentId.length === 0) return - mainWindow.send('action', 'addTorrent', torrentId) - }) - } + role: 'paste' }, { label: 'Select All', @@ -183,7 +206,7 @@ var template = [ label: 'Reload', accelerator: 'CmdOrCtrl+R', click: function (item, focusedWindow) { - reload(focusedWindow) + reloadWindow(focusedWindow) } }, { @@ -193,7 +216,7 @@ var template = [ else return 'Ctrl+Shift+I' })(), click: function (item, focusedWindow) { - devTools(focusedWindow) + toggleDevTools(focusedWindow) } } ] @@ -296,23 +319,6 @@ if (process.platform === 'darwin') { ) } -function devTools (win) { - win = win || electron.BrowserWindow.getFocusedWindow() - - if (win) { - win.toggleDevTools() - } -} - -function reload (win) { - win = win || electron.BrowserWindow.getFocusedWindow() - - if (win) { - startTime = Date.now() - win.webContents.reloadIgnoringCache() - } -} - // var progress = 0 // setInterval(function () { // progress += 0.1 diff --git a/main/index.js b/main/index.js index 1cf772fb..7d553c6a 100644 --- a/main/index.js +++ b/main/index.js @@ -69,6 +69,12 @@ function init () { airplay.createBrowser().on('deviceOn', function (player) { state.airplay = player }).start() + + document.addEventListener('paste', function () { + electron.ipcRenderer.send('action', 'addTorrentFromPaste') + }) + + handler('addTorrent', 'magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d&dn=sintel.mp4') } init()