1
1
'use strict'
2
2
3
3
const React = require ( 'react' )
4
- const ipc = require ( 'ipc' )
5
- const shell = require ( 'shell' )
4
+ const ReactDOM = require ( 'react-dom' )
5
+ const { ipcRenderer} = require ( 'electron' )
6
+ const { shell} = require ( 'electron' )
6
7
const url = require ( 'url' )
7
8
8
9
const App = React . createClass ( {
10
+
9
11
getInitialState ( ) {
10
12
return {
11
13
slackWebhookUrl : window . localStorage . getItem ( 'slackWebhookUrl' ) ,
12
- listenerName : window . localStorage . getItem ( 'listenerName' )
14
+ listenerName : window . localStorage . getItem ( 'listenerName' ) ,
15
+ autoSend : ( window . localStorage . getItem ( 'autoSend' ) === null || window . localStorage . getItem ( 'autoSend' ) === 'true' ) // localstorage only knows strings
13
16
}
14
17
} ,
15
18
16
19
componentDidMount ( ) {
17
- ipc . send ( 'data' , this . state )
20
+ ipcRenderer . send ( 'data' , this . state )
18
21
} ,
19
22
20
23
componentDidUpdate ( ) {
21
- ipc . send ( 'data' , this . state )
24
+ ipcRenderer . send ( 'data' , this . state )
22
25
} ,
23
26
24
27
inputIsValid ( ) {
@@ -28,6 +31,15 @@ const App = React.createClass({
28
31
render ( ) {
29
32
const self = this
30
33
34
+ const onlyIfChecked = ! this . state . autoSend
35
+ ? React . DOM . button ( {
36
+ className : 'btn btn-default btn-sendnow' ,
37
+ onClick : function ( ) {
38
+ ipcRenderer . send ( 'sendnow' )
39
+ }
40
+ } , 'Send Now' )
41
+ : null
42
+
31
43
return (
32
44
React . DOM . main ( {
33
45
className : 'container'
@@ -67,25 +79,35 @@ const App = React.createClass({
67
79
window . localStorage . setItem ( 'listenerName' , e . target . value )
68
80
}
69
81
} ) ,
82
+ React . DOM . input ( {
83
+ className : 'checkbox' ,
84
+ id : 'autosend-checkbox' ,
85
+ type : 'checkbox' ,
86
+ defaultChecked : self . state . autoSend ,
87
+ onChange : function ( e ) {
88
+ self . setState ( { autoSend : e . target . checked } )
89
+ window . localStorage . setItem ( 'autoSend' , e . target . checked )
90
+ }
91
+ } ) ,
92
+ React . DOM . label ( { htmlFor : 'autosend-checkbox' } , 'Send automatically' ) ,
70
93
this . inputIsValid ( ) && React . DOM . div ( { className : 'alert alert-success' } , '✔ Play music on iTunes!' )
71
94
] ) ,
72
-
95
+ onlyIfChecked ,
73
96
React . DOM . button ( {
74
97
className : 'btn btn-default btn-quit' ,
75
98
onClick : function ( ) {
76
- ipc . send ( 'terminate' )
99
+ ipcRenderer . send ( 'terminate' )
77
100
}
78
101
} , 'Quit' )
79
102
] )
80
103
)
81
104
}
82
105
} )
83
106
84
- React . render ( React . createFactory ( App ) ( ) , document . body )
107
+ ReactDOM . render ( React . createFactory ( App ) ( ) , document . getElementById ( 'content' ) )
85
108
86
- var remote = require ( 'remote' )
87
- var Menu = remote . require ( 'menu' )
88
- var MenuItem = remote . require ( 'menu-item' )
109
+ const { remote} = require ( 'electron' )
110
+ const { Menu, MenuItem} = remote
89
111
90
112
var menu = new Menu ( )
91
113
menu . append ( new MenuItem ( {
0 commit comments