Skip to content

Commit

Permalink
Replace nobin-debian-installer
Browse files Browse the repository at this point in the history
  • Loading branch information
hicom150 committed Sep 9, 2019
1 parent 647eaf5 commit aff402f
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 167 deletions.
53 changes: 24 additions & 29 deletions bin/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -501,35 +501,30 @@ function buildLinux (cb) {
// Create .deb file for Debian-based platforms
console.log('Linux: Creating deb...')

const deb = require('nobin-debian-installer')()
const destPath = path.join('/opt', pkg.name)

deb.pack({
package: pkg,
info: {
arch: 'amd64',
targetDir: DIST_PATH,
depends: 'gconf2, libgtk2.0-0, libnss3, libxss1',
scripts: {
postinst: path.join(config.STATIC_PATH, 'linux', 'postinst'),
prerm: path.join(config.STATIC_PATH, 'linux', 'prerm')
}
}
}, [{
src: ['./**'],
dest: destPath,
expand: true,
cwd: filesPath
}, {
src: ['./**'],
dest: path.join('/usr', 'share'),
expand: true,
cwd: path.join(config.STATIC_PATH, 'linux', 'share')
}], function (err) {
if (err) return cb(err)
console.log('Linux: Created deb.')
cb(null)
})
const installer = require('electron-installer-debian')

const options = {
src: filesPath + '/',
dest: DIST_PATH,
arch: 'amd64',
bin: 'WebTorrent',
icon: {
'48x48': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/48x48/apps/webtorrent-desktop.png'),
'256x256': path.join(config.STATIC_PATH, 'linux/share/icons/hicolor/256x256/apps/webtorrent-desktop.png')
},
categories: ['Network', 'FileTransfer', 'P2P'],
mimeType: ['application/x-bittorrent', 'x-scheme-handler/magnet', 'x-scheme-handler/stream-magnet'],
desktopTemplate: path.join(config.STATIC_PATH, 'linux/webtorrent-desktop.ejs')
}

installer(options)
.then(function () {
console.log('Linux: Created deb.')
cb(null)
})
.catch(function (err) {
cb(err)
})
}

function packageZip (filesPath, cb) {
Expand Down
146 changes: 146 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"mkdirp": "^0.5.1",
"music-metadata": "^4.5.0",
"network-address": "^1.1.2",
"nobin-debian-installer": "github:webtorrent/nobin-debian-installer",
"parse-torrent": "^7.0.1",
"prettier-bytes": "^1.0.4",
"prop-types": "^15.7.2",
Expand All @@ -56,6 +55,7 @@
"cross-zip": "^2.1.6",
"depcheck": "^0.8.3",
"electron": "~6.0.7",
"electron-installer-debian": "^2.0.0",
"electron-osx-sign": "^0.4.12",
"electron-packager": "^14.0.5",
"electron-winstaller": "^4.0.0",
Expand Down
101 changes: 0 additions & 101 deletions src/main/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ function install () {
break
case 'win32': installWin32()
break
case 'linux': installLinux()
break
}
}

Expand All @@ -23,8 +21,6 @@ function uninstall () {
break
case 'win32': uninstallWin32()
break
case 'linux': uninstallLinux()
break
}
}

Expand Down Expand Up @@ -269,100 +265,3 @@ function uninstallWin32 () {
function commandToArgs (command) {
return command.map((arg) => `"${arg}"`).join(' ')
}

function installLinux () {
const fs = require('fs')
const os = require('os')
const path = require('path')

const config = require('../config')
const log = require('./log')

// Do not install in user dir if running on system
if (/^\/opt/.test(process.execPath)) return

installDesktopFile()
installIconFile()

function installDesktopFile () {
const templatePath = path.join(
config.STATIC_PATH, 'linux', 'webtorrent-desktop.desktop'
)
fs.readFile(templatePath, 'utf8', writeDesktopFile)
}

function writeDesktopFile (err, desktopFile) {
if (err) return log.error(err.message)

const appPath = config.IS_PRODUCTION
? path.dirname(process.execPath)
: config.ROOT_PATH

desktopFile = desktopFile
.replace(/\$APP_NAME/g, config.APP_NAME)
.replace(/\$APP_PATH/g, appPath)
.replace(/\$EXEC_PATH/g, EXEC_COMMAND.join(' '))
.replace(/\$TRY_EXEC_PATH/g, process.execPath)

const desktopFilePath = path.join(
os.homedir(),
'.local',
'share',
'applications',
'webtorrent-desktop.desktop'
)
fs.mkdirp(path.dirname(desktopFilePath))
fs.writeFile(desktopFilePath, desktopFile, err => {
if (err) return log.error(err.message)
})
}

function installIconFile () {
const iconStaticPath = path.join(config.STATIC_PATH, 'WebTorrent.png')
fs.readFile(iconStaticPath, writeIconFile)
}

function writeIconFile (err, iconFile) {
if (err) return log.error(err.message)

const mkdirp = require('mkdirp')

const iconFilePath = path.join(
os.homedir(),
'.local',
'share',
'icons',
'webtorrent-desktop.png'
)
mkdirp(path.dirname(iconFilePath), err => {
if (err) return log.error(err.message)
fs.writeFile(iconFilePath, iconFile, err => {
if (err) log.error(err.message)
})
})
}
}

function uninstallLinux () {
const os = require('os')
const path = require('path')
const rimraf = require('rimraf')

const desktopFilePath = path.join(
os.homedir(),
'.local',
'share',
'applications',
'webtorrent-desktop.desktop'
)
rimraf.sync(desktopFilePath)

const iconFilePath = path.join(
os.homedir(),
'.local',
'share',
'icons',
'webtorrent-desktop.png'
)
rimraf.sync(iconFilePath)
}
4 changes: 0 additions & 4 deletions static/linux/postinst

This file was deleted.

3 changes: 0 additions & 3 deletions static/linux/prerm

This file was deleted.

Loading

0 comments on commit aff402f

Please sign in to comment.