-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunUninstall.js
80 lines (71 loc) · 2.27 KB
/
runUninstall.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const path = require("path")
const os = require("os")
const { exec } = require("child_process")
const uninstall = () => {
// Get the name of the main directory
let cwd = __dirname
let dirs = cwd.split(path.sep)
let name = dirs[dirs.length - 1]
// Remove Windows Shortcuts
if (os.platform() == "win32") {
let desktop = path.join( os.homedir(), "Desktop", `${name}.lnk`)
let startMenu = path.join( os.homedir(), "AppData", "Roaming", "Microsoft", "Windows", "Start Menu", "Programs", `${name}.lnk`)
// Remove .desktop files
let command = `del "${desktop}" & del "${startMenu}"`
exec(command, (error) => {
if (error) {
console.log('')
console.log("There was an error uninstalling shortcuts: ")
console.log('')
console.log(error)
return false
} else {
console.log('')
console.log("Shortcuts have been uninstalled successfully.")
}
})
return 'Uninstall successful (Windows)'
} // Remove Linux Shortcuts
if (os.platform() == "linux") {
// Check for Ubuntu
let version = os.version()
if (version.includes("Ubuntu")) {
// Remove .desktop files
let command = `rm ~/Desktop/${name}.desktop & rm ~/.local/share/applications/${name}.desktop`
exec(command, (error) => {
if (error) {
console.log('')
console.log("There was an error uninstalling shortcuts: ")
console.log('')
console.log( error )
return false
} else {
console.log('')
console.log("Shortcuts have been uninstalled successfully.")
}
})
return 'Uninstall successful (Ubuntu)'
}
else {
return 'Uninstall not supported on non-Ubuntu Linux systems'
}
} // Mac Shortcuts
if (os.platform() == "darwin") {
// Remove .desktop files
let command = `rm ~/Desktop/${name}.command`
exec(command, (error) => {
if (error) {
console.log('')
console.log("There was an error uninstalling shortcuts: ")
console.log('')
console.log( error )
return
} else {
console.log('')
console.log("Shortcuts have been uninstalled successfully.")
}
})
return 'Uninstall successuful (MacOS)'
}
}
module.exports = uninstall