mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-15 02:36:36 +00:00
Add wakatime-plugin #2810
This commit is contained in:
@@ -26,6 +26,8 @@ import TurndownService from 'turndown'
|
||||
import {
|
||||
gfm
|
||||
} from 'turndown-plugin-gfm'
|
||||
import { findStorage } from 'browser/lib/findStorage'
|
||||
import { sendWakatimeHeartBeat } from 'browser/lib/wakatime-plugin'
|
||||
|
||||
CodeMirror.modeURL = '../node_modules/codemirror/mode/%N/%N.js'
|
||||
|
||||
@@ -741,8 +743,14 @@ export default class CodeEditor extends React.Component {
|
||||
this.updateHighlight(editor, changeObject)
|
||||
|
||||
this.value = editor.getValue()
|
||||
|
||||
const { storageKey, noteKey } = this.props
|
||||
const storage = findStorage(storageKey)
|
||||
if (this.props.onChange) {
|
||||
this.props.onChange(editor)
|
||||
if (storage) sendWakatimeHeartBeat(storage.path, noteKey, storage.name, true, true, false)
|
||||
} else {
|
||||
if (storage) sendWakatimeHeartBeat(storage.path, noteKey, storage.name, false, false, false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -846,6 +854,11 @@ export default class CodeEditor extends React.Component {
|
||||
}
|
||||
|
||||
reload () {
|
||||
// wakatime
|
||||
const { storageKey, noteKey } = this.props
|
||||
const storage = findStorage(storageKey)
|
||||
if (storage) sendWakatimeHeartBeat(storage.path, noteKey, storage.name, false, false, true)
|
||||
|
||||
// Change event shouldn't be fired when switch note
|
||||
this.editor.off('change', this.changeHandler)
|
||||
this.value = this.props.value
|
||||
|
||||
26
browser/lib/wakatime-plugin.js
Normal file
26
browser/lib/wakatime-plugin.js
Normal file
@@ -0,0 +1,26 @@
|
||||
const exec = require('child_process').exec
|
||||
const path = require('path')
|
||||
let lastHeartbeat = 0
|
||||
|
||||
function sendWakatimeHeartBeat (storagePath, noteKey, storageName, isWrite, hasFileChanges, isFileChange) {
|
||||
|
||||
if (new Date().getTime() - lastHeartbeat > 120000 || isFileChange) {
|
||||
const notePath = path.join(storagePath, 'notes', noteKey + '.cson')
|
||||
|
||||
if (!isWrite && !hasFileChanges && !isFileChange) {
|
||||
return
|
||||
}
|
||||
|
||||
// TODO: add --key sdasdsa-sdsad-asdasd-asdsa-asdasdadas from configuration UI or use ~/.wakatime.conf
|
||||
exec(`wakatime --file ${notePath} --project ${storageName} --plugin Boostnote-wakatime`, (error, stdOut, stdErr) => {
|
||||
if (error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
lastHeartbeat = new Date()
|
||||
console.log('wakatime', 'isWrite', isWrite, 'hasChanges', hasFileChanges)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export { sendWakatimeHeartBeat }
|
||||
Reference in New Issue
Block a user