@@ -3,13 +3,14 @@ import React from 'react'
33import CSSModules from 'browser/lib/CSSModules'
44import styles from './ConfigTab.styl'
55import ConfigManager from 'browser/main/lib/ConfigManager'
6- import store from 'browser/main/store'
6+ import { store } from 'browser/main/store'
77import _ from 'lodash'
88import i18n from 'browser/lib/i18n'
9-
9+ import { sync as commandExists } from 'command-exists'
1010const electron = require ( 'electron' )
1111const ipc = electron . ipcRenderer
12-
12+ const { remote } = electron
13+ const { dialog } = remote
1314class PluginsTab extends React . Component {
1415 constructor ( props ) {
1516 super ( props )
@@ -59,6 +60,35 @@ class PluginsTab extends React.Component {
5960 ipc . removeListener ( 'APP_SETTING_ERROR' , this . handleSettingError )
6061 }
6162
63+ checkPluginsRequirements ( ) {
64+ this . checkWakatimePluginRequirement ( )
65+ }
66+
67+ checkWakatimePluginRequirement ( ) {
68+ if ( ! commandExists ( 'wakatime-cli' ) ) {
69+ this . setState ( {
70+ wakatimePlugin : {
71+ type : i18n . __ ( 'Warning' ) ,
72+ message : i18n . __ ( 'Missing wakatime-cli' )
73+ }
74+ } )
75+
76+ const alertConfig = {
77+ type : 'warning' ,
78+ message : i18n . __ ( 'Missing Wakatime CLI' ) ,
79+ detail : i18n . __ (
80+ `Please install Wakatime CLI to use Wakatime tracker feature.`
81+ ) ,
82+ buttons : [ i18n . __ ( 'OK' ) ]
83+ }
84+ dialog . showMessageBox ( remote . getCurrentWindow ( ) , alertConfig )
85+ } else {
86+ this . setState ( {
87+ wakatimePlugin : null
88+ } )
89+ }
90+ }
91+
6292 handleSaveButtonClick ( e ) {
6393 const newConfig = {
6494 wakatime : this . state . config . wakatime
@@ -72,6 +102,7 @@ class PluginsTab extends React.Component {
72102 } )
73103 this . clearMessage ( )
74104 this . props . haveToSave ( )
105+ this . checkPluginsRequirements ( )
75106 }
76107
77108 handleWakatimeKeyChange ( e ) {
@@ -105,6 +136,13 @@ class PluginsTab extends React.Component {
105136 pluginsAlert != null ? (
106137 < p className = { `alert ${ pluginsAlert . type } ` } > { pluginsAlert . message } </ p >
107138 ) : null
139+
140+ const wakatimeAlert = this . state . wakatimePlugin
141+ const wakatimePluginAlertElement =
142+ wakatimeAlert != null ? (
143+ < p className = { `alert ${ wakatimeAlert . type } ` } > { wakatimeAlert . message } </ p >
144+ ) : null
145+
108146 const { config } = this . state
109147
110148 return (
@@ -121,6 +159,7 @@ class PluginsTab extends React.Component {
121159 value = { config . wakatime . key }
122160 type = 'text'
123161 />
162+ { wakatimePluginAlertElement }
124163 </ div >
125164 </ div >
126165 < div styleName = 'group-control' >
0 commit comments