From 467335470396896f0d09b4440ee3a770b66bf825 Mon Sep 17 00:00:00 2001 From: grunjol Date: Tue, 22 Mar 2016 19:53:47 -0300 Subject: [PATCH] fixes #116 Add Unity launcher icons --- main/handlers.js | 10 ++++++++-- main/index.js | 26 ++++++++++++++++++++------ main/ipc.js | 4 ++++ main/menu.js | 1 + renderer/index.js | 3 +++ static/webtorrent.desktop | 19 ++++++++++++++++++- 6 files changed, 54 insertions(+), 9 deletions(-) diff --git a/main/handlers.js b/main/handlers.js index 9413f84a..87643f72 100644 --- a/main/handlers.js +++ b/main/handlers.js @@ -27,8 +27,14 @@ function installDesktopFile () { var desktopFile = fs.readFileSync(templatePath, 'utf8') desktopFile = desktopFile.replace(/\$APP_NAME/g, config.APP_NAME) - desktopFile = desktopFile.replace(/\$APP_PATH/g, path.dirname(process.execPath)) - desktopFile = desktopFile.replace(/\$EXEC_PATH/g, process.execPath) + + var appPath = config.IS_PRODUCTION ? path.dirname(process.execPath) : config.ROOT_PATH + desktopFile = desktopFile.replace(/\$APP_PATH/g, appPath) + + var execPath = process.execPath + (config.IS_PRODUCTION ? '' : ' \.') + desktopFile = desktopFile.replace(/\$EXEC_PATH/g, execPath) + + desktopFile = desktopFile.replace(/\$TRY_EXEC_PATH/g, process.execPath) var desktopFilePath = path.join(os.homedir(), '.local', 'share', 'applications', 'webtorrent.desktop') fs.writeFileSync(desktopFilePath, desktopFile) diff --git a/main/index.js b/main/index.js index b75dba9b..80eea65d 100644 --- a/main/index.js +++ b/main/index.js @@ -57,9 +57,7 @@ function init () { app.on('ipcReady', function () { log('Command line args:', argv) - argv.forEach(function (torrentId) { - windows.main.send('dispatch', 'onOpen', torrentId) - }) + processArgv(argv) }) app.on('before-quit', function () { @@ -104,9 +102,7 @@ function onAppOpen (newArgv) { log('Second app instance opened, but was prevented:', newArgv) windows.focusMainWindow() - newArgv.forEach(function (torrentId) { - windows.main.send('dispatch', 'onOpen', torrentId) - }) + processArgv(newArgv) } else { argv.push(...newArgv) } @@ -116,6 +112,24 @@ function sliceArgv (argv) { return argv.slice(config.IS_PRODUCTION ? 1 : 2) } +function processArgv (argv) { + argv.forEach(function (argvi) { + switch (argvi) { + case '-n': + windows.main.send('dispatch', 'showCreateTorrent') + break + case '-o': + windows.main.send('dispatch', 'showOpenTorrentFile') + break + case '-u': + windows.main.send('showOpenTorrentAddress') + break + default: + windows.main.send('dispatch', 'onOpen', argvi) + } + }) +} + function setupCrashReporter () { // require('crash-reporter').start({ // productName: 'WebTorrent', diff --git a/main/ipc.js b/main/ipc.js index ffbdad46..9439d973 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -27,6 +27,10 @@ function init () { menu.showOpenTorrentFile() }) + ipcMain.on('showCreateTorrent', function (e) { + menu.showCreateTorrent() + }) + ipcMain.on('setBounds', function (e, bounds, maximize) { setBounds(bounds, maximize) }) diff --git a/main/menu.js b/main/menu.js index 2f9b960e..dc4eb038 100644 --- a/main/menu.js +++ b/main/menu.js @@ -4,6 +4,7 @@ module.exports = { onWindowHide: onWindowHide, onWindowShow: onWindowShow, showOpenTorrentFile: showOpenTorrentFile, + showCreateTorrent: showCreateTorrent, toggleFullScreen: toggleFullScreen } diff --git a/renderer/index.js b/renderer/index.js index d376dc1b..8c07717a 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -173,6 +173,9 @@ function dispatch (action, ...args) { if (action === 'addTorrent') { addTorrent(args[0] /* torrent */) } + if (action === 'showCreateTorrent') { + ipcRenderer.send('showCreateTorrent') + } if (action === 'showOpenTorrentFile') { ipcRenderer.send('showOpenTorrentFile') } diff --git a/static/webtorrent.desktop b/static/webtorrent.desktop index 41ffe369..ea956dea 100644 --- a/static/webtorrent.desktop +++ b/static/webtorrent.desktop @@ -10,7 +10,24 @@ Icon=webtorrent Terminal=false Path=$APP_PATH Exec=$EXEC_PATH %U -TryExec=$EXEC_PATH +TryExec=$TRY_EXEC_PATH StartupNotify=false Categories=Network;FileTransfer;P2P; MimeType=application/x-bittorrent;x-scheme-handler/magnet; + +Actions=CreateNewTorrent;OpenTorrentFile;OpenTorrentAddress; + +[Desktop Action CreateNewTorrent] +Name=Create New Torrent... +Exec=$EXEC_PATH -n +Path=$APP_PATH + +[Desktop Action OpenTorrentFile] +Name=Open Torrent File... +Exec=$EXEC_PATH -o +Path=$APP_PATH + +[Desktop Action OpenTorrentAddress] +Name=Open Torrent Address... +Exec=$EXEC_PATH -u +Path=$APP_PATH