Fixes two portable app bugs, to make the app fully "silent", not just
"portable". This means that not only are all data files stored in the
"Portable Settings" folder, but the app should leave no trace on the
host system.
- Disable Electron's single instance mode so no lock file is created in
"%APPDATA%\Roaming\WebTorrent".
- Put Electron crash files, and other electron files into the "Portable
Settings\Temp" folder instead of "%APPDATA%\Temp".
Fixes: #971
This is a perfect example of putting too many statements into a
try-catch block. My bad. I was trying to keep the code simple, but it
bit us here.
This happens because we were using IS_PRODUCTION, but the order of the
consts at the top are:
const IS_PORTABLE = isPortable()
const IS_PRODUCTION = isProduction()
So we're inside of isPortable() and referring to IS_PRODUCTION before
it's defined. This should have thrown an exception, since const does
not allow use-before-define, but we're transforming to ES5 with Babel.
Also, standard could have caught this, but we can't enable the
use-before-define rule until this bug is fixed:
https://github.com/feross/standard/issues/636
Basically, a perfect storm.
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.
This gets rid of the light gray to dark gray background color change on
the main window at startup. Makes the window show slightly later, but
it's gray for less time. Doesn't affect overall startup time. Feels
less jank IMO.
From the Electron docs:
> While loading the page, the 'ready-to-show' event will be emitted
when renderer process has done drawing for the first time, showing
window after this event will have no visual flash.
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.
- Make State.save() always throttle calls -- since that's the common
case.
- Immediate saves are now the exception, with State.saveImmediate().
- The function is called State.save(), so the dispatch event should be
'stateSave'.