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,70 +2,85 @@ 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()
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') { if (process.platform === 'linux') {
installDesktopFile() initLinux()
installDesktopIcon()
} }
} }
function installDesktopFile () { function initWindows () {
var config = require('../config') var iconPath = path.join(process.resourcesPath, 'app.asar.unpacked', 'static', 'WebTorrentFile.ico')
var fs = require('fs') registerProtocolHandlerWin32('magnet', 'URL:BitTorrent Magnet URL', iconPath, process.execPath)
var path = require('path') registerFileHandlerWin32('.torrent', 'io.webtorrent.torrent', 'BitTorrent Document', iconPath, process.execPath)
var os = require('os')
var templatePath = path.join(config.STATIC_PATH, 'webtorrent.desktop')
var desktopFile = fs.readFileSync(templatePath, 'utf8')
var appPath = config.IS_PRODUCTION ? path.dirname(process.execPath) : config.ROOT_PATH
var execPath = process.execPath + (config.IS_PRODUCTION ? '' : ' \.')
var tryExecPath = process.execPath
desktopFile = desktopFile.replace(/\$APP_NAME/g, config.APP_NAME)
desktopFile = desktopFile.replace(/\$APP_PATH/g, appPath)
desktopFile = desktopFile.replace(/\$EXEC_PATH/g, execPath)
desktopFile = desktopFile.replace(/\$TRY_EXEC_PATH/g, tryExecPath)
var desktopFilePath = path.join(
os.homedir(),
'.local',
'share',
'applications',
'webtorrent.desktop'
)
mkdirp(path.dirname(desktopFilePath))
fs.writeFileSync(desktopFilePath, desktopFile)
} }
function installDesktopIcon () { 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')
var iconStaticPath = path.join(config.STATIC_PATH, 'WebTorrent.png') installDesktopFile()
var iconFile = fs.readFileSync(iconStaticPath) installIconFile()
var iconFilePath = path.join( function installDesktopFile () {
os.homedir(), var templatePath = path.join(config.STATIC_PATH, 'webtorrent.desktop')
'.local', fs.readFile(templatePath, 'utf8', writeDesktopFile)
'share', }
'icons',
'webtorrent.png' function writeDesktopFile (err, desktopFile) {
) if (err) return console.error(err.message)
mkdirp(path.dirname(iconFilePath))
fs.writeFileSync(iconFilePath, iconFile) var appPath = config.IS_PRODUCTION ? path.dirname(process.execPath) : config.ROOT_PATH
var execPath = process.execPath + (config.IS_PRODUCTION ? '' : ' \.')
var tryExecPath = process.execPath
desktopFile = desktopFile.replace(/\$APP_NAME/g, config.APP_NAME)
desktopFile = desktopFile.replace(/\$APP_PATH/g, appPath)
desktopFile = desktopFile.replace(/\$EXEC_PATH/g, execPath)
desktopFile = desktopFile.replace(/\$TRY_EXEC_PATH/g, tryExecPath)
var desktopFilePath = path.join(
os.homedir(),
'.local',
'share',
'applications',
'webtorrent.desktop'
)
mkdirp(path.dirname(desktopFilePath))
fs.writeFile(desktopFilePath, desktopFile, function (err) {
if (err) return console.error(err.message)
})
}
function installIconFile () {
var iconStaticPath = path.join(config.STATIC_PATH, 'WebTorrent.png')
fs.readFile(iconStaticPath, writeIconFile)
}
function writeIconFile (err, iconFile) {
if (err) return console.error(err.message)
var iconFilePath = path.join(
os.homedir(),
'.local',
'share',
'icons',
'webtorrent.png'
)
mkdirp(path.dirname(iconFilePath))
fs.writeFile(iconFilePath, iconFile, function (err) {
if (err) return console.error(err.message)
})
}
} }
/** /**