From 64f0f5c2fe8ca7ae3d55d5ee6fc441d77b657139 Mon Sep 17 00:00:00 2001 From: smirko-dev Date: Wed, 18 Nov 2020 18:08:40 +0100 Subject: [PATCH 1/8] Added user settings --- README.md | 4 +-- app/index.js | 55 +++++++++++++++++++++++++++++++++++++----- companion/index.js | 13 ++++++++++ package.json | 2 +- resources/calories.png | 3 +++ resources/distance.png | 3 +++ resources/stairs.png | 3 +++ settings/index.jsx | 21 ++++++++++++++++ 8 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 resources/calories.png create mode 100644 resources/distance.png create mode 100644 resources/stairs.png create mode 100644 settings/index.jsx diff --git a/README.md b/README.md index 2299b13..ddc220f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![](https://img.shields.io/badge/Fitbit%20App%20Gallery-%2300B0B9?style=flat&logo=fitbit&logoColor=white)](https://gallery.fitbit.com/details/ae441b73-2660-407f-b796-a98d1d0583a0) ![languages](https://img.shields.io/badge/languages-JavaScript%20|%20CSS-blue) ![platform](https://img.shields.io/badge/platforms-Ionic%20|%20Versa%20|%20Versa%202%20|%20Versa%20Lite-silver) -[![version](https://img.shields.io/badge/version-%201.3.0-green)](https://github.com/smirko-dev/fitbit-clockface/releases) +[![version](https://img.shields.io/badge/version-%201.4.0-green)](https://github.com/smirko-dev/fitbit-clockface/releases) [![](https://img.shields.io/github/license/smirko-dev/fitbit-clockface.svg)](https://github.com/smirko-dev/fitbit-clockface/blob/master/LICENSE) [![FitbitBuild Actions Status](https://github.com/smirko-dev/fitbit-clockface/workflows/FitbitBuild/badge.svg)](https://github.com/smirko-dev/fitbit-clockface/actions) [![CodeQL Actions Status](https://github.com/smirko-dev/fitbit-clockface/workflows/CodeQL/badge.svg)](https://github.com/smirko-dev/fitbit-clockface/actions) @@ -16,7 +16,7 @@ It comes with - languages: de-DE, en-EN - battery icon with status in percentage - next calendar event of the current day -- step count in case of no events +- user activity in case of no events Find the latest published version in the [Fitbit gallery](https://gallery.fitbit.com/details/ae441b73-2660-407f-b796-a98d1d0583a0). diff --git a/app/index.js b/app/index.js index d9a187e..6a55de0 100644 --- a/app/index.js +++ b/app/index.js @@ -8,6 +8,7 @@ import { me as device } from "device"; import * as util from "../common/utils"; import * as appointment from "./appointment"; import * as clock from "./clock"; +import * as messaging from "messaging"; import { fromEpochSec, timeString } from "../common/utils"; // Get a handle on the elements @@ -21,6 +22,32 @@ const batteryLabel = document.getElementById("batteryLabel"); const activityIcon = document.getElementById("activityIcon"); const activityLabel = document.getElementById("activityLabel"); +const ActivitySelection = { + DIST: 'distance', + STAIRS: 'stairs', + CAL: 'calories', + STEPS: 'steps' +} + +let activitySelection = ActivitySelection.STEPS; + +// Update app settings +messaging.peerSocket.onmessage = (evt) => { + if (evt.data === "distance") { + activitySelection = ActivitySelection.DIST; + } + else if (evt.data === "stairs") { + activitySelection = ActivitySelection.STAIRS; + } + else if (evt.data === "calories") { + activitySelection = ActivitySelection.CAL; + } + else { + activitySelection = ActivitySelection.STEPS; + } + renderAppointment(); +} + clock.initialize("minutes", data => { // Update elements with each tick hourLabel.text = data.hours; @@ -42,7 +69,7 @@ appointment.initialize(() => { }); display.addEventListener("change", () => { - // Update appointment on display on + // Update appointment and battery on display on if (display.on) { renderAppointment(); renderBattery(); @@ -58,19 +85,35 @@ function renderAppointment() { hideActivity(); } else { - appointmentsLabel.text = "" + appointmentsLabel.text = ""; renderActivity(); } } function hideActivity() { - activityIcon.image = "" - activityLabel.text = "" + activityIcon.image = ""; + activityLabel.text = ""; } function renderActivity() { - activityIcon.image = "shoe-print.png" - activityLabel.text = today.adjusted.steps + switch (activitySelection) { + case ActivitySelection.DIST: + activityIcon.image = "distance.png"; + activityLabel.text = today.adjusted.distance; + break; + case ActivitySelection.STAIRS: + activityIcon.image = "stairs.png"; + activityLabel.text = today.adjusted.elevationGain; + break; + case ActivitySelection.CAL: + activityIcon.image = "calories.png"; + activityLabel.text = today.adjusted.calories; + break; + default: + activityIcon.image = "shoe-print.png"; + activityLabel.text = today.adjusted.steps; + break; + } } function renderBattery() { diff --git a/companion/index.js b/companion/index.js index a3c4f79..1e7abdc 100644 --- a/companion/index.js +++ b/companion/index.js @@ -6,6 +6,19 @@ import { outbox } from "file-transfer"; import { toEpochSec } from "../common/utils"; import { dataFile, millisecondsPerMinute } from "../common/constants"; +import { settingsStorage } from "settings"; +import * as messaging from "messaging"; + +// Update user settings +settingsStorage.onchange = function(evt) { + if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) { + if (evt.key === "activity") { + let data = JSON.parse(evt.newValue); + messaging.peerSocket.send(data["values"][0].value); + } + } +} + companion.wakeInterval = 15 * millisecondsPerMinute; companion.addEventListener("wakeinterval", refreshEvents); diff --git a/package.json b/package.json index 2181b6b..ee6ac07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "compactclock", - "version": "1.3.0", + "version": "1.4.0", "license": "MIT", "devDependencies": { "@fitbit/sdk": "~4.2.0", diff --git a/resources/calories.png b/resources/calories.png new file mode 100644 index 0000000..43286f3 --- /dev/null +++ b/resources/calories.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39dfa8af07eb9e0f38a41239aef84be9d1daa7001c73a5c684fc7d140fe47f90 +size 8830 diff --git a/resources/distance.png b/resources/distance.png new file mode 100644 index 0000000..54d1fab --- /dev/null +++ b/resources/distance.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:85165705ed7d0ff229f6f2baa4abb13db149349c5b6cce6c8390d7cbde7ced4d +size 8580 diff --git a/resources/stairs.png b/resources/stairs.png new file mode 100644 index 0000000..c701950 --- /dev/null +++ b/resources/stairs.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b06d3a312482dc988358766ac5b80a222b9055188a2328b3d684af5ff65e527d +size 6189 diff --git a/settings/index.jsx b/settings/index.jsx new file mode 100644 index 0000000..f3d90c4 --- /dev/null +++ b/settings/index.jsx @@ -0,0 +1,21 @@ + +function settingsFunc(props){ + return ( + +
+
From fce846380a476a1cbac96a9e208f1556f6137a14 Mon Sep 17 00:00:00 2001 From: smirko-dev Date: Fri, 20 Nov 2020 16:00:35 +0100 Subject: [PATCH 4/8] Updated languages --- app/index.js | 2 +- settings/i18n/en-US.po | 2 +- settings/i18n/ru-RU.po | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/index.js b/app/index.js index 6a55de0..d4e4298 100644 --- a/app/index.js +++ b/app/index.js @@ -11,7 +11,7 @@ import * as clock from "./clock"; import * as messaging from "messaging"; import { fromEpochSec, timeString } from "../common/utils"; -// Get a handle on the elements +// Get a handle on the and elements const hourLabel = document.getElementById("hourLabel"); const minuteLabel = document.getElementById("minuteLabel"); const dateLabel = document.getElementById("dateLabel"); diff --git a/settings/i18n/en-US.po b/settings/i18n/en-US.po index e7a5d12..2e0e706 100644 --- a/settings/i18n/en-US.po +++ b/settings/i18n/en-US.po @@ -1,6 +1,6 @@ msgid "title" -msgstr "Activitiy info" +msgstr "Activity info" msgid "steps" msgstr "Steps" diff --git a/settings/i18n/ru-RU.po b/settings/i18n/ru-RU.po index e7a5d12..5dbc05d 100644 --- a/settings/i18n/ru-RU.po +++ b/settings/i18n/ru-RU.po @@ -1,15 +1,15 @@ msgid "title" -msgstr "Activitiy info" +msgstr "Инфо о деятельности" msgid "steps" -msgstr "Steps" +msgstr "Шаги" msgid "cal" -msgstr "Calories" +msgstr "Калорий" msgid "dist" -msgstr "Distance" +msgstr "Расстояние" msgid "floors" -msgstr "Floors" +msgstr "Полы" From f1e7dd0d1c6e8e1cab3d625d6ab90de365cd5809 Mon Sep 17 00:00:00 2001 From: smirko-dev Date: Fri, 20 Nov 2020 16:07:46 +0100 Subject: [PATCH 5/8] Updated battery icons --- resources/battery-10.png | 4 ++-- resources/battery-100.png | 4 ++-- resources/battery-20.png | 4 ++-- resources/battery-30.png | 4 ++-- resources/battery-40.png | 4 ++-- resources/battery-50.png | 4 ++-- resources/battery-60.png | 4 ++-- resources/battery-70.png | 4 ++-- resources/battery-80.png | 4 ++-- resources/battery-90.png | 4 ++-- resources/battery-alert.png | 4 ++-- resources/index.gui | 2 +- resources/styles.css | 4 ++++ 13 files changed, 27 insertions(+), 23 deletions(-) diff --git a/resources/battery-10.png b/resources/battery-10.png index e8f7f15..3406535 100644 --- a/resources/battery-10.png +++ b/resources/battery-10.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3d6b02b3016bed68b9b1a5df9d0ed03c5387e95da46befc615383cd266e43e99 -size 406 +oid sha256:df878505e864b1401548a609e55bcd0b5af9e2b3b968da69c2203cbb842134f9 +size 5756 diff --git a/resources/battery-100.png b/resources/battery-100.png index 3b7a29b..d8b0407 100644 --- a/resources/battery-100.png +++ b/resources/battery-100.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:159a3c75899f5307b3f3a2138dcf782b65d6904aa398a26aa4d1f5323f399149 -size 390 +oid sha256:5edaf5cf8a7c6a374ba89113f83594765bb47a262696173c7a90831d087f1ef8 +size 5586 diff --git a/resources/battery-20.png b/resources/battery-20.png index 657ea77..a7eb7b9 100644 --- a/resources/battery-20.png +++ b/resources/battery-20.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0a2b3923092ed7919150ab4429922bbc14b5ac0ea7e12e329185c7ad68d7ed62 -size 406 +oid sha256:df935af93b734f56b0fe3042c7122d6f261ee3338e264b8047adda154e916e39 +size 5874 diff --git a/resources/battery-30.png b/resources/battery-30.png index ee208f0..9bc2a89 100644 --- a/resources/battery-30.png +++ b/resources/battery-30.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bf86cb42d62063ed84c47e94712b6dc4540c8fa98d38a2ed36f734129251496a -size 407 +oid sha256:252c7e06fd9ee04c371ef81849222842ef47ae50b673b0b3b122e594225eea13 +size 5734 diff --git a/resources/battery-40.png b/resources/battery-40.png index c5777e7..fb79523 100644 --- a/resources/battery-40.png +++ b/resources/battery-40.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:333f8c49f9c6f21d0406b905e8f652fe3f608468bf1d0329b67917182e85a17b -size 405 +oid sha256:66e04d7c7051c242ca5d1c56d7fbb1826502273be6ee647e95fff1193de10800 +size 5839 diff --git a/resources/battery-50.png b/resources/battery-50.png index ab46b07..3755950 100644 --- a/resources/battery-50.png +++ b/resources/battery-50.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cc8a4a9ee5bff99faae9f1a08c783e54a5edb89989bfb4447db29b29d775252b -size 405 +oid sha256:479b1671484a5fa090aad4e37718d015bc0299103b2a09ddcc3a8ffe4a299e74 +size 5887 diff --git a/resources/battery-60.png b/resources/battery-60.png index fab9447..818a11d 100644 --- a/resources/battery-60.png +++ b/resources/battery-60.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:dd32bef6c886784833bd06af710ded1a7874aa4bd4b1965fdd20eaf83a8edd80 -size 406 +oid sha256:9422ebe0ed813239a3be7aa22d321ee9ff55588f7f3449fe734e91eb46b6f3af +size 5713 diff --git a/resources/battery-70.png b/resources/battery-70.png index a450de8..4057287 100644 --- a/resources/battery-70.png +++ b/resources/battery-70.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b026894674cc403c539d4b911b28156bd985cd91a25f0530c9ad703b6c8eddc1 -size 405 +oid sha256:76b9ed46bcfead1c5463273167d20e294a2fd7032146ae3deb64b16aa38fd0ef +size 5867 diff --git a/resources/battery-80.png b/resources/battery-80.png index 7132474..b005246 100644 --- a/resources/battery-80.png +++ b/resources/battery-80.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e97e0bbb5ad81abcbacdfa67efa887ad5cdd932353a40d9678bc61ad9637fde1 -size 405 +oid sha256:a67068a7249f7f778b54211139717288da68490e89eaea4303df330dc2126fce +size 5694 diff --git a/resources/battery-90.png b/resources/battery-90.png index 842e1c6..a99e0f9 100644 --- a/resources/battery-90.png +++ b/resources/battery-90.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5d0095b3f4a77d5d9738980e9939feaa2337cfb9eec8cbb6c30433bf2a01e4b0 -size 405 +oid sha256:646eb5322342c9e90fc6f1dc187e528cab64bee576743d8ae9b582fe0771e50c +size 5812 diff --git a/resources/battery-alert.png b/resources/battery-alert.png index 7e6d683..2afe78c 100644 --- a/resources/battery-alert.png +++ b/resources/battery-alert.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:48697103b61b3ca7458d15e574ed4c44ca34e543620e05d88c8943317ca2977e -size 404 +oid sha256:ad7ad7a19cd82c76c60f73b809de729778a9a8ea80f978ed28608183f871cbc0 +size 5906 diff --git a/resources/index.gui b/resources/index.gui index f84ee13..b7123a0 100644 --- a/resources/index.gui +++ b/resources/index.gui @@ -3,7 +3,7 @@