Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 39 additions & 31 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,38 +91,46 @@ var client = {
if (this.testing === null)
return;

var payload = {
"data": data,
"duration": 0.0,
"timestamp": timestamp.toISOString(),
};

var attempt = () => {
return this.awc.heartbeat(this.getBucketId(), pulsetime, payload);
};

retry(attempt, { retries: 3 }).then(
(res) => {
if (!client.lastSyncSuccess) {
emitNotification(
"Now connected again",
"Connection to ActivityWatch server established again"
);
}
client.lastSyncSuccess = true;
client.updateSyncStatus();
}, (err) => {
if(client.lastSyncSuccess) {
emitNotification(
"Unable to send event to server",
"Please ensure that ActivityWatch is running"
);
}
client.lastSyncSuccess = false;
client.updateSyncStatus();
logHttpError(err);
// First get tags if they exist
chrome.storage.local.get(['tags'], (result) => {
var payload = {
"data": data,
"duration": 0.0,
"timestamp": timestamp.toISOString(),
};

// Only add tags if they exist
if (result.tags) {
payload.data.tags = result.tags;
}
);

var attempt = () => {
return client.awc.heartbeat(client.getBucketId(), pulsetime, payload);
};

retry(attempt, { retries: 3 }).then(
(res) => {
if (!client.lastSyncSuccess) {
emitNotification(
"Now connected again",
"Connection to ActivityWatch server established again"
);
}
client.lastSyncSuccess = true;
client.updateSyncStatus();
}, (err) => {
if(client.lastSyncSuccess) {
emitNotification(
"Unable to send event to server",
"Please ensure that ActivityWatch is running"
);
}
client.lastSyncSuccess = false;
client.updateSyncStatus();
logHttpError(err);
}
);
});
}
};

Expand Down
7 changes: 7 additions & 0 deletions static/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
<!-- Filled by JS -->
</td>
</tr>

<tr align="right">
<th>Tags:</th>
<td>
<input type="text" id="status-tags-input" placeholder="work, study, etc">
</td>
</tr>
</table>

<hr>
Expand Down
12 changes: 11 additions & 1 deletion static/popup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

function renderStatus() {
chrome.storage.local.get(["lastSync", "lastSyncSuccess", "testing", "baseURL", "enabled"], function(obj) {
chrome.storage.local.get(["lastSync", "lastSyncSuccess", "testing", "baseURL", "enabled", "tags"], function(obj) {
// Enabled checkbox
let enabledCheckbox = document.getElementById('status-enabled-checkbox');
enabledCheckbox.checked = obj.enabled;
Expand Down Expand Up @@ -39,6 +39,10 @@ function renderStatus() {

// Set webUI button link
document.getElementById('webui-link').href = obj.baseURL;

// Tags
let tagsInput = document.getElementById('status-tags-input');
tagsInput.value = obj.tags || '';
});
}

Expand All @@ -53,6 +57,12 @@ function domListeners() {
const url = chrome.runtime.getURL("../static/consent.html");
chrome.windows.create({ url, type: "popup", height: 550, width: 416, });
});

let tagsInput = document.getElementById('status-tags-input');
tagsInput.addEventListener("change", (event) => {
const tags = event.target.value.split(',').map(tag => tag.trim()).filter(tag => tag);
chrome.storage.local.set({ tags: event.target.value });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Store the processed array of tags instead of the raw input value to ensure consistency and avoid storing unnecessary spaces.

Suggested change
chrome.storage.local.set({ tags: event.target.value });
chrome.storage.local.set({ tags: tags });

});
}

document.addEventListener('DOMContentLoaded', function() {
Expand Down