feat(download): torrent downloads manager
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
23
src/background/menu/manage_menu_template.js
Normal file
23
src/background/menu/manage_menu_template.js
Normal 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', '/')
|
||||
},
|
||||
}
|
||||
]
|
||||
};
|
@ -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)) {
|
||||
|
Reference in New Issue
Block a user