-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapp.js
125 lines (111 loc) · 3.69 KB
/
app.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
'use strict'
const React = require('react')
const ReactDOM = require('react-dom')
const {ipcRenderer} = require('electron')
const {shell} = require('electron')
const url = require('url')
const App = React.createClass({
getInitialState () {
return {
slackWebhookUrl: window.localStorage.getItem('slackWebhookUrl'),
listenerName: window.localStorage.getItem('listenerName'),
autoSend: (window.localStorage.getItem('autoSend') === null || window.localStorage.getItem('autoSend') === 'true') // localstorage only knows strings
}
},
componentDidMount () {
ipcRenderer.send('data', this.state)
},
componentDidUpdate () {
ipcRenderer.send('data', this.state)
},
inputIsValid () {
return url.parse(this.state.slackWebhookUrl || '').host === 'hooks.slack.com'
},
render () {
const self = this
const onlyIfChecked = !this.state.autoSend
? React.DOM.button({
className: 'btn btn-default btn-sendnow',
onClick: function () {
ipcRenderer.send('sendnow')
}
}, 'Send Now')
: null
return (
React.DOM.main({
className: 'container'
}, [
React.DOM.div({}, [
React.DOM.h2({}, 'playing'),
React.DOM.p({ className: 'description' }, [
React.DOM.a({
href: 'https://slack.com/services/new/incoming-webhook',
onClick: function (e) {
e.preventDefault()
shell.openExternal(e.target.href)
}
}, 'Add a new Incoming Webhook in Slack'),
'\nand paste the webhook URL to this form.'
]),
React.DOM.label({}, 'Slack Webhook URL'),
React.DOM.input({
className: 'form-control',
type: 'text',
placeholder: 'https://hooks.slack.com/...',
value: this.state.slackWebhookUrl,
onChange: function (e) {
self.setState({ slackWebhookUrl: e.target.value })
window.localStorage.setItem('slackWebhookUrl', e.target.value)
}
}),
React.DOM.label({}, 'Your name'),
React.DOM.input({
className: 'form-control',
type: 'text',
placeholder: 'your name',
value: this.state.listenerName,
onChange: function (e) {
self.setState({ listenerName: e.target.value })
window.localStorage.setItem('listenerName', e.target.value)
}
}),
React.DOM.input({
className: 'checkbox',
id: 'autosend-checkbox',
type: 'checkbox',
defaultChecked: self.state.autoSend,
onChange: function (e) {
self.setState({ autoSend: e.target.checked })
window.localStorage.setItem('autoSend', e.target.checked)
}
}),
React.DOM.label({ htmlFor: 'autosend-checkbox' }, 'Send automatically'),
this.inputIsValid() && React.DOM.div({ className: 'alert alert-success' }, '✔ Play music on iTunes!')
]),
onlyIfChecked,
React.DOM.button({
className: 'btn btn-default btn-quit',
onClick: function () {
ipcRenderer.send('terminate')
}
}, 'Quit')
])
)
}
})
ReactDOM.render(React.createFactory(App)(), document.getElementById('content'))
const {remote} = require('electron')
const {Menu, MenuItem} = remote
var menu = new Menu()
menu.append(new MenuItem({
label: 'Copy',
selector: 'copy:'
}))
menu.append(new MenuItem({
label: 'Paste',
selector: 'paste:'
}))
window.addEventListener('contextmenu', function (e) {
e.preventDefault()
menu.popup(remote.getCurrentWindow())
}, false)