Skip to content

Commit 5ac7edf

Browse files
committed
fix(heartbeat): streamline total seconds calculation and improve status bar updates for daily summaries
1 parent 58b1205 commit 5ac7edf

1 file changed

Lines changed: 3 additions & 17 deletions

File tree

src/heartbeat.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,9 @@ export class HeartbeatManager {
251251
if (!apiKey || !baseUrl) {
252252
return;
253253
}
254-
255254
try {
256255
const url = new URL("/api/external/stats", baseUrl);
257256
url.searchParams.append("timeRange", "today");
258-
259257
const now = new Date();
260258
const timezoneOffsetMinutes = now.getTimezoneOffset();
261259
const timezoneOffsetSeconds = timezoneOffsetMinutes * 60;
@@ -264,7 +262,6 @@ export class HeartbeatManager {
264262
timezoneOffsetSeconds.toString()
265263
);
266264
url.searchParams.append("t", Date.now().toString());
267-
268265
const requestOptions = {
269266
hostname: url.hostname,
270267
port: url.port || (url.protocol === "https:" ? 443 : 80),
@@ -275,7 +272,6 @@ export class HeartbeatManager {
275272
},
276273
protocol: url.protocol,
277274
};
278-
279275
const apiResponse = await this.makeRequest<{
280276
summaries: Array<{
281277
date: string;
@@ -288,33 +284,24 @@ export class HeartbeatManager {
288284
}>;
289285
timezone: string;
290286
}>(requestOptions);
291-
292287
this.setOnlineStatus(true);
293288
this.setApiKeyStatus(true);
294-
295289
if (
296290
apiResponse &&
297291
apiResponse.summaries &&
298292
apiResponse.summaries.length > 0
299293
) {
300294
const todaySummary = apiResponse.summaries[0];
301295
this.todayLocalTotalSeconds = todaySummary.totalSeconds;
302-
303-
const totalSeconds =
304-
this.todayLocalTotalSeconds + this.unsyncedLocalSeconds;
305-
306296
if (this.statusBar) {
307-
const hours = Math.floor(totalSeconds / 3600);
308-
const minutes = Math.floor((totalSeconds % 3600) / 60);
297+
const hours = Math.floor(this.todayLocalTotalSeconds / 3600);
298+
const minutes = Math.floor((this.todayLocalTotalSeconds % 3600) / 60);
309299
this.statusBar.updateTime(hours, minutes);
310300
}
311301
this.unsyncedLocalSeconds = 0;
312302
} else {
313-
const totalSeconds = this.unsyncedLocalSeconds;
314303
if (this.statusBar) {
315-
const hours = Math.floor(totalSeconds / 3600);
316-
const minutes = Math.floor((totalSeconds % 3600) / 60);
317-
this.statusBar.updateTime(hours, minutes);
304+
this.statusBar.updateTime(0, 0);
318305
}
319306
}
320307
} catch (error) {
@@ -325,7 +312,6 @@ export class HeartbeatManager {
325312
this.setOnlineStatus(false);
326313
log(`Error fetching daily summary: ${error}`);
327314
}
328-
329315
if (
330316
this.statusBar &&
331317
(this.todayLocalTotalSeconds > 0 || this.unsyncedLocalSeconds > 0)

0 commit comments

Comments
 (0)