Skip to content

Commit

Permalink
fix: get user info (#544)
Browse files Browse the repository at this point in the history
* fix: get user info

* chore: using en

* style: lint
  • Loading branch information
alvinhui authored Sep 15, 2020
1 parent bfda9bd commit 6abca6f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion extensions/iceworks-time-steward/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Iceworks Time Steward(Beta)",
"description": "Metrics, insights, and time tracking automatically generated from your programming activity.",
"publisher": "iceworks-team",
"version": "0.1.0",
"version": "0.1.1",
"engines": {
"vscode": "^1.41.0"
},
Expand Down
2 changes: 1 addition & 1 deletion extensions/iceworks-time-steward/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let timer: Timer;

export async function activate() {
console.info('start timer');
let user = { name: vscode.env.machineId };
let user = { empId: vscode.env.machineId, account: 'anonymous' };

const isAliInternal = await checkIsAliInternal();
if (isAliInternal) {
Expand Down
14 changes: 11 additions & 3 deletions extensions/iceworks-time-steward/src/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Timer {

private lastHeartbeat: number = 0;

private user;
private user: { empId: string; account: string };

constructor(user) {
this.user = user;
Expand Down Expand Up @@ -79,15 +79,17 @@ export class Timer {
if (isWrite || enoughTimePassed || this.lastFile !== file) {
const project = this.getProjectName(file);
const subTime = time - this.lastHeartbeat;
const { name } = this.user;
const { account, empId } = this.user;
if (this.lastHeartbeat !== 0) {
recorder.record({
module: 'main',
action: 'tracking',
data: {
user: name,
userName: account,
userId: empId,
timestamp: subTime,
project,
version,
},
});
}
Expand All @@ -104,6 +106,12 @@ export class Timer {
return this.lastHeartbeat + 120000 < time;
}

/**
* Priority:
* - TODO: Git's group/project
* - package.json's name
* - Folder name
*/
private getProjectName(file: string): string {
const uri = vscode.Uri.file(file);
const workspaceFolder = vscode.workspace.getWorkspaceFolder(uri);
Expand Down

0 comments on commit 6abca6f

Please sign in to comment.