Perf: Remove all *Sync methods for Linux startup

This commit is contained in:
Feross Aboukhadijeh
2016-03-25 21:47:49 -07:00
parent 7b627d2e60
commit 7c278fba01

View File

@@ -2,31 +2,42 @@ module.exports = {
init
}
var mkdirp = require('mkdirp')
var path = require('path')
var log = require('./log')
function init () {
if (process.platform === 'win32') {
var path = require('path')
initWindows()
}
if (process.platform === 'linux') {
initLinux()
}
}
function initWindows () {
var iconPath = path.join(process.resourcesPath, 'app.asar.unpacked', 'static', 'WebTorrentFile.ico')
registerProtocolHandlerWin32('magnet', 'URL:BitTorrent Magnet URL', iconPath, process.execPath)
registerFileHandlerWin32('.torrent', 'io.webtorrent.torrent', 'BitTorrent Document', iconPath, process.execPath)
}
if (process.platform === 'linux') {
installDesktopFile()
installDesktopIcon()
}
}
function installDesktopFile () {
function initLinux () {
var config = require('../config')
var fs = require('fs')
var path = require('path')
var mkdirp = require('mkdirp')
var os = require('os')
var path = require('path')
installDesktopFile()
installIconFile()
function installDesktopFile () {
var templatePath = path.join(config.STATIC_PATH, 'webtorrent.desktop')
var desktopFile = fs.readFileSync(templatePath, 'utf8')
fs.readFile(templatePath, 'utf8', writeDesktopFile)
}
function writeDesktopFile (err, desktopFile) {
if (err) return console.error(err.message)
var appPath = config.IS_PRODUCTION ? path.dirname(process.execPath) : config.ROOT_PATH
var execPath = process.execPath + (config.IS_PRODUCTION ? '' : ' \.')
@@ -45,17 +56,18 @@ function installDesktopFile () {
'webtorrent.desktop'
)
mkdirp(path.dirname(desktopFilePath))
fs.writeFileSync(desktopFilePath, desktopFile)
fs.writeFile(desktopFilePath, desktopFile, function (err) {
if (err) return console.error(err.message)
})
}
function installDesktopIcon () {
var config = require('../config')
var fs = require('fs')
var path = require('path')
var os = require('os')
function installIconFile () {
var iconStaticPath = path.join(config.STATIC_PATH, 'WebTorrent.png')
var iconFile = fs.readFileSync(iconStaticPath)
fs.readFile(iconStaticPath, writeIconFile)
}
function writeIconFile (err, iconFile) {
if (err) return console.error(err.message)
var iconFilePath = path.join(
os.homedir(),
@@ -65,7 +77,10 @@ function installDesktopIcon () {
'webtorrent.png'
)
mkdirp(path.dirname(iconFilePath))
fs.writeFileSync(iconFilePath, iconFile)
fs.writeFile(iconFilePath, iconFile, function (err) {
if (err) return console.error(err.message)
})
}
}
/**