Skip to content

Commit

Permalink
release v1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ZimoLoveShuang committed Nov 29, 2020
1 parent e40f46a commit f4dd63c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
hbuilderx-wakatime.zip
hbuilderx-wakatime.zip

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

# 更新日志

- 2020-11-29 修复os被识别为null的bug v1.0.3
- 2020-11-26 一些小优化 v1.0.2
- 2020-11-24 修复识别为Unknown Editor的bug v1.0.1
- 2020-11-23 发布 v1.0.0
Expand Down
27 changes: 13 additions & 14 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const ini = require('ini')
const request = require('request')

const plugin_name = 'HbuilderX-wakatime'
const plugin_version = '1.0.2'
const plugin_version = '1.0.3'
const ide = hx.env.appName
const ide_version = hx.env.appVersion
const config_path = path.format({
Expand All @@ -17,7 +17,7 @@ const config_path = path.format({

var lastAction = 0
var lastFile = undefined
var debug = false
var debug = true
var partten = /\w{8}-\w{4}-\w{4}-\w{4}-\w{12}/

// 读取api_key,如果不存在就创建
Expand Down Expand Up @@ -53,7 +53,7 @@ function enoughTimePassed() {
}

// 发送心跳包
function sendHeartbeat(file, time, project, language, isWrite, lines, api_key) {
function sendHeartbeat(file, time, project, language, isWrite, lines) {
var data = {
entity: file,
type: 'file',
Expand All @@ -73,7 +73,7 @@ function sendHeartbeat(file, time, project, language, isWrite, lines, api_key) {
json: true,
headers: {
'Content-Type': 'application/json',
'User-Agent': ide + '/' + ide_version + ' ' + plugin_name + '/' + plugin_version,
'User-Agent': ide + '/' + ide_version + ' (' + os.type() + ' ' + os.release() + ')',
'Authorization': 'Basic ' + Buffer.from(api_key).toString('base64')
},
body: data
Expand All @@ -87,19 +87,18 @@ function sendHeartbeat(file, time, project, language, isWrite, lines, api_key) {
lastFile = file
}

function handleAction(isWrite, api_key) {
function handleAction(isWrite) {
api_key = read_api_key()
hx.window.getActiveTextEditor()
.then(function(editor) {
var currentDocument = editor.document
if (debug) console.log(currentDocument)
var time = Date.now()
if (isWrite || enoughTimePassed() || lastFile !== currentDocument.uri.fsPath) {
hx.workspace.getWorkspaceFolder("%fsPath%").then(function(wsFolder) {
var language = currentDocument.languageId ? currentDocument.languageId : undefined
var project = wsFolder.name ? wsFolder.name : undefined
var lines = currentDocument.lineCount ? currentDocument.lineCount : undefined
sendHeartbeat(currentDocument.uri.fsPath, time, project, language, isWrite, lines, api_key)
})
var language = currentDocument.languageId ? currentDocument.languageId : undefined
var project = currentDocument.workspaceFolder.name ? currentDocument.workspaceFolder.name : undefined
var lines = currentDocument.lineCount ? currentDocument.lineCount : undefined
sendHeartbeat(currentDocument.uri.fsPath, time, project, language, isWrite, lines, api_key)
}
})
}
Expand All @@ -119,15 +118,15 @@ function activate(context) {
hx.workspace.onDidChangeTextDocument(function(event) {
let document = event.document;
if (debug) console.log('文档被修改时的事件' + JSON.stringify(document))
handleAction(true, api_key)
handleAction(true)
})
hx.workspace.onDidSaveTextDocument(function(document) {
if (debug) console.log('文档被保存时的事件' + JSON.stringify(document))
handleAction(true, api_key)
handleAction(true)
})
hx.workspace.onDidOpenTextDocument(function(document) {
if (debug) console.log('文档被打开时的事件' + JSON.stringify(document))
handleAction(true, api_key)
handleAction(true)
})
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "wakatime-hbuilderx",
"description": "Wakatime plug-in of hbuilderx",
"displayName": "wakatime",
"version": "1.0.2",
"version": "1.0.3",
"publisher": "zimo",
"engines": {
"HBuilderX": "^2.7.0"
Expand Down

0 comments on commit f4dd63c

Please sign in to comment.