feat(download): torrent downloads manager

This commit is contained in:
Alexey Kasyanchuk
2018-03-06 11:17:24 +03:00
parent c40799816b
commit 1e86ba84c1
8 changed files with 119 additions and 6 deletions

View File

@ -15,6 +15,7 @@ import { devMenuTemplate } from "./menu/dev_menu_template";
import { editMenuTemplate } from "./menu/edit_menu_template";
import { settingsMenuTemplate } from "./menu/config_menu_template";
import { aboutMenuTemplate } from "./menu/about_menu_template";
import { manageMenuTemplate } from "./menu/manage_menu_template";
// Special module holding environment variables which you declared
// in config/env_xxx.json file.
@ -28,7 +29,7 @@ const iconv = require('iconv-lite');
require('electron-context-menu')({})
const setApplicationMenu = () => {
const menus = [editMenuTemplate, settingsMenuTemplate, aboutMenuTemplate];
const menus = [editMenuTemplate, manageMenuTemplate, settingsMenuTemplate, aboutMenuTemplate];
if (env.name !== "production") {
menus.push(devMenuTemplate);
}

View File

@ -0,0 +1,23 @@
import { app, BrowserWindow, shell } from "electron";
import path from "path";
import url from "url";
export const manageMenuTemplate = {
label: "Manage",
submenu: [
{
label: "Downloads",
accelerator: "CmdOrCtrl+d",
click: () => {
BrowserWindow.getFocusedWindow().webContents.send('url', '/downloads')
},
},
{
label: "Search",
accelerator: "CmdOrCtrl+n",
click: () => {
BrowserWindow.getFocusedWindow().webContents.send('url', '/')
},
}
]
};

View File

@ -690,8 +690,9 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
callback(true)
});
recive('download', (magnet) =>
recive('download', (torrentObject) =>
{
const magnet = `magnet:?xt=urn:btih:${torrentObject.hash}`
console.log('download', magnet)
if(torrentClient.get(magnet)) {
console.log('aready added')
@ -700,6 +701,7 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
torrentClient.add(magnet, {path: config.client.downloadPath}, (torrent) =>{
torrentClientHashMap[torrent.infoHash] = magnet
torrent.torrentObject = torrentObject
console.log('start downloading', torrent.infoHash)
send('downloading', torrent.infoHash)
@ -716,7 +718,7 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
now = Date.now()
send('downloadProgress', torrent.infoHash, {
bytes,
received: bytes,
downloaded: torrent.downloaded,
speed: torrent.downloadSpeed,
progress: torrent.progress
@ -751,6 +753,17 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
})
})
recive('downloads', (callback) =>
{
callback(torrentClient.torrents.map(torrent => ({
torrentObject: torrent.torrentObject,
received: torrent.received,
downloaded: torrent.downloaded,
progress: torrent.progress,
speed: torrent.downloadSpeed
})))
})
let socketIPV4 = () => {
let ip = socket.request.connection.remoteAddress;
if (ipaddr.IPv4.isValid(ip)) {