Skip to content

Commit b5dda1f

Browse files
committed
bump to 0.5.0
1 parent 3e66c7f commit b5dda1f

File tree

11 files changed

+133
-65
lines changed

11 files changed

+133
-65
lines changed

app/app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>electron Torrent</title>
5+
<title>Electron Torrent</title>
66
<link rel="stylesheet" href="../dist/main.css" />
77
</head>
88
<body>

app/components/QueuePanel.jsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ export default class QueuePanel extends React.Component {
9393

9494
addMagnetUrl() {
9595
if (this.state.magnetUrl.match(/magnet:\?xt=urn:[a-z0-9]+:[a-z0-9]{32}/i) != null) {
96-
console.log(this.state.magnetUrl);
9796
Ipc.send('add-client-from-magnet', this.state.magnetUrl);
9897
this.closeMagnetModal();
9998
} else {
@@ -214,7 +213,7 @@ export default class QueuePanel extends React.Component {
214213
let selectRowProp = {
215214
mode: "checkbox",
216215
clickToSelect: true,
217-
bgColor: "rgb(238, 193, 213)",
216+
bgColor: "#E0FFFF",
218217
onSelect: this.onCliensSelect.bind(this),
219218
onSelectAll: this.onSelectAllClient.bind(this)
220219
};

app/components/Sidebar.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ export default class Sidebar extends React.Component {
77
return (
88
<div className="col-sm-3 app-full-height">
99
<div className="sidebar app-full-height">
10-
<legend>electron Torrents</legend>
10+
<div className="brand">
11+
<img src="../icon/res/mipmap-mdpi/ic_launcher.png" />
12+
</div>
1113
<div className="list-group">
1214
<Link to="queue_all" className="list-group-item">All</Link>
1315
<Link to="queue_download" className="list-group-item">Downloading</Link>

app/containers/PageAboutContainer.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import React from 'react'
22
import { Link } from 'react-router'
33

4+
import sh from 'shell'
5+
46
export default class PageAboutContainer extends React.Component {
7+
openUrl(url) {
8+
sh.openExternal(url)
9+
}
510

611
render() {
712
return (
813
<div className="col-sm-9 page">
914
<div className="panel panel-default">
1015
<div className="panel-heading">
11-
<h3 className="panel-title">About electron Torrent</h3>
16+
<h3 className="panel-title">About</h3>
1217
</div>
1318
<div className="panel-body">
14-
19+
<div className="brand">
20+
<img src="../icon/res/mipmap-hdpi/ic_launcher.png" />
21+
</div>
22+
<p>Electron-Torrent is a pure javascript BitTorrent client based on Electron, React, torrent-stream.</p>
23+
<hr />
24+
<p>MIT © LeeChSien <button className="btn btn-default btn-sm" onClick={this.openUrl.bind(this, 'https://github.com/LeeChSien/electron-torrent')}>Github Repo</button></p>
1525
</div>
1626
</div>
1727
</div>

app/hot-dev-app.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>electron Torrent</title>
5+
<title>Electron Torrent</title>
66
</head>
77
<body>
88
<div id="react-root"></div>

app/styles/app.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ td {
5656
margin: 0;
5757
}
5858
}
59+
60+
.brand {
61+
margin-bottom: 10px;
62+
}

background/lib/local-storage.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ var LocalStorage = function() {
1515
}
1616

1717
function saveClients(clients) {
18-
Jsonfile.writeFileSync(CLIENTS_JSON_FILE_PATH, clients);
18+
var deferred = Defer();
19+
Jsonfile.writeFile(CLIENTS_JSON_FILE_PATH, clients, function(err) {
20+
deferred.resolve();
21+
});
22+
return deferred.promise;
1923
}
2024

2125
function getClients() {

background/lib/manager.js

Lines changed: 77 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
var fs = require("fs")
1+
var fs = require("fs")
22
var parseTorrent = require('parse-torrent')
3-
var Md5 = require('md5')
3+
var Md5 = require('md5')
4+
var Defer = require("node-promise").defer
45

56
var App = require('app')
67
var Ipc = require('ipc')
@@ -9,6 +10,8 @@ var Dialog = require('dialog')
910
var Client = require('./client')
1011
var LocalStorage = require('./local-storage')
1112

13+
var GlobalState = require('./global-state')
14+
1215
var clients = [];
1316

1417

@@ -52,10 +55,13 @@ var Manager = function() {
5255
}
5356

5457
function removeClient(controlHash) {
55-
getItemBy(clients, 'controlHash', controlHash).teardown();
56-
removeItemBy(clients, 'controlHash', controlHash);
58+
var _client = getItemBy(clients, 'controlHash', controlHash);
59+
if (_client) {
60+
_client.teardown();
61+
removeItemBy(clients, 'controlHash', controlHash);
5762

58-
LocalStorage.saveClients(getClients());
63+
LocalStorage.saveClients(getClients());
64+
}
5965
}
6066

6167
function restoreClients() {
@@ -85,31 +91,69 @@ var Manager = function() {
8591
}
8692

8793
function quit() {
88-
LocalStorage.saveClients(getClients());
94+
var deferred = Defer();
95+
LocalStorage.saveClients(getClients()).then(function() {
96+
deferred.resolve();
97+
});
98+
return deferred.promise;
8999
}
90100

91-
function bindIpc() {
92-
Ipc.on('add-client-from-magnet', function(event, magnet) {
93-
if (getItemBy(clients , 'magnet', magnet)) {
94-
Dialog.showMessageBox({
95-
type: 'error',
96-
buttons: ['ok'],
97-
title: 'Duplicate torrent',
98-
message: 'Duplicate torrent',
99-
detail: 'This torrent is already exist in the queue.'
100-
}, function() { });
101-
return;
101+
function openUrl(magnet) {
102+
if (getItemBy(clients , 'magnet', magnet)) {
103+
Dialog.showMessageBox({
104+
type: 'error',
105+
buttons: ['ok'],
106+
title: 'Duplicate torrent',
107+
message: 'Duplicate torrent',
108+
detail: 'This torrent is already exist in the queue.'
109+
}, function() { });
110+
return;
111+
}
112+
113+
Dialog.showOpenDialog({
114+
title: 'Select download path',
115+
properties: ['openDirectory']
116+
}, function (paths) {
117+
if (paths) {
118+
addClient(magnet, paths[0]);
119+
120+
var Window = GlobalState.getWindow();
121+
if (Window) {Window.webContents.send('client-list-refresh', getClients()); }
102122
}
123+
});
124+
}
103125

104-
Dialog.showOpenDialog({
105-
title: 'Select download path',
106-
properties: ['openDirectory']
107-
}, function (paths) {
108-
if (paths) {
109-
addClient(magnet, paths[0]);
110-
event.sender.send('client-list-refresh', getClients());
111-
}
112-
});
126+
function openFile(file) {
127+
var result = parseTorrent(fs.readFileSync(file)),
128+
magnet = parseTorrent.toMagnetURI(result);
129+
130+
if (getItemBy(clients , 'magnet', magnet)) {
131+
Dialog.showMessageBox({
132+
type: 'error',
133+
buttons: ['ok'],
134+
title: 'Duplicate torrent',
135+
message: 'Duplicate torrent',
136+
detail: 'This torrent is already exist in the queue.'
137+
}, function() { });
138+
return;
139+
}
140+
141+
Dialog.showOpenDialog({
142+
title: 'Select download path',
143+
properties: ['openDirectory']
144+
}, function (paths) {
145+
if (paths) {
146+
addClient(magnet, paths[0]);
147+
148+
var Window = GlobalState.getWindow();
149+
if (Window) {Window.webContents.send('client-list-refresh', getClients()); }
150+
}
151+
});
152+
}
153+
154+
function bindIpc() {
155+
Ipc.on('add-client-from-magnet', function(event, magnet) {
156+
openUrl(magnet);
113157
});
114158

115159
Ipc.on('add-client-from-torrent', function(event) {
@@ -121,29 +165,7 @@ var Manager = function() {
121165
]
122166
}, function (torrentPaths) {
123167
if (torrentPaths) {
124-
var result = parseTorrent(fs.readFileSync(torrentPaths[0])),
125-
magnet = parseTorrent.toMagnetURI(result);
126-
127-
if (getItemBy(clients , 'magnet', magnet)) {
128-
Dialog.showMessageBox({
129-
type: 'error',
130-
buttons: ['ok'],
131-
title: 'Duplicate torrent',
132-
message: 'Duplicate torrent',
133-
detail: 'This torrent is already exist in the queue.'
134-
}, function() { });
135-
return;
136-
}
137-
138-
Dialog.showOpenDialog({
139-
title: 'Select download path',
140-
properties: ['openDirectory']
141-
}, function (paths) {
142-
if (paths) {
143-
addClient(magnet, paths[0]);
144-
event.sender.send('client-list-refresh', getClients());
145-
}
146-
});
168+
openFile(torrentPaths[0]);
147169
}
148170
});
149171
});
@@ -159,20 +181,21 @@ var Manager = function() {
159181
Ipc.on('client-stop', function(event, controlHashes) {
160182
controlHashes.forEach(function(controlHash) {
161183
var c = getItemBy(clients , 'controlHash', controlHash)
162-
if (c.can('stop')) { c.stop(); }
184+
if (c && c.can('stop')) { c.stop(); }
163185
});
164186
});
165187

166188
Ipc.on('client-resume', function(event, controlHashes) {
167189
controlHashes.forEach(function(controlHash) {
168190
var c = getItemBy(clients , 'controlHash', controlHash)
169-
if (c.can('resume')) { c.resume(); }
191+
if (c && c.can('resume')) { c.resume(); }
170192
});
171193
});
172194

173195
Ipc.on('client-open-path', function(event, controlHashes) {
174196
controlHashes.forEach(function(controlHash) {
175-
getItemBy(clients , 'controlHash', controlHash).openPath();
197+
var c = getItemBy(clients , 'controlHash', controlHash)
198+
if (c) { c.openPath(); }
176199
});
177200
});
178201

@@ -184,6 +207,8 @@ var Manager = function() {
184207
return {
185208
bindIpc: bindIpc,
186209
restore: restore,
210+
openFile: openFile,
211+
openUrl: openUrl,
187212
quit: quit
188213
};
189214
}

background/main.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,30 @@ require('crash-reporter').start()
1212
var mainWindow = null
1313

1414
app.on('window-all-closed', function() {
15-
TorrentManager.quit();
16-
app.quit()
15+
TorrentManager.quit().then(function() {
16+
app.quit();
17+
});
1718
})
1819

20+
app.on('open-url', function(event, url) {
21+
if (GlobalState.getWindow()) {
22+
TorrentManager.openUrl(url);
23+
} else {
24+
app.on('preopen-url', function() {
25+
TorrentManager.openUrl(url);
26+
});
27+
}
28+
})
29+
30+
app.on('open-file', function(event, path) {
31+
if (GlobalState.getWindow()) {
32+
TorrentManager.openFile(path);
33+
} else {
34+
app.on('preopen-url', function() {
35+
TorrentManager.openFile(path);
36+
});
37+
}
38+
})
1939

2040
app.on('ready', function() {
2141
mainWindow = new BrowserWindow({ width: 1024, height: 600, resizable: false });
@@ -24,6 +44,9 @@ app.on('ready', function() {
2444
TorrentManager.bindIpc();
2545
TorrentManager.restore();
2646

47+
app.emit('preopen-url');
48+
app.emit('preopen-file');
49+
2750
if (process.env.HOT) {
2851
mainWindow.loadUrl('file://' + __dirname + '/../app/hot-dev-app.html')
2952
} else {

package.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ var del = require('del')
77
var latest = require('github-latest-release')
88
var argv = require('minimist')(process.argv.slice(2))
99
var devDeps = Object.keys(require('./package.json').devDependencies)
10-
10+
var packageJson = require('./package.json')
1111

1212
var appName = argv.name || argv.n || 'ElectronReact'
1313
var shouldUseAsar = argv.asar || argv.a || false
1414
var shouldBuildAll = argv.all || false
1515

1616

1717
var DEFAULT_OPTS = {
18+
'app-version': packageJson.version,
1819
dir: './',
1920
name: appName,
2021
asar: shouldUseAsar,

0 commit comments

Comments
 (0)