It wasn't clear what was causing this error, and I couldn't reproduce
it.
This PR attempts to resolve the issue by just guarding against the
exception.
This PR fixes one of our number 2 top error (142 error reports today
alone):
Processes: webtorrent window, platforms: darwin linux win32, versions:
pre-0.12 0.14.0 0.17.0 0.17.1
TypeError: Cannot read property 'files' of null
at getAudioMetadata (.../build/renderer/webtorrent.js:328:21)
at EventEmitter.<anonymous> (.../build/renderer/webtorrent.js:84:74)
at emitThree (events.js:116:13)
at EventEmitter.emit (events.js:194:7)
This error is reproducible if you start webtorrent for the first time
and click the WIRED CD torrent. This causes the webtorrent process to
get a 'wt-get-audio-metadata' before 'wt-start-torrenting'.
You can reproduce it 100% of the time if you force the race condition
to show itself by slowing down the sending of the 'wt-start-torrenting'
event.
(This same error was showing for an unrelated reason in the past: #891)
- Fix bug where approxNumTorrents and other stats were not refreshed
when getting sent on 12 hour interval
- Lazy require modules
- Move setInterval into renderer/main.js
- Remove low-level https usage, use simple-get
By deferring more code in the renderer and loading state earlier, we
improve startup time by another 90ms!
Before: 507 unique requires (1270-1280ms)
After: 506 unique requires (1180-1190ms)
In Electron apps, the cost of large modules is very real.
fs-extra is very convenient, but removing it caused 50 fewer unique
files to be required(), resultin in 60ms faster startup!
Before: 557 unique requires (1330-1340ms)
After: 507 unique requires (1270-1280ms)
If the user accidentally pastes something that's not a torrent id, then
they get one "Invalid torrent Id" error for each line of the text.
Sure, this removes a "feature", but it's a pretty surprising one. When
I added it, I was being too clever, IMO.
The trim code can be removed, because that's handled in
controllers.torrentList.addTorrent().
Before this change, using the "Open Torrent Address" dialog to paste a
magnet link would fail with leading or trailing spaces.
Pasting on the torrent list page has always trimmed. So this PR just
makes it consistent.
Before, the gradient transparent black overlay made text hard to read in some cases. Torrents without a poster image showed up in blue-gray and didn't look good.
Every require() that we do before the users sees UI reduces startup
time.
I used the following code (added to index.js) to log every require()
call in the main process:
```js
var Module = require('module')
var required = {}
Module.prototype.require = function (orig) {
return function (id) {
if (!required[id]) {
required[id] = true
console.log(`${id} (from ${this.filename})`)
}
return orig.apply(this, arguments)
}
}(Module.prototype.require)
```
From this I was able to learn that lots of modules were being required
that aren't actually used until later.
I also sent this related PR to eliminate another few require()s:
https://github.com/LinusU/node-application-config/pull/4
This increases startup time by 50ms.
We'll probably realize much bigger gains by following this same
procedure for the renderer process.