Skip to content

Commit fd3e243

Browse files
committed
feat: Check for missing wakatime cli. And display modal and alert message.
1 parent 938b075 commit fd3e243

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

browser/main/modals/PreferencesModal/PluginsTab.js

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import React from 'react'
33
import CSSModules from 'browser/lib/CSSModules'
44
import styles from './ConfigTab.styl'
55
import ConfigManager from 'browser/main/lib/ConfigManager'
6-
import store from 'browser/main/store'
6+
import { store } from 'browser/main/store'
77
import _ from 'lodash'
88
import i18n from 'browser/lib/i18n'
9-
9+
import { sync as commandExists } from 'command-exists'
1010
const electron = require('electron')
1111
const ipc = electron.ipcRenderer
12-
12+
const { remote } = electron
13+
const { dialog } = remote
1314
class 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'>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"chart.js": "^2.7.2",
6262
"codemirror": "^5.40.2",
6363
"codemirror-mode-elixir": "^1.1.1",
64+
"command-exists": "^1.2.9",
6465
"connected-react-router": "^6.4.0",
6566
"electron-config": "^1.0.0",
6667
"electron-gh-releases": "^2.0.4",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,11 @@ [email protected], combined-stream@~1.0.5:
19661966
dependencies:
19671967
delayed-stream "~1.0.0"
19681968

1969+
command-exists@^1.2.9:
1970+
version "1.2.9"
1971+
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.9.tgz#c50725af3808c8ab0260fd60b01fbfa25b954f69"
1972+
integrity sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==
1973+
19691974
commander@2:
19701975
version "2.16.0"
19711976
resolved "http://registry.npm.taobao.org/commander/download/commander-2.16.0.tgz#f16390593996ceb4f3eeb020b31d78528f7f8a50"

0 commit comments

Comments
 (0)