activitywatch / aw-client-js Goto Github PK
View Code? Open in Web Editor NEWClient library for ActivityWatch in JavaScript
License: MIT License
Client library for ActivityWatch in JavaScript
License: MIT License
Similar to aw-client-python it would be nice to have pre-merge heartbeats supported in aw-client-js to improve performance.
It might possibly fix the following issue for aw-watcher-vscode: ActivityWatch/aw-watcher-vscode#12
I am not entirely sure how, but it seems to be possible for the axios res.data to be a string, despite the content-type being correctly set to json, causing the snippet below to error with TypeError: n.forEach is not a function
. This happens with both aw-server and aw-server-rust, and only in Firefox.
Lines 206 to 211 in 39868c7
Lines 99 to 103 in 39868c7
Just recently used your library for interacting with the Activity Watch client via JS I did notice that when I query the event count it does not correlate with the results I get back from fetching the events.
For both queries I used the same start and end time but the count and results do not line up. I used a limit of 100 and one of my buckets came back with a count of 389 but the records returned where only 97. So I checked the request and your source code noticed that for AWClient.countEvents()
you are passing the time params as "starttime" and "endtime" which are not the params stated in the docs, resulting in from what I can see it querying all the data in a bucket instead of scoping to the timestamps.
Query params for AWClient.countEvents()
should be start
and end
, not starttime
, endtime
when making the request.
Needed to fix ActivityWatch/aw-watcher-web#16
As far as I know, in the server heartbeats get merged together if they have the same data and are in the time span lastEventTime<->lastEvenTime+pulsetime. Therefore sending heartbeats can be redundant.
Currently we check for this in several watchers (here for aw-watcher-web and here for aw-watcher-vscode), so we don't send unnecessary heartbeats. But I think it would be better to check for this in aw-client.js.
On the one hand, this would ensure that server traffic is kept low and, on the other hand, we wouldn't have to recode it for every watcher.
Do you agree on this being useful or have something to add?
I'd really like to work with a typescript version of this, as it makes developing faster and less error prone (regarding to my one week experience with typescript ^_^).
As one can compile it to vanilla js, the only downside I see, is that the developers of aw-client.js should have a basic knowledge of how to use typescript. On the other hand, users of it could choose whether they want to use the typescript file, or the vanilla js one.
Example of this compiled output:
Therefore I'd like to have an aw-client.ts which gets compiled to the aw-client.js file.
Edit: I've made a quick transformation to typescript. Some params I didn't know the type of (See TODOs)
Axios also seem to support typescript (https://github.com/axios/axios/blob/master/index.d.ts)
Here is the draft: Quick draft of aw-client.ts
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.