AlexBlade / vscode-time-tracker

The time tracking addon for Visual Studio Code
32 stars 6 forks source link

What happens in shared repos ? #11

Open plagasul opened 1 year ago

plagasul commented 1 year ago

Hello!

This seems like the simplest, most spot-on time tracking tool I found on the vscode market! Thanks for the effort.

But what happens with .timetracking file if more than one user is using this tool and pushing ?

The extension does not seem to add username to the .timetracking file.

Thank you!

AlexBlade commented 1 year ago

Hi! Yeah, at the moment the extension is not taking into account a username. I promise to solve the issue but right now I have no time at all. I guess I'll be back to continue maintain the extension in a month. Thanks for your interest and please accept my apologize for delay.

plagasul commented 1 year ago

Please, no need to apologize. I appreciate your contribution.

My knowledge of TS (and OOP, aand vscode extensions) is limited (to say the least), but I may attempt to submit a PR.

As a workaround we are adding .timetracker to .gitignore, and using it locally, each of us.

Thank you very much.

plagasul commented 1 year ago

Actually, perhaps you can give me a headstart.

I can see that the json is constructed in TrackedData.ts.

I see that the json has this structure:

{
    "total": 44,
    "sessions": [
        {
            "begin": "2023-03-01T13:39:43+01:00",
            "end": "2023-03-01T13:40:20+01:00",
            "duration": 37
        },
        {
            "begin": "2023-03-01T13:41:22+01:00",
            "end": "2023-03-01T13:41:29+01:00",
            "duration": 7
        }
    ]
}

Assuming we can obtain a username, the json could have for example, this structure:

{
    "username": 
        {
            "total": 44,
            "sessions": [
                {
                    "begin": "2023-03-01T13:39:43+01:00",
                    "end": "2023-03-01T13:40:20+01:00",
                    "duration": 37
                },
                {
                    "begin": "2023-03-01T13:41:22+01:00",
                    "end": "2023-03-01T13:41:29+01:00",
                    "duration": 7
                }
            ]
        }

}

TrackedData could have a this._user property, then:

in `TrackedData.load()`, we could 
  loop the stringified json properties
    check the actual username against stored usernames
      If a stored username matches actual username
        this._sessions = data.username.sessions etc
      if a stored username does NOT match actual username
        no change

in `TrackedData.save()`, we could
  modify the json structure to include the user as property of the main object
  write totaltime and sessions below this user

This would allow to add a username BUT it would overwrite the whole file, and the other usernames.

We should overwrite only our matching username object OR create a new username object pair if the username is not there.

What do you think ?

AlexBlade commented 1 year ago

Yeah, Your idea is very good except one small problem. There is no username when user didn't initialize git-repo. But I guess it is possible to use something default, just 'default-user' for example. Anyway. it is good idea and I will try to implement it when be back to the project.

jamesbradleym commented 5 months ago

@AlexBlade You could use:

import os from 'os';
const userInfo = os.userInfo();

Foregoing the reliance on a github user?