diff --git a/browser/main/modals/PreferencesModal/PluginsTab.js b/browser/main/modals/PreferencesModal/PluginsTab.js index 1b1ebfa4..5e054a04 100644 --- a/browser/main/modals/PreferencesModal/PluginsTab.js +++ b/browser/main/modals/PreferencesModal/PluginsTab.js @@ -3,13 +3,14 @@ import React from 'react' import CSSModules from 'browser/lib/CSSModules' import styles from './ConfigTab.styl' import ConfigManager from 'browser/main/lib/ConfigManager' -import store from 'browser/main/store' +import { store } from 'browser/main/store' import _ from 'lodash' import i18n from 'browser/lib/i18n' - +import { sync as commandExists } from 'command-exists' const electron = require('electron') const ipc = electron.ipcRenderer - +const { remote } = electron +const { dialog } = remote class PluginsTab extends React.Component { constructor(props) { super(props) @@ -59,6 +60,35 @@ class PluginsTab extends React.Component { ipc.removeListener('APP_SETTING_ERROR', this.handleSettingError) } + checkPluginsRequirements() { + this.checkWakatimePluginRequirement() + } + + checkWakatimePluginRequirement() { + if (!commandExists('wakatime-cli')) { + this.setState({ + wakatimePlugin: { + type: i18n.__('Warning'), + message: i18n.__('Missing wakatime-cli') + } + }) + + const alertConfig = { + type: 'warning', + message: i18n.__('Missing Wakatime CLI'), + detail: i18n.__( + `Please install Wakatime CLI to use Wakatime tracker feature.` + ), + buttons: [i18n.__('OK')] + } + dialog.showMessageBox(remote.getCurrentWindow(), alertConfig) + } else { + this.setState({ + wakatimePlugin: null + }) + } + } + handleSaveButtonClick(e) { const newConfig = { wakatime: this.state.config.wakatime @@ -72,6 +102,7 @@ class PluginsTab extends React.Component { }) this.clearMessage() this.props.haveToSave() + this.checkPluginsRequirements() } handleWakatimeKeyChange(e) { @@ -105,6 +136,13 @@ class PluginsTab extends React.Component { pluginsAlert != null ? (

{pluginsAlert.message}

) : null + + const wakatimeAlert = this.state.wakatimePlugin + const wakatimePluginAlertElement = + wakatimeAlert != null ? ( +

{wakatimeAlert.message}

+ ) : null + const { config } = this.state return ( @@ -121,6 +159,7 @@ class PluginsTab extends React.Component { value={config.wakatime.key} type='text' /> + {wakatimePluginAlertElement}
diff --git a/package.json b/package.json index 0682c1bb..46c23312 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "chart.js": "^2.7.2", "codemirror": "^5.40.2", "codemirror-mode-elixir": "^1.1.1", + "command-exists": "^1.2.9", "connected-react-router": "^6.4.0", "electron-config": "^1.0.0", "electron-gh-releases": "^2.0.4", diff --git a/yarn.lock b/yarn.lock index 27221ff9..b29c94f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1966,6 +1966,11 @@ combined-stream@1.0.6, combined-stream@~1.0.5: dependencies: delayed-stream "~1.0.0" +command-exists@^1.2.9: + version "1.2.9" + resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.9.tgz#c50725af3808c8ab0260fd60b01fbfa25b954f69" + integrity sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w== + commander@2: version "2.16.0" resolved "http://registry.npm.taobao.org/commander/download/commander-2.16.0.tgz#f16390593996ceb4f3eeb020b31d78528f7f8a50"