Skip to content

Commit

Permalink
fix sleep time display
Browse files Browse the repository at this point in the history
  • Loading branch information
novvember committed Jul 7, 2024
1 parent 188c743 commit a523a96
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions nothing-elaborate/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"appName": "Elaborate",
"appType": "watchface",
"version": {
"code": 2,
"name": "1.0.1"
"code": 3,
"name": "1.0.2"
},
"icon": "icon.png",
"vender": "novvember",
Expand Down
6 changes: 5 additions & 1 deletion nothing-elaborate/utils/getSleepTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ function getWakeTime(sleepSensor) {
.reduce((sum, { start, stop }) => sum + stop - start + 1, 0);
}

export function getSleepTimeTotal(sleepSensor) {
return sleepSensor.getTotalTime();
}

export function getSleepTimeString(sleepSensor) {
const totalTime = sleepSensor.getTotalTime();
const totalTime = getSleepTimeTotal(sleepSensor);

if (totalTime) {
return formatTime(totalTime - getWakeTime(sleepSensor));
Expand Down
20 changes: 16 additions & 4 deletions nothing-elaborate/watchface/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getSleepTimeString } from '../utils/getSleepTime';
import { getSleepTimeString, getSleepTimeTotal } from '../utils/getSleepTime';
import {
BATTERY,
COLORS,
Expand Down Expand Up @@ -75,14 +75,26 @@ WatchFace({
if (hmSetting.getScreenType() == hmSetting.screen_type.WATCHFACE) {
const sleepTime = getSleepTimeString(sleepSensor);
const sleepString = `${sleepTime}\n${SLEEP.postfix}`;
const { startTime, endTime } = sleepSensor.getBasicInfo();
const totalSleepTimeHours = getSleepTimeTotal(sleepSensor) / 60;
let { startTime, endTime } = sleepSensor.getBasicInfo();

let angleStart = getAngleFromTime(startTime);
let angleEnd = getAngleFromTime(endTime);

if (angleEnd < angleStart) {
angleEnd += 360;
}

if (totalSleepTimeHours >= 12) {
angleEnd += 360;
}

if (sleepTime) {
textWidget.setProperty(hmUI.prop.TEXT, sleepString);
arcWidget.setProperty(hmUI.prop.MORE, {
...SLEEP_ARC_PROPS,
start_angle: getAngleFromTime(startTime),
end_angle: getAngleFromTime(endTime),
start_angle: angleStart,
end_angle: angleEnd,
});
} else {
textWidget.setProperty(hmUI.prop.TEXT, '');
Expand Down

0 comments on commit a523a96

Please sign in to comment.