-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingleTorrent.js
More file actions
113 lines (96 loc) · 2.28 KB
/
singleTorrent.js
File metadata and controls
113 lines (96 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
'use strict';
var numeral = require('numeral');
var moment = require('moment');
var Torrent = function(torrent, downloadPath) {
var rowHeight = 15;
var leftpadding = 5;
this.torrent = torrent;
var torrentTitle = new TextInput({
left: leftpadding,
top: 5,
width: '100%',
readonly: true
});
var progressBar = new ProgressBar({
left: leftpadding,
top: rowHeight + 5,
right: 60
});
var percent = new TextInput({
right: 5,
top: rowHeight + 5,
readonly: true,
width: 50,
alignment: 'right'
});
var downSpeed = new TextInput({
left: leftpadding,
top: rowHeight + 25,
width: 100,
readonly: true
});
var upSpeed = new TextInput({
left: 101,
top: rowHeight + 25,
width: 100,
readonly: true
});
var timeReamaingLabel = new TextInput({
top: 5,
right: 100,
width: 200,
readonly: true,
alignment: 'right',
value: 'Time Remaining:'
});
var timeRemainingValue = new TextInput({
top: 5,
right: 5,
width: 95,
readonly: true,
alignment: 'center'
});
var showTorrent = new Button({
right: 5,
bottom: 5,
title: 'Show'
});
showTorrent.addEventListener('click', function() {
System.openFile(downloadPath);
});
this.torrentView = new Container();
this.torrentView.appendChild(
[
torrentTitle,
progressBar,
downSpeed,
upSpeed,
percent,
timeReamaingLabel,
timeRemainingValue,
showTorrent
]
);
progressBar.value = torrent.progress;
downSpeed.value = '▼ ' + numeral(torrent.downloadSpeed()).format('0.0a');
upSpeed.value = '▲ ' + numeral(torrent.uploadSpeed()).format('0.0a');
percent.value = numeral(torrent.progress).format('0.00%');
torrentTitle.value = torrent.name;
timeRemainingValue.value = '500 days';
this.update = function(torrent) {
progressBar.value = torrent.progress;
if (torrent.progress === 1) {
downSpeed.value = '▼ ' + numeral(0).format('0.0a');
timeRemainingValue.value = 'Completed';
} else {
downSpeed.value = '▼ ' + numeral(torrent.downloadSpeed()).format('0.0a');
timeRemainingValue.value = moment.duration(torrent.timeRemaining).humanize();
}
upSpeed.value = '▲ ' + numeral(torrent.uploadSpeed()).format('0.0a');
percent.value = numeral(torrent.progress).format('0.00%');
};
this.remove = function() {
this.torrent.destroy();
};
};
module.exports = Torrent;