Merge pull request #297 from feross/win

Uninstall handlers on Windows uninstall/npm run clean
This commit is contained in:
Feross Aboukhadijeh
2016-04-04 20:34:44 -07:00
5 changed files with 125 additions and 12 deletions

View File

@@ -5,13 +5,18 @@
* Useful for developers.
*/
var config = require('../config')
var os = require('os')
var path = require('path')
var pathExists = require('path-exists')
var rimraf = require('rimraf')
var config = require('../config')
var handlers = require('../main/handlers')
rimraf.sync(config.CONFIG_PATH)
var tmpPath = path.join(pathExists.sync('/tmp') ? '/tmp' : os.tmpDir(), 'webtorrent')
rimraf.sync(tmpPath)
// Uninstall .torrent file and magnet link handlers
handlers.uninstall()

View File

@@ -1,24 +1,37 @@
module.exports = {
init
install,
uninstall
}
var path = require('path')
var log = require('./log')
function init () {
function install () {
if (process.platform === 'darwin') {
initDarwin()
installDarwin()
}
if (process.platform === 'win32') {
initWin32()
installWin32()
}
if (process.platform === 'linux') {
initLinux()
installLinux()
}
}
function initDarwin () {
function uninstall () {
if (process.platform === 'darwin') {
uninstallDarwin()
}
if (process.platform === 'win32') {
uninstallWin32()
}
if (process.platform === 'linux') {
uninstallLinux()
}
}
function installDarwin () {
var electron = require('electron')
var app = electron.app
@@ -29,7 +42,9 @@ function initDarwin () {
// File handlers are registered in the Info.plist.
}
function initWin32 () {
function uninstallDarwin () {}
function installWin32 () {
var Registry = require('winreg')
var iconPath = path.join(process.resourcesPath, 'app.asar.unpacked', 'static', 'WebTorrentFile.ico')
@@ -163,7 +178,70 @@ function initWin32 () {
}
}
function initLinux () {
function uninstallWin32 () {
var Registry = require('winreg')
unregisterProtocolHandlerWin32('magnet', process.execPath)
unregisterFileHandlerWin32('.torrent', 'io.webtorrent.torrent', process.execPath)
function unregisterProtocolHandlerWin32 (protocol, command) {
getCommand()
function getCommand () {
var commandKey = new Registry({
hive: Registry.HKCU, // HKEY_CURRENT_USER
key: '\\Software\\Classes\\' + protocol + '\\shell\\open\\command'
})
commandKey.get('', function (err, item) {
if (!err && item.value.indexOf(command) >= 0) {
eraseProtocol()
}
})
}
function eraseProtocol () {
var protocolKey = new Registry({
hive: Registry.HKCU,
key: '\\Software\\Classes\\' + protocol
})
protocolKey.erase(function () {})
}
}
function unregisterFileHandlerWin32 (ext, id, command) {
eraseId()
function eraseId () {
var idKey = new Registry({
hive: Registry.HKCU, // HKEY_CURRENT_USER
key: '\\Software\\Classes\\' + id
})
idKey.erase(getExt)
}
function getExt () {
var extKey = new Registry({
hive: Registry.HKCU,
key: '\\Software\\Classes\\' + ext
})
extKey.get('', function (err, item) {
if (!err && item.value === id) {
eraseExt()
}
})
}
function eraseExt () {
var extKey = new Registry({
hive: Registry.HKCU, // HKEY_CURRENT_USER
key: '\\Software\\Classes\\' + ext
})
extKey.erase(function () {})
}
}
}
function installLinux () {
var config = require('../config')
var fs = require('fs')
var mkdirp = require('mkdirp')
@@ -224,3 +302,27 @@ function initLinux () {
})
}
}
function uninstallLinux () {
var os = require('os')
var path = require('path')
var rimraf = require('rimraf')
var desktopFilePath = path.join(
os.homedir(),
'.local',
'share',
'applications',
'webtorrent-desktop.desktop'
)
rimraf.sync(desktopFilePath)
var iconFilePath = path.join(
os.homedir(),
'.local',
'share',
'icons',
'webtorrent-desktop.png'
)
rimraf.sync(iconFilePath)
}

View File

@@ -55,7 +55,7 @@ function init () {
windows.createMainWindow()
shortcuts.init()
tray.init()
handlers.init()
handlers.install()
})
app.on('ipcReady', function () {

View File

@@ -11,6 +11,8 @@ var pathExists = require('path-exists')
var app = electron.app
var handlers = require('./handlers')
var exeName = path.basename(process.execPath)
var updateDotExe = path.join(process.execPath, '..', '..', 'Update.exe')
@@ -41,6 +43,10 @@ function handleEvent (cmd) {
removeShortcuts(function () {
app.quit()
})
// Uninstall .torrent file and magnet link handlers
handlers.uninstall()
return true
}

View File

@@ -29,11 +29,12 @@
"network-address": "^1.1.0",
"path-exists": "^2.1.0",
"prettier-bytes": "^1.0.1",
"rimraf": "^2.5.2",
"simple-get": "^2.0.0",
"upload-element": "^1.0.1",
"virtual-dom": "^2.1.1",
"webtorrent": "^0.90.0",
"winreg": "^1.0.1"
"winreg": "feross/node-winreg"
},
"devDependencies": {
"electron-osx-sign": "^0.3.0",
@@ -42,7 +43,6 @@
"gh-release": "^2.0.3",
"nobin-debian-installer": "^0.0.6",
"plist": "^1.2.0",
"rimraf": "^2.5.2",
"standard": "^6.0.5"
},
"homepage": "https://webtorrent.io",