-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: create router page error * chore: router-service package version * fix: create rax-app page import error * chore: page-service version * fix: lint * fix: repeat create router * feat: Time Steward (#528) * feat: Initial release * fix: remove unuseful codetime * fix: code time init * refactor: rename * chore: make code simple * refactor: using recorder * refactor: user logic * docs: security and privacy * style: import order * style: shorthand * refactor: rename packageJson interface * refactor: logo * docs: add more section * docs: add beta description * docs: style Co-authored-by: 新影 <xinying.ykk@alibaba-inc.com> Co-authored-by: alvinhui <alvin.hui@qq.com> * fix: create router pagename param (#537) * fix: comment * fix: lint * chore: version * fix: comment Co-authored-by: luhc228 <luhengchang228@gmail.com> Co-authored-by: yincoco <524404942@qq.com> Co-authored-by: 新影 <xinying.ykk@alibaba-inc.com> Co-authored-by: Hengchang Lu <44047106+luhc228@users.noreply.github.com>
- Loading branch information
1 parent
e3346f1
commit f019d65
Showing
21 changed files
with
406 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.vscode/** | ||
.vscode-test/** | ||
out/test/** | ||
src/** | ||
.gitignore | ||
vsc-extension-quickstart.md | ||
**/tsconfig.json | ||
**/tslint.json | ||
**/*.map | ||
**/*.ts | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Change Log | ||
|
||
## 0.1.0 | ||
|
||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
English | [简体中文](https://github.com/ice-lab/iceworks/blob/master/extensions/iceworks-time-steward/README.zh-CN.md) | ||
|
||
# Iceworks Time Steward(Beta) | ||
|
||
[![Version for VS Code Extension](https://vsmarketplacebadge.apphb.com/version-short/iceworks-team.iceworks-time-steward.svg?logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks-time-steward) | ||
[![Installs](https://vsmarketplacebadge.apphb.com/installs-short/iceworks-team.iceworks-time-steward.svg)](https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks-time-steward) | ||
[![Rating](https://vsmarketplacebadge.apphb.com/rating-short/iceworks-team.iceworks-time-steward.svg)](https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks-time-steward) | ||
[![The MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT) | ||
|
||
Metrics, insights, and time tracking automatically generated from your programming activity. | ||
|
||
## Security and Privacy | ||
|
||
**We never access your code**: We do not process, send, or store your proprietary code. We only provide metrics about programming. Time Steward is an open source plugin, we make it easy to see the data we collect. | ||
|
||
**Your data is private**: We will never share your individually identifiable data with anyone. | ||
|
||
## Check Data | ||
|
||
This plugin is still in the internal testing stage, please contact the author to check the data. | ||
|
||
## More | ||
|
||
See the [Iceworks](https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks) to know more features. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
简体中文 | [English](https://github.com/ice-lab/iceworks/blob/master/extensions/iceworks-time-steward/README.md) | ||
|
||
# Iceworks 时间管家(Beta) | ||
|
||
[![Version for VS Code Extension](https://vsmarketplacebadge.apphb.com/version-short/iceworks-team.iceworks-time-steward.svg?logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks-time-steward) | ||
[![Installs](https://vsmarketplacebadge.apphb.com/installs-short/iceworks-team.iceworks-time-steward.svg)](https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks-time-steward) | ||
[![Rating](https://vsmarketplacebadge.apphb.com/rating-short/iceworks-team.iceworks-time-steward.svg)](https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks-time-steward) | ||
[![The MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT) | ||
|
||
自动生成你的编程时间统计和效率度量,提供优化建议。 | ||
|
||
## 如何查看数据 | ||
|
||
插件当前仍在内测阶段,数据查看需联系作者。 | ||
|
||
## 安全和隐私 | ||
|
||
**我们从不访问您的代码**:我们不处理、发送或存储您的代码,我们只提供有关编程的度量。时间管家是开源的,你可以很容易地看到我们收集了什么数据。 | ||
|
||
**您的数据是私有的**:我们永远不会与任何人共享您的个人数据。 | ||
|
||
## 更多 | ||
|
||
访问 [Iceworks](https://marketplace.visualstudio.com/items?itemName=iceworks-team.iceworks) 获取更多功能。 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "iceworks-time-steward", | ||
"displayName": "Iceworks Time Steward(Beta)", | ||
"description": "Metrics, insights, and time tracking automatically generated from your programming activity.", | ||
"publisher": "iceworks-team", | ||
"version": "0.1.0", | ||
"engines": { | ||
"vscode": "^1.41.0" | ||
}, | ||
"categories": [ | ||
"Other" | ||
], | ||
"keywords": [ | ||
"Time", | ||
"Metrics", | ||
"Insights", | ||
"Tracker", | ||
"Time Tracking", | ||
"Timer" | ||
], | ||
"icon": "assets/logo.png", | ||
"activationEvents": [ | ||
"*" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/ice-lab/iceworks.git" | ||
}, | ||
"main": "./build/extension.js", | ||
"scripts": { | ||
"vscode:prepublish": "rm -rf build && webpack --mode production", | ||
"webpack": "webpack --mode development", | ||
"webpack-dev": "webpack --mode development --watch", | ||
"compile": "tsc -p ./tsconfig.json" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^12.11.7", | ||
"@types/vscode": "^1.41.0", | ||
"@types/request": "^2.48.5", | ||
"ts-loader": "^8.0.3", | ||
"typescript": "^3.6.4", | ||
"webpack": "^4.44.1", | ||
"webpack-cli": "^3.3.12" | ||
}, | ||
"dependencies": { | ||
"@iceworks/common-service": "^0.1.14", | ||
"@iceworks/recorder": "^0.1.1" | ||
}, | ||
"homepage": "https://github.com/ice-lab/iceworks/blob/master/extensions/iceworks-time-steward/README.md", | ||
"bugs": { | ||
"url": "https://github.com/ice-lab/iceworks/issues", | ||
"email": "iceworksteam@163.com" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as vscode from 'vscode'; | ||
import { getUserInfo, checkIsAliInternal } from '@iceworks/common-service'; | ||
import { Timer } from './timer'; | ||
|
||
let timer: Timer; | ||
|
||
export async function activate() { | ||
console.info('start timer'); | ||
let user = { name: vscode.env.machineId }; | ||
|
||
const isAliInternal = await checkIsAliInternal(); | ||
if (isAliInternal) { | ||
user = await getUserInfo(); | ||
} | ||
|
||
timer = new Timer(user); | ||
timer.initialize(); | ||
} | ||
|
||
export function deactivate() { | ||
timer.dispose(); | ||
console.info('timer has been disabled!'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import * as vscode from 'vscode'; | ||
import * as fs from 'fs'; | ||
import { Recorder } from '@iceworks/recorder'; | ||
import { IPackageJson } from './typings/package'; | ||
|
||
// eslint-disable-next-line | ||
const { name, version } = require('../package.json'); | ||
const recorder = new Recorder(name, version); | ||
|
||
export class Timer { | ||
private disposable: vscode.Disposable; | ||
|
||
private lastFile: string = ''; | ||
|
||
private lastHeartbeat: number = 0; | ||
|
||
private user; | ||
|
||
constructor(user) { | ||
this.user = user; | ||
} | ||
|
||
public initialize(): void { | ||
this.setupEventListeners(); | ||
} | ||
|
||
private setupEventListeners(): void { | ||
// subscribe to selection change and editor activation events | ||
const subscriptions: vscode.Disposable[] = []; | ||
|
||
// 监听光标位置变化 | ||
vscode.window.onDidChangeTextEditorSelection(this.onChange, this, subscriptions); | ||
// 监听左侧文件树当前激活的文件变化 | ||
vscode.window.onDidChangeActiveTextEditor(this.onChange, this, subscriptions); | ||
// 监听保存事件 | ||
vscode.workspace.onDidSaveTextDocument(this.onSave, this, subscriptions); | ||
// 监听编辑器失去焦点的变化情况 | ||
vscode.window.onDidChangeWindowState(this.onFocus, this, subscriptions); | ||
|
||
// create a combined disposable from both event subscriptions | ||
this.disposable = vscode.Disposable.from(...subscriptions); | ||
} | ||
|
||
public dispose() { | ||
this.disposable.dispose(); | ||
} | ||
|
||
private onChange(): void { | ||
this.onEvent(false); | ||
} | ||
|
||
private onSave(): void { | ||
this.onEvent(true); | ||
} | ||
|
||
private onFocus(event: { focused: boolean }): void { | ||
if (!event.focused) { | ||
this.onEvent(true); | ||
this.lastHeartbeat = 0; | ||
} | ||
} | ||
|
||
private onEvent(isWrite: boolean): void { | ||
const editor = vscode.window.activeTextEditor; | ||
if (editor) { | ||
const doc = editor.document; | ||
if (doc) { | ||
const file: string = doc.fileName; | ||
if (file) { | ||
const time: number = Date.now(); | ||
const enoughTimePassed = this.enoughTimePassed(time); | ||
console.info(`isWrite:${isWrite}; enoughTimePassed: ${enoughTimePassed}; lastFile: ${this.lastFile}`); | ||
/** | ||
* 发送规则: | ||
* 1. 保存时必然发送 | ||
* 2. 切换文件时必然发送 | ||
* 3. 在同一个文件里面每隔2分钟发送一次 | ||
*/ | ||
if (isWrite || enoughTimePassed || this.lastFile !== file) { | ||
const project = this.getProjectName(file); | ||
const subTime = time - this.lastHeartbeat; | ||
const { name } = this.user; | ||
if (this.lastHeartbeat !== 0) { | ||
recorder.record({ | ||
module: 'main', | ||
action: 'tracking', | ||
data: { | ||
user: name, | ||
timestamp: subTime, | ||
project, | ||
}, | ||
}); | ||
} | ||
|
||
this.lastFile = file; | ||
this.lastHeartbeat = time; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private enoughTimePassed(time: number): boolean { | ||
return this.lastHeartbeat + 120000 < time; | ||
} | ||
|
||
private getProjectName(file: string): string { | ||
const uri = vscode.Uri.file(file); | ||
const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri); | ||
if (workspaceFolder) { | ||
try { | ||
const packageJsonResultObj: IPackageJson = JSON.parse( | ||
fs.readFileSync(`${workspaceFolder.uri.path}/package.json`, 'utf-8') | ||
); | ||
return packageJsonResultObj.name; | ||
} catch (e) { | ||
console.error(e.message); | ||
} | ||
return workspaceFolder.name; | ||
} | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface IPackageJson { | ||
name: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es2019", | ||
"lib": ["ES2019"], | ||
"sourceMap": true, | ||
"strict": true /* enable all strict type-checking options */ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es6", | ||
"outDir": "out", | ||
"moduleResolution": "node", | ||
"lib": ["es2018"], | ||
"sourceMap": true, | ||
"rootDir": ".", | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"strict": true, | ||
"importHelpers": true, | ||
"removeComments": true, | ||
"noImplicitAny": false, | ||
"strictPropertyInitialization": false | ||
}, | ||
"exclude": ["node_modules"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const path = require('path'); | ||
|
||
const tsConfigPath = path.join(__dirname, 'tsconfig.json'); | ||
|
||
const config = { | ||
target: 'node', | ||
entry: './src/index.ts', | ||
output: { | ||
path: path.resolve(__dirname, 'build'), | ||
filename: 'extension.js', | ||
libraryTarget: 'commonjs2', | ||
devtoolModuleFilenameTemplate: '../[resource-path]', | ||
}, | ||
externals: { | ||
vscode: 'commonjs vscode', | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.js'], | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.ts$/, | ||
use: [ | ||
{ | ||
loader: 'ts-loader', | ||
options: { | ||
transpileOnly: true, | ||
configFile: tsConfigPath, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
module.exports = (env, argv) => { | ||
if (argv.mode === 'development') { | ||
config.devtool = 'source-map'; | ||
} | ||
|
||
return config; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.