forked from zaaack/node-systray
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.js
64 lines (55 loc) · 2.1 KB
/
util.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
const { existsSync } = require('fs')
const { join } = require('path')
const { homedir } = require('os')
/* cloned from [email protected]
github repo was removed somehow so no way to give feedback/PRs
therefore copied it here */
const whereis = (filename) => {
const pathSep = process.platform === 'win32' ? ';' : ':'
const directories = process.env.PATH.split(pathSep)
for (var i = 0; i < directories.length; i++) {
var path = directories[i] + '/' + filename
if (existsSync(path)) {
return path
}
}
// impure check if we already fetched the helper
if (existsSync(helperLocation)) {
return helperLocation
}
return ''
}
exports.whereis = whereis
const helperName = process.platform === 'win32' ? 'systrayhelper.exe' : 'systrayhelper'
exports.helperName = helperName
// this is the fallback location where the prebuilt will be put
const helperLocation = join(__dirname, helperName)
exports.helperLocation = helperLocation
exports.errorAndExit = (err) => {
console.error(err)
console.warn('\n######\nHello, sorry you had to see this...')
console.warn(`\nFailed to fetch pre-built systrayhelper.
Most likely the combination of OS and Architecture isn't currently supported.
To still get this working you will have to do some console-magic...
1) Install Go - See https://golang.org/doc/install
1.5) On linux: you need two libraries, listed here: https://github.com/getlantern/systray#platform-specific-concerns
2) run this command: go get github.com/ssbc/systrayhelper
3) sudo mv $HOME/go/bin/systrayhelper /usr/local/bin (or any other folder, as long as it's in your $PATH)
TODO: evaluate falling back to https://github.com/chemdrew/npm-golang
TODO: brew.sh and windows snoop templates installing the helper`)
process.exit(1)
}
exports.shasum = (done) => {
var hasher = require('crypto').createHash('sha256')
var Transform = require('stream').Transform
var t = new Transform({
transform: function (data, encoding, cb) {
hasher.update(data)
cb(null, data)
}
})
t.on('end', function () {
done(hasher.digest().toString('hex'))
})
return t
}