diff --git a/src/client.js b/src/client.js index 3a1fd6d..a692f8c 100644 --- a/src/client.js +++ b/src/client.js @@ -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); + } + ); + }); } }; diff --git a/static/popup.html b/static/popup.html index be17372..4ff659d 100644 --- a/static/popup.html +++ b/static/popup.html @@ -57,6 +57,13 @@ + + + Tags: + + + +
diff --git a/static/popup.js b/static/popup.js index 19c5459..c1af326 100644 --- a/static/popup.js +++ b/static/popup.js @@ -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; @@ -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 || ''; }); } @@ -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 }); + }); } document.addEventListener('DOMContentLoaded', function() {