Perf: Remove all *Sync methods for Linux startup

This commit is contained in:
Feross Aboukhadijeh
2016-03-25 21:47:49 -07:00
parent 01e27b2691
commit 59a1bc03f2

View File

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