Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

muxrpc #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed docs/.nojekyll
Empty file.
865 changes: 0 additions & 865 deletions docs/assets/css/main.css

This file was deleted.

7 changes: 0 additions & 7 deletions docs/assets/css/main.css.map

This file was deleted.

Binary file removed docs/assets/images/icons.png
Binary file not shown.
Binary file removed docs/assets/images/[email protected]
Binary file not shown.
Binary file removed docs/assets/images/widgets.png
Binary file not shown.
Binary file removed docs/assets/images/[email protected]
Binary file not shown.
5 changes: 0 additions & 5 deletions docs/assets/js/main.js

This file was deleted.

3 changes: 0 additions & 3 deletions docs/assets/js/search.js

This file was deleted.

1,794 changes: 0 additions & 1,794 deletions docs/classes/_index_.systray.html

This file was deleted.

1,618 changes: 0 additions & 1,618 deletions docs/classes/_index_.systray.internal.eventemitter.html

This file was deleted.

1,067 changes: 0 additions & 1,067 deletions docs/globals.html

This file was deleted.

1,068 changes: 0 additions & 1,068 deletions docs/index.html

This file was deleted.

1,353 changes: 0 additions & 1,353 deletions docs/modules/_index_.html

This file was deleted.

1,004 changes: 0 additions & 1,004 deletions docs/modules/_index_.systray.internal.html

This file was deleted.

94 changes: 94 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
const { EventEmitter } = require('events')
const { spawn } = require('child_process')
const pull = require('pull-stream')
const toPull = require('stream-to-pull-stream')
const pndj = require('pull-ndjson')
const Notify = require('pull-notify')

const { whereis, helperName } = require('./util')


class SysTray extends EventEmitter {
constructor(conf) {
const debugPull = (from) => {
if (typeof process.env["DEBUG"] === 'undefined') {
return pull.through()
}
return pull.through((data) => {
if (data instanceof Buffer) {
console.warn(from, ":", data.toString())
} else {
console.warn(from, ":", data)
}
})
}

super()
this._conf = conf
this._notifyHelper = Notify()

this._helperPath = whereis(helperName)
if (this._helperPath === '') {
console.error('could not locate helper binary:', helperName)
process.exit(1)
}

this._helper = spawn(this._helperPath, [], {
windowsHide: true
})
this._helper.stderr.pipe(process.stderr)

// from helper
pull(
toPull.source(this._helper.stdout),
debugPull("hstdout"),
pndj.parse(),
pull.drain((v) => {
if (v.type === 'ready') {
this.emit('ready', v)
}
if (v.type === 'clicked') {
this.emit('click', v)
}
})
)

// to helper
pull(
this._notifyHelper.listen(),
pndj.serialize(),
debugPull('hstdin'),
toPull.sink(this._helper.stdin)
)

// was onError
this._helper.on('error', e => {
this.emit('error', e)
})

// was onExit
this._helper.on('exit', (code, signal) => {
this.emit('exit', {code, signal})
})

// was sendAction
this.on('action', this._notifyHelper)

// initialize menu
this._notifyHelper(conf.menu)
}

/**
* Kill the systray process
* @param exitNode Exit current node process after systray process is killed, default is true
*/
kill(exitNode = true) {
this._notifyHelper.end()
this._helper.kill()
if (exitNode) {
this.on('exit', () => process.exit(0))
}
}
}

module.exports = SysTray
Loading