mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 02:36:36 +00:00
feat: Add checkbox validation to active or deactive plugin.
This commit is contained in:
@@ -11,7 +11,11 @@ function sendWakatimeHeartBeat(
|
|||||||
hasFileChanges,
|
hasFileChanges,
|
||||||
isFileChange
|
isFileChange
|
||||||
) {
|
) {
|
||||||
if (new Date().getTime() - lastHeartbeat > 120000 || isFileChange) {
|
if (
|
||||||
|
config.get().wakatime.isActive &&
|
||||||
|
!!config.get().wakatime.key &&
|
||||||
|
(new Date().getTime() - lastHeartbeat > 120000 || isFileChange)
|
||||||
|
) {
|
||||||
const notePath = path.join(storagePath, 'notes', noteKey + '.cson')
|
const notePath = path.join(storagePath, 'notes', noteKey + '.cson')
|
||||||
|
|
||||||
if (!isWrite && !hasFileChanges && !isFileChange) {
|
if (!isWrite && !hasFileChanges && !isFileChange) {
|
||||||
|
|||||||
@@ -30,27 +30,15 @@ class PluginsTab extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.handleSettingError = err => {
|
this.handleSettingError = err => {
|
||||||
if (
|
this.setState({
|
||||||
this.state.config.wakatime.key === '' ||
|
pluginsAlert: {
|
||||||
this.state.config.wakatime.key === null
|
type: 'error',
|
||||||
) {
|
message:
|
||||||
this.setState({
|
err.message != null ? err.message : i18n.__('An error occurred!')
|
||||||
pluginsAlert: {
|
}
|
||||||
type: 'success',
|
})
|
||||||
message: i18n.__('Successfully applied!')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
this.setState({
|
|
||||||
pluginsAlert: {
|
|
||||||
type: 'error',
|
|
||||||
message:
|
|
||||||
err.message != null ? err.message : i18n.__('An error occurred!')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.oldWakatimekey = this.state.config.wakatime
|
this.oldWakatimeConfig = this.state.config.wakatime
|
||||||
ipc.addListener('APP_SETTING_DONE', this.handleSettingDone)
|
ipc.addListener('APP_SETTING_DONE', this.handleSettingDone)
|
||||||
ipc.addListener('APP_SETTING_ERROR', this.handleSettingError)
|
ipc.addListener('APP_SETTING_ERROR', this.handleSettingError)
|
||||||
}
|
}
|
||||||
@@ -65,9 +53,10 @@ class PluginsTab extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkWakatimePluginRequirement() {
|
checkWakatimePluginRequirement() {
|
||||||
if (!commandExists('wakatime-cli')) {
|
const { wakatime } = this.state.config
|
||||||
|
if (wakatime.isActive && !commandExists('wakatime-cli')) {
|
||||||
this.setState({
|
this.setState({
|
||||||
wakatimePlugin: {
|
wakatimePluginAlert: {
|
||||||
type: i18n.__('Warning'),
|
type: i18n.__('Warning'),
|
||||||
message: i18n.__('Missing wakatime-cli')
|
message: i18n.__('Missing wakatime-cli')
|
||||||
}
|
}
|
||||||
@@ -84,14 +73,17 @@ class PluginsTab extends React.Component {
|
|||||||
dialog.showMessageBox(remote.getCurrentWindow(), alertConfig)
|
dialog.showMessageBox(remote.getCurrentWindow(), alertConfig)
|
||||||
} else {
|
} else {
|
||||||
this.setState({
|
this.setState({
|
||||||
wakatimePlugin: null
|
wakatimePluginAlert: null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSaveButtonClick(e) {
|
handleSaveButtonClick(e) {
|
||||||
const newConfig = {
|
const newConfig = {
|
||||||
wakatime: this.state.config.wakatime
|
wakatime: {
|
||||||
|
isActive: this.state.config.wakatime.isActive,
|
||||||
|
key: this.state.config.wakatime.key
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigManager.set(newConfig)
|
ConfigManager.set(newConfig)
|
||||||
@@ -105,13 +97,33 @@ class PluginsTab extends React.Component {
|
|||||||
this.checkPluginsRequirements()
|
this.checkPluginsRequirements()
|
||||||
}
|
}
|
||||||
|
|
||||||
handleWakatimeKeyChange(e) {
|
handleIsWakatimePluginActiveChange(e) {
|
||||||
const { config } = this.state
|
const { config } = this.state
|
||||||
config.wakatime = { key: this.refs.key.value }
|
config.wakatime.isActive = !config.wakatime.isActive
|
||||||
this.setState({
|
this.setState({
|
||||||
config
|
config
|
||||||
})
|
})
|
||||||
if (_.isEqual(this.oldWakatimekey, config.wakatime)) {
|
if (_.isEqual(this.oldWakatimeConfig.isActive, config.wakatime.isActive)) {
|
||||||
|
this.props.haveToSave()
|
||||||
|
} else {
|
||||||
|
this.props.haveToSave({
|
||||||
|
tab: 'Plugins',
|
||||||
|
type: 'warning',
|
||||||
|
message: i18n.__('Unsaved Changes!')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleWakatimeKeyChange(e) {
|
||||||
|
const { config } = this.state
|
||||||
|
config.wakatime = {
|
||||||
|
isActive: true,
|
||||||
|
key: this.refs.wakatimeKey.value
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
config
|
||||||
|
})
|
||||||
|
if (_.isEqual(this.oldWakatimeConfig.key, config.wakatime.key)) {
|
||||||
this.props.haveToSave()
|
this.props.haveToSave()
|
||||||
} else {
|
} else {
|
||||||
this.props.haveToSave({
|
this.props.haveToSave({
|
||||||
@@ -137,7 +149,7 @@ class PluginsTab extends React.Component {
|
|||||||
<p className={`alert ${pluginsAlert.type}`}>{pluginsAlert.message}</p>
|
<p className={`alert ${pluginsAlert.type}`}>{pluginsAlert.message}</p>
|
||||||
) : null
|
) : null
|
||||||
|
|
||||||
const wakatimeAlert = this.state.wakatimePlugin
|
const wakatimeAlert = this.state.wakatimePluginAlert
|
||||||
const wakatimePluginAlertElement =
|
const wakatimePluginAlertElement =
|
||||||
wakatimeAlert != null ? (
|
wakatimeAlert != null ? (
|
||||||
<p className={`alert ${wakatimeAlert.type}`}>{wakatimeAlert.message}</p>
|
<p className={`alert ${wakatimeAlert.type}`}>{wakatimeAlert.message}</p>
|
||||||
@@ -150,12 +162,25 @@ class PluginsTab extends React.Component {
|
|||||||
<div styleName='group'>
|
<div styleName='group'>
|
||||||
<div styleName='group-header'>{i18n.__('Plugins')}</div>
|
<div styleName='group-header'>{i18n.__('Plugins')}</div>
|
||||||
<div styleName='group-section'>
|
<div styleName='group-section'>
|
||||||
<div styleName='group-section-label'>{i18n.__('Wakatime key')}</div>
|
<div styleName='group-section-label'>
|
||||||
|
<div styleName='group-checkBoxSection'>
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
onChange={e => this.handleIsWakatimePluginActiveChange(e)}
|
||||||
|
checked={config.wakatime.isActive}
|
||||||
|
ref='wakatimeIsActive'
|
||||||
|
type='checkbox'
|
||||||
|
/>
|
||||||
|
|
||||||
|
{i18n.__('Wakatime key')}
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div styleName='group-section-control'>
|
<div styleName='group-section-control'>
|
||||||
<input
|
<input
|
||||||
styleName='group-section-control-input'
|
styleName='group-section-control-input'
|
||||||
onChange={e => this.handleWakatimeKeyChange(e)}
|
onChange={e => this.handleWakatimeKeyChange(e)}
|
||||||
ref='key'
|
ref='wakatimeKey'
|
||||||
value={config.wakatime.key}
|
value={config.wakatime.key}
|
||||||
type='text'
|
type='text'
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user