@@ -30,27 +30,15 @@ class PluginsTab extends React.Component {
30
30
} )
31
31
}
32
32
this . handleSettingError = err => {
33
- if (
34
- this . state . config . wakatime . key === '' ||
35
- this . state . config . wakatime . key === null
36
- ) {
37
- this . setState ( {
38
- pluginsAlert : {
39
- type : 'success' ,
40
- message : i18n . __ ( 'Successfully applied!' )
41
- }
42
- } )
43
- } else {
44
- this . setState ( {
45
- pluginsAlert : {
46
- type : 'error' ,
47
- message :
48
- err . message != null ? err . message : i18n . __ ( 'An error occurred!' )
49
- }
50
- } )
51
- }
33
+ this . setState ( {
34
+ pluginsAlert : {
35
+ type : 'error' ,
36
+ message :
37
+ err . message != null ? err . message : i18n . __ ( 'An error occurred!' )
38
+ }
39
+ } )
52
40
}
53
- this . oldWakatimekey = this . state . config . wakatime
41
+ this . oldWakatimeConfig = this . state . config . wakatime
54
42
ipc . addListener ( 'APP_SETTING_DONE' , this . handleSettingDone )
55
43
ipc . addListener ( 'APP_SETTING_ERROR' , this . handleSettingError )
56
44
}
@@ -65,9 +53,10 @@ class PluginsTab extends React.Component {
65
53
}
66
54
67
55
checkWakatimePluginRequirement ( ) {
68
- if ( ! commandExists ( 'wakatime-cli' ) ) {
56
+ const { wakatime } = this . state . config
57
+ if ( wakatime . isActive && ! commandExists ( 'wakatime-cli' ) ) {
69
58
this . setState ( {
70
- wakatimePlugin : {
59
+ wakatimePluginAlert : {
71
60
type : i18n . __ ( 'Warning' ) ,
72
61
message : i18n . __ ( 'Missing wakatime-cli' )
73
62
}
@@ -84,14 +73,17 @@ class PluginsTab extends React.Component {
84
73
dialog . showMessageBox ( remote . getCurrentWindow ( ) , alertConfig )
85
74
} else {
86
75
this . setState ( {
87
- wakatimePlugin : null
76
+ wakatimePluginAlert : null
88
77
} )
89
78
}
90
79
}
91
80
92
81
handleSaveButtonClick ( e ) {
93
82
const newConfig = {
94
- wakatime : this . state . config . wakatime
83
+ wakatime : {
84
+ isActive : this . state . config . wakatime . isActive ,
85
+ key : this . state . config . wakatime . key
86
+ }
95
87
}
96
88
97
89
ConfigManager . set ( newConfig )
@@ -105,13 +97,33 @@ class PluginsTab extends React.Component {
105
97
this . checkPluginsRequirements ( )
106
98
}
107
99
100
+ handleIsWakatimePluginActiveChange ( e ) {
101
+ const { config } = this . state
102
+ config . wakatime . isActive = ! config . wakatime . isActive
103
+ this . setState ( {
104
+ config
105
+ } )
106
+ if ( _ . isEqual ( this . oldWakatimeConfig . isActive , config . wakatime . isActive ) ) {
107
+ this . props . haveToSave ( )
108
+ } else {
109
+ this . props . haveToSave ( {
110
+ tab : 'Plugins' ,
111
+ type : 'warning' ,
112
+ message : i18n . __ ( 'Unsaved Changes!' )
113
+ } )
114
+ }
115
+ }
116
+
108
117
handleWakatimeKeyChange ( e ) {
109
118
const { config } = this . state
110
- config . wakatime = { key : this . refs . key . value }
119
+ config . wakatime = {
120
+ isActive : true ,
121
+ key : this . refs . wakatimeKey . value
122
+ }
111
123
this . setState ( {
112
124
config
113
125
} )
114
- if ( _ . isEqual ( this . oldWakatimekey , config . wakatime ) ) {
126
+ if ( _ . isEqual ( this . oldWakatimeConfig . key , config . wakatime . key ) ) {
115
127
this . props . haveToSave ( )
116
128
} else {
117
129
this . props . haveToSave ( {
@@ -137,7 +149,7 @@ class PluginsTab extends React.Component {
137
149
< p className = { `alert ${ pluginsAlert . type } ` } > { pluginsAlert . message } </ p >
138
150
) : null
139
151
140
- const wakatimeAlert = this . state . wakatimePlugin
152
+ const wakatimeAlert = this . state . wakatimePluginAlert
141
153
const wakatimePluginAlertElement =
142
154
wakatimeAlert != null ? (
143
155
< p className = { `alert ${ wakatimeAlert . type } ` } > { wakatimeAlert . message } </ p >
@@ -150,12 +162,25 @@ class PluginsTab extends React.Component {
150
162
< div styleName = 'group' >
151
163
< div styleName = 'group-header' > { i18n . __ ( 'Plugins' ) } </ div >
152
164
< div styleName = 'group-section' >
153
- < div styleName = 'group-section-label' > { i18n . __ ( 'Wakatime key' ) } </ div >
165
+ < div styleName = 'group-section-label' >
166
+ < div styleName = 'group-checkBoxSection' >
167
+ < label >
168
+ < input
169
+ onChange = { e => this . handleIsWakatimePluginActiveChange ( e ) }
170
+ checked = { config . wakatime . isActive }
171
+ ref = 'wakatimeIsActive'
172
+ type = 'checkbox'
173
+ />
174
+
175
+ { i18n . __ ( 'Wakatime key' ) }
176
+ </ label >
177
+ </ div >
178
+ </ div >
154
179
< div styleName = 'group-section-control' >
155
180
< input
156
181
styleName = 'group-section-control-input'
157
182
onChange = { e => this . handleWakatimeKeyChange ( e ) }
158
- ref = 'key '
183
+ ref = 'wakatimeKey '
159
184
value = { config . wakatime . key }
160
185
type = 'text'
161
186
/>
0 commit comments