diff --git a/app/appointment.js b/app/appointment.js index 9ea7b27..96c7871 100644 --- a/app/appointment.js +++ b/app/appointment.js @@ -4,8 +4,7 @@ import { readFileSync } from "fs"; import { dataFile, dataType } from "../common/constants"; import { toEpochSec } from "../common/utils"; -let data = {}; -let cb; +let data, cb; export function initialize(callback) { cb = callback; @@ -59,7 +58,7 @@ function loadData() { } function existsData() { - if (Object.keys(data).length === 0 && data.constructor === Object) { + if (data === undefined) { console.warn("Appointment: No data found."); return false; } diff --git a/build/app.fba b/build/app.fba deleted file mode 100644 index 301279a..0000000 Binary files a/build/app.fba and /dev/null differ diff --git a/common/utils.js b/common/utils.js index 519bf28..ad95201 100644 --- a/common/utils.js +++ b/common/utils.js @@ -38,26 +38,27 @@ export function timeUntil(date) { ); if (days > 0) { - return `in ${days} day${pluralize(days)}`; + return `in ${days} ${pluralize(days, "day")}`; } if (hours > 0) { - return `in ${hours}hr${pluralize(hours)}${ - hours < 3 && minutes > 0 ? ` ${minutes}min${pluralize(minutes)}` : "" + return `in ${hours}${pluralize(hours, "hr")}${ + hours < 3 && minutes > 0 ? ` ${minutes}${pluralize(minutes, "min")}` : "" }`; } if (minutes > 0) { - return `in ${minutes}min${pluralize(minutes)}`; + return `in ${minutes}${pluralize(minutes, "min")}`; } return "Now"; } /** - * Returns an `s` if the number is plural + * Pluralizes the units if required * @param {Number} number + * @param {String} unit */ -function pluralize(number) { - return number === 1 ? "" : "s"; +function pluralize(number, unit) { + return number === 1 ? unit : `${unit}s`; } diff --git a/companion/index.js b/companion/index.js index 39aaa21..d4383f3 100644 --- a/companion/index.js +++ b/companion/index.js @@ -12,8 +12,7 @@ companion.addEventListener("wakeinterval", refreshData); refreshData(); function refreshData() { - let dataCalendars = [], - dataEvents = []; + let dataEvents = []; calendars .searchSources() @@ -21,22 +20,12 @@ function refreshData() { return calendars.searchCalendars(); }) .then(results => { - results.forEach(calendar => { - // console.log( - // `> calendar: ${calendar.title} (${calendar.sourceId}/${calendar.id})` - // ); - dataCalendars.push(calendar); - }); - // Filter events to 48hr window - const start = new Date(); - const end = new Date(); - start.setHours(0, 0, 0, 0); - end.setHours(128, 59, 59, 999); - const eventsQuery = { - startDate: start, - endDate: end - }; + const startDate = new Date(); + const endDate = new Date(); + startDate.setHours(0, 0, 0, 0); + endDate.setHours(128, 59, 59, 999); + const eventsQuery = { startDate, endDate }; return calendars.searchEvents(eventsQuery); }) diff --git a/screenshot.png b/screenshot.png index bedb2e5..9c355dd 100644 Binary files a/screenshot.png and b/screenshot.png differ