Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Times shows as "started" in other tabs after you have stopped it #4865

Open
3 tasks done
fulldecent opened this issue May 17, 2024 · 3 comments
Open
3 tasks done

Times shows as "started" in other tabs after you have stopped it #4865

fulldecent opened this issue May 17, 2024 · 3 comments

Comments

@fulldecent
Copy link

Describe the issue

Test case:

  1. Open your instance
  2. Start time tracking using button on header of screen
  3. Open a second tab of your instance
  4. Stop time tracking on the second tab
  5. Go back to the first tab

Expected:

The time tracking widget shows that time is not tracking.

Actual:

The time tracking widget shows that time is still tracking.

Proposed solution:

A local storage, or possibly session storage, is a way for the application to communicate with itself between different tabs. This can be polled once per second without any performance impact.

I already tried

Kimai version

2

How do you run Kimai?

KIMAI CLOUD

Which PHP version are you using?

8.1

Logfile

No response

Screenshots

Screenshot 2024-05-17 at 16 53 00

@kevinpapst
Copy link
Member

This can be polled once per second without any performance impact.

Brave! Now tell me how to achieve that with thousands of open tabs/sessions.

Closing, duplicate of #3620

@kevinpapst kevinpapst closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
@fulldecent
Copy link
Author

This is NOT a duplicate of #3620. That addresses when you have one session open on one device and the same customer logged in on another device.

Instead, this issue addresses when the same person has two tabs open and logged in on the same browser.


I assume your question is being facetious. But I'll provide an answer.

  1. First, buy a Mac Studio configured with 192GB of RAM.
  2. Update Chrome source code to allow you to open 2,000 tabs on your computer.
  3. Open 2,000 tabs of the Kimai website on your computer in the same browser.

The above is the facetious part. Now is the important part:

  1. On one of the tabs start timing.
  2. When start timing, set a local storage with localStorage.setItem('timerstatus-user1234', 'last-updated-198342589724597-status-on'); where that number is the unix time that tracking started.
  3. In every other browser tab, query once per second with localStorage.getItem('timerstatus-user1234'). If during that query, the information in session storage is newer that the information currently in that tab (see timestamp), update the tab and set the favicon.

I think you can also do this for push notifications between tabs:

// Listen for storage changes
window.addEventListener('storage', function(event) {
    if (event.key === 'timerstatus-user1234') {
        console.log('New value: ', event.newValue);
    }
});

Please note that setting and getting this value causes zero network traffic to your server. And it does not leak any information during other page requests. It is NOT a cookie.

This approach above and/or BroadcastChannel is best practice and it is currently how Gmail and other web apps will manage communication between multiple tabs in the same browser window.

@kevinpapst
Copy link
Member

I assume your question is being facetious

No, I didn't see the localstorage part.
I was talking about thousands of users on different computers.
I just saw "poll every second" and was thinking "how in the world can should a server not be impacted by such a task"?

It is NOT a cookie.

That's patronising. Your communication is at the edge of being rude. Please try to work on that.

this issue addresses when the same person has two tabs open and logged in on the same browser

That only covers 80% of the use-cases, but that's likely enough...
Still many issues with this approach, eg.g using an app and a desktop browser in parallel.

I am just not sure if the idea is feasible. What if someone has two tabs open deliberately. Say, currently writing down some new tasks or updating customer data in a modal.
Not sure if I can simply change certain parts of the page without breaking the current situation.
But its a very simple and therefor good approach. I'll give it a try. Thanks for sharing 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants