diff --git a/apps/bikespeedo/ChangeLog b/apps/bikespeedo/ChangeLog index 10752ee2b..b47f8cdc3 100644 --- a/apps/bikespeedo/ChangeLog +++ b/apps/bikespeedo/ChangeLog @@ -1,3 +1,4 @@ 0.01: New App! 0.02: Barometer altitude adjustment setting 0.03: Use default Bangle formatter for booleans +0.04: Add options for units in locale and recording GPS diff --git a/apps/bikespeedo/app.js b/apps/bikespeedo/app.js index a62a429e5..6f462a820 100644 --- a/apps/bikespeedo/app.js +++ b/apps/bikespeedo/app.js @@ -403,6 +403,8 @@ function onGPS(fix) { if ( sp < 10 ) sp = sp.toFixed(1); else sp = Math.round(sp); + if (isNaN(sp)) sp = '---'; + if (parseFloat(sp) > parseFloat(max.spd) && max.n > 15 ) max.spd = parseFloat(sp); // Altitude @@ -416,6 +418,12 @@ function onGPS(fix) { // Age of last fix (secs) age = Math.max(0,Math.round(getTime())-(lf.time.getTime()/1000)); + } else { + // populate spd_unit + if (cfg.spd == 0) { + m = require("locale").speed(0).match(/[0-9,\.]+(.*)/); + cfg.spd_unit = m[1]; + } } if ( cfg.modeA == 1 ) { @@ -465,7 +473,7 @@ function updateClock() { // Read settings. let cfg = require('Storage').readJSON('bikespeedo.json',1)||{}; -cfg.spd = 1; // Multiplier for speed unit conversions. 0 = use the locale values for speed +cfg.spd = !cfg.localeUnits; // Multiplier for speed unit conversions. 0 = use the locale values for speed cfg.spd_unit = 'km/h'; // Displayed speed unit cfg.alt = 1; // Multiplier for altitude unit conversions. (feet:'0.3048') cfg.alt_unit = 'm'; // Displayed altitude units ('feet') @@ -499,14 +507,6 @@ function onPressure(dat) { altiBaro = Number(dat.altitude.toFixed(0)) + Number(cfg.altDiff); } -Bangle.setBarometerPower(1); // needs some time... -g.clearRect(0,screenYstart,screenW,screenH); -onGPS(lf); -Bangle.setGPSPower(1); -Bangle.on('GPS', onGPS); -Bangle.on('pressure', onPressure); - -Bangle.setCompassPower(1); var CALIBDATA = require("Storage").readJSON("magnav.json",1)||null; if (!CALIBDATA) calibrateCompass = true; function Compass_tiltfixread(O,S){ @@ -544,11 +544,33 @@ function Compass_reading() { Compass_heading = Compass_newHeading(d,Compass_heading); hdngCompass = Compass_heading.toFixed(0); } -if (!calibrateCompass) setInterval(Compass_reading,200); -setButtons(); -if (emulator) setInterval(updateClock, 2000); -else setInterval(updateClock, 10000); +function start() { + Bangle.setBarometerPower(1); // needs some time... + g.clearRect(0,screenYstart,screenW,screenH); + onGPS(lf); + Bangle.setGPSPower(1); + Bangle.on('GPS', onGPS); + Bangle.on('pressure', onPressure); + + Bangle.setCompassPower(1); + if (!calibrateCompass) setInterval(Compass_reading,200); + + setButtons(); + if (emulator) setInterval(updateClock, 2000); + else setInterval(updateClock, 10000); + + Bangle.drawWidgets(); +} Bangle.loadWidgets(); -Bangle.drawWidgets(); +if (cfg.record && WIDGETS["recorder"]) { + WIDGETS["recorder"] + .setRecording(true) + .then(start); + + if (cfg.recordStopOnExit) + E.on('kill', () => WIDGETS["recorder"].setRecording(false)); +} else { + start(); +} diff --git a/apps/bikespeedo/metadata.json b/apps/bikespeedo/metadata.json index 80b91427c..ea74db9a1 100644 --- a/apps/bikespeedo/metadata.json +++ b/apps/bikespeedo/metadata.json @@ -2,7 +2,7 @@ "id": "bikespeedo", "name": "Bike Speedometer (beta)", "shortName": "Bike Speedometer", - "version": "0.03", + "version": "0.04", "description": "Shows GPS speed, GPS heading, Compass heading, GPS altitude and Barometer altitude from internal sources", "icon": "app.png", "screenshots": [{"url":"Screenshot.png"}], diff --git a/apps/bikespeedo/settings.js b/apps/bikespeedo/settings.js index f41524263..bb943c081 100644 --- a/apps/bikespeedo/settings.js +++ b/apps/bikespeedo/settings.js @@ -11,9 +11,34 @@ '< Back': back, '< Load Bike Speedometer': ()=>{load('bikespeedo.app.js');}, 'Barometer Altitude adjustment' : function() { E.showMenu(altdiffMenu); }, - 'Kalman Filters' : function() { E.showMenu(kalMenu); } + 'Kalman Filters' : function() { E.showMenu(kalMenu); }, + 'Speed units': { + value: !!settings.localeUnits, + format: b => b ? "Locale" : "km/h", + onchange: b => { + settings.localeUnits = b; + writeSettings(); + } + }, }; + if (global.WIDGETS && WIDGETS["recorder"]) { + appMenu[/*LANG*/"Record rides"] = { + value : !!settings.record, + onchange : v => { + settings.record = v; + writeSettings(); + } + }; + appMenu[/*LANG*/"Stop record on exit"] = { + value : !!settings.recordStopOnExit, + onchange : v => { + settings.recordStopOnExit = v; + writeSettings(); + } + }; + } + const altdiffMenu = { '': { 'title': 'Altitude adjustment' }, '< Back': function() { E.showMenu(appMenu); }, diff --git a/apps/calendar/ChangeLog b/apps/calendar/ChangeLog index 27e1e2517..c7902e263 100644 --- a/apps/calendar/ChangeLog +++ b/apps/calendar/ChangeLog @@ -13,3 +13,4 @@ 0.12: Mark dated events on a day 0.13: Switch to swipe left/right for month and up/down for year selection Display events for current month on touch +0.14: Add support for holidays diff --git a/apps/calendar/README.md b/apps/calendar/README.md index ec1c0c55a..5f90d0d52 100644 --- a/apps/calendar/README.md +++ b/apps/calendar/README.md @@ -10,6 +10,7 @@ Basic calendar - Swipe down (Bangle.js 2 only) to go to the next year - Touch to display events for current month - Press the button (button 3 on Bangle.js 1) to exit +- Holidays have same color as weekends and can be edited with the 'Download'-interface, e.g. by uploading an iCalendar file. ## Settings diff --git a/apps/calendar/calendar.js b/apps/calendar/calendar.js index 6aab1aecd..d7c43eb1f 100644 --- a/apps/calendar/calendar.js +++ b/apps/calendar/calendar.js @@ -16,6 +16,7 @@ const white = "#ffffff"; const red = "#d41706"; const blue = "#0000ff"; const yellow = "#ffff00"; +const cyan = "#00ffff"; let bgColor = color4; let bgColorMonth = color1; let bgColorDow = color2; @@ -23,6 +24,7 @@ let bgColorWeekend = color3; let fgOtherMonth = gray1; let fgSameMonth = white; let bgEvent = blue; +let bgOtherEvent = "#ff8800"; const eventsPerDay=6; // how much different events per day we can display const date = new Date(); @@ -36,9 +38,17 @@ const events = (require("Storage").readJSON("sched.json",1) || []).filter(a => a date.setHours(time.h); date.setMinutes(time.m); date.setSeconds(time.s); - return {date: date, msg: a.msg}; + return {date: date, msg: a.msg, type: "e"}; +}); +// add holidays & other events +(require("Storage").readJSON("calendar.days.json",1) || []).forEach(d => { + const date = new Date(d.date); + const o = {date: date, msg: d.name, type: d.type}; + if (d.repeat) { + o.repeat = d.repeat; + } + events.push(o); }); -events.sort((a,b) => a.date - b.date); if (settings.ndColors === undefined) { settings.ndColors = !g.theme.dark; @@ -52,68 +62,16 @@ if (settings.ndColors === true) { fgOtherMonth = blue; fgSameMonth = black; bgEvent = color2; + bgOtherEvent = cyan; } function getDowLbls(locale) { - let dowLbls; - //TODO: Find some clever way to generate this programmatically from locale lib - switch (locale) { - case "de_AT": - case "de_CH": - case "de_DE": - if (startOnSun) { - dowLbls = ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"]; - } else { - dowLbls = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"]; - } - break; - case "nl_NL": - if (startOnSun) { - dowLbls = ["zo", "ma", "di", "wo", "do", "vr", "za"]; - } else { - dowLbls = ["ma", "di", "wo", "do", "vr", "za", "zo"]; - } - break; - case "fr_BE": - case "fr_CH": - case "fr_FR": - if (startOnSun) { - dowLbls = ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"]; - } else { - dowLbls = ["Lu", "Ma", "Me", "Je", "Ve", "Sa", "Di"]; - } - break; - case "sv_SE": - if (startOnSun) { - dowLbls = ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa"]; - } else { - dowLbls = ["Lu", "Ma", "Me", "Je", "Ve", "Sa", "Di"]; - } - break; - case "it_CH": - case "it_IT": - if (startOnSun) { - dowLbls = ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa"]; - } else { - dowLbls = ["Lu", "Ma", "Me", "Gi", "Ve", "Sa", "Do"]; - } - break; - case "oc_FR": - if (startOnSun) { - dowLbls = ["dg", "dl", "dm", "dc", "dj", "dv", "ds"]; - } else { - dowLbls = ["dl", "dm", "dc", "dj", "dv", "ds", "dg"]; - } - break; - default: - if (startOnSun) { - dowLbls = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]; - } else { - dowLbls = ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"]; - } - break; - } - return dowLbls; + let days = startOnSun ? [0, 1, 2, 3, 4, 5, 6] : [1, 2, 3, 4, 5, 6, 0]; + const d = new Date(); + return days.map(i => { + d.setDate(d.getDate() + (i + 7 - d.getDay()) % 7); + return require("locale").dow(d, 1); + }); } function sameDay(d1, d2) { @@ -206,8 +164,13 @@ function drawCalendar(date) { weekBeforeMonth.setDate(weekBeforeMonth.getDate() - 7); const week2AfterMonth = new Date(date.getFullYear(), date.getMonth()+1, 0); week2AfterMonth.setDate(week2AfterMonth.getDate() + 14); + events.forEach(ev => { + if (ev.repeat === "y") { + ev.date.setFullYear(ev.date.getMonth() < 6 ? week2AfterMonth.getFullYear() : weekBeforeMonth.getFullYear()); + } + }); const eventsThisMonth = events.filter(ev => ev.date > weekBeforeMonth && ev.date < week2AfterMonth); - + eventsThisMonth.sort((a,b) => a.date - b.date); let i = 0; for (y = 0; y < rowN - 1; y++) { for (x = 0; x < colN; x++) { @@ -220,6 +183,33 @@ function drawCalendar(date) { const y1 = y * rowH + headerH + rowH; const x2 = x * colW + colW; const y2 = y * rowH + headerH + rowH + rowH; + + if (eventsThisMonth.length > 0) { + // Display events for this day + eventsThisMonth.forEach((ev, idx) => { + if (sameDay(ev.date, curDay)) { + switch(ev.type) { + case "e": // alarm/event + const hour = ev.date.getHours() + ev.date.getMinutes()/60.0; + const slice = hour/24*(eventsPerDay-1); // slice 0 for 0:00 up to eventsPerDay for 23:59 + const height = (y2-2) - (y1+2); // height of a cell + const sliceHeight = height/eventsPerDay; + const ystart = (y1+2) + slice*sliceHeight; + g.setColor(bgEvent).fillRect(x1+1, ystart, x2-2, ystart+sliceHeight); + break; + case "h": // holiday + g.setColor(bgColorWeekend).fillRect(x1+1, y1+1, x2-1, y2-1); + break; + case "o": // other + g.setColor(bgOtherEvent).fillRect(x1+1, y1+1, x2-1, y2-1); + break; + } + + eventsThisMonth.splice(idx, 1); // this event is no longer needed + } + }); + } + if (isToday) { g.setColor(red); g.drawRect(x1, y1, x2, y2); @@ -231,23 +221,6 @@ function drawCalendar(date) { ); } - if (eventsThisMonth.length > 0) { - // Display events for this day - g.setColor(bgEvent); - eventsThisMonth.forEach((ev, idx) => { - if (sameDay(ev.date, curDay)) { - const hour = ev.date.getHours() + ev.date.getMinutes()/60.0; - const slice = hour/24*(eventsPerDay-1); // slice 0 for 0:00 up to eventsPerDay for 23:59 - const height = (y2-2) - (y1+2); // height of a cell - const sliceHeight = height/eventsPerDay; - const ystart = (y1+2) + slice*sliceHeight; - g.fillRect(x1+1, ystart, x2-2, ystart+sliceHeight); - - eventsThisMonth.splice(idx, 1); // this event is no longer needed - } - }); - } - require("Font8x12").add(Graphics); g.setFont("8x12", fontSize); g.setColor(day < 50 ? fgOtherMonth : fgSameMonth); @@ -286,10 +259,11 @@ function setUI() { }, btn: (n) => n === (process.env.HWVERSION === 2 ? 1 : 3) && load(), touch: (n,e) => { + events.sort((a,b) => a.date - b.date); const menu = events.filter(ev => ev.date.getFullYear() === date.getFullYear() && ev.date.getMonth() === date.getMonth()).map(e => { const dateStr = require("locale").date(e.date, 1); const timeStr = require("locale").time(e.date, 1); - return { title: `${dateStr} ${timeStr}` + (e.msg ? " " + e.msg : "") }; + return { title: `${dateStr} ${e.type === "e" ? timeStr : ""}` + (e.msg ? " " + e.msg : "") }; }); if (menu.length === 0) { menu.push({title: /*LANG*/"No events"}); diff --git a/apps/calendar/interface.html b/apps/calendar/interface.html new file mode 100644 index 000000000..280a96c0b --- /dev/null +++ b/apps/calendar/interface.html @@ -0,0 +1,234 @@ + +
+ + + + + + + +Date | +Holiday | +Type | +Repeat | ++ |
---|
Please choose your country's flag:
+ +Is your flag not here? Please add it here!
+Click
+ + + + + + + + + + + \ No newline at end of file diff --git a/apps/patriotclk/img/README.md b/apps/patriotclk/img/README.md new file mode 100644 index 000000000..53c26165c --- /dev/null +++ b/apps/patriotclk/img/README.md @@ -0,0 +1,9 @@ +Flags +------ + +These flags come from https://icons8.com/icon/set/flags/color and are 480x480px + +If you want to add your own flag ensure it's in the same style and then also list the image file in custom.html in the root directory. + +If your flag is listed in https://icons8.com/icon/set/flags/color and you can't download it in the right size, please file an issue and we'll download it with our account. + diff --git a/apps/patriotclk/img/icons8-australia-480.png b/apps/patriotclk/img/icons8-australia-480.png new file mode 100644 index 000000000..edf34cdee Binary files /dev/null and b/apps/patriotclk/img/icons8-australia-480.png differ diff --git a/apps/patriotclk/img/icons8-austria-480.png b/apps/patriotclk/img/icons8-austria-480.png new file mode 100644 index 000000000..8450a8840 Binary files /dev/null and b/apps/patriotclk/img/icons8-austria-480.png differ diff --git a/apps/patriotclk/img/icons8-belgium-480.png b/apps/patriotclk/img/icons8-belgium-480.png new file mode 100644 index 000000000..395fef8d1 Binary files /dev/null and b/apps/patriotclk/img/icons8-belgium-480.png differ diff --git a/apps/patriotclk/img/icons8-brazil-480.png b/apps/patriotclk/img/icons8-brazil-480.png new file mode 100644 index 000000000..570ee39f9 Binary files /dev/null and b/apps/patriotclk/img/icons8-brazil-480.png differ diff --git a/apps/patriotclk/img/icons8-canada-480.png b/apps/patriotclk/img/icons8-canada-480.png new file mode 100644 index 000000000..3d3080768 Binary files /dev/null and b/apps/patriotclk/img/icons8-canada-480.png differ diff --git a/apps/patriotclk/img/icons8-china-480.png b/apps/patriotclk/img/icons8-china-480.png new file mode 100644 index 000000000..c3c3faba7 Binary files /dev/null and b/apps/patriotclk/img/icons8-china-480.png differ diff --git a/apps/patriotclk/img/icons8-denmark-480.png b/apps/patriotclk/img/icons8-denmark-480.png new file mode 100644 index 000000000..2add9dbce Binary files /dev/null and b/apps/patriotclk/img/icons8-denmark-480.png differ diff --git a/apps/patriotclk/img/icons8-england-480.png b/apps/patriotclk/img/icons8-england-480.png new file mode 100644 index 000000000..5c9a836a6 Binary files /dev/null and b/apps/patriotclk/img/icons8-england-480.png differ diff --git a/apps/patriotclk/img/icons8-flag-of-europe-480.png b/apps/patriotclk/img/icons8-flag-of-europe-480.png new file mode 100644 index 000000000..654da87ba Binary files /dev/null and b/apps/patriotclk/img/icons8-flag-of-europe-480.png differ diff --git a/apps/patriotclk/img/icons8-france-480.png b/apps/patriotclk/img/icons8-france-480.png new file mode 100644 index 000000000..e3cb56348 Binary files /dev/null and b/apps/patriotclk/img/icons8-france-480.png differ diff --git a/apps/patriotclk/img/icons8-germany-480.png b/apps/patriotclk/img/icons8-germany-480.png new file mode 100644 index 000000000..0f86aa568 Binary files /dev/null and b/apps/patriotclk/img/icons8-germany-480.png differ diff --git a/apps/patriotclk/img/icons8-great-britain-480.png b/apps/patriotclk/img/icons8-great-britain-480.png new file mode 100644 index 000000000..0acdcc191 Binary files /dev/null and b/apps/patriotclk/img/icons8-great-britain-480.png differ diff --git a/apps/patriotclk/img/icons8-greece-480.png b/apps/patriotclk/img/icons8-greece-480.png new file mode 100644 index 000000000..319cf93cb Binary files /dev/null and b/apps/patriotclk/img/icons8-greece-480.png differ diff --git a/apps/patriotclk/img/icons8-hungary-480.png b/apps/patriotclk/img/icons8-hungary-480.png new file mode 100644 index 000000000..ab838afea Binary files /dev/null and b/apps/patriotclk/img/icons8-hungary-480.png differ diff --git a/apps/patriotclk/img/icons8-italy-480.png b/apps/patriotclk/img/icons8-italy-480.png new file mode 100644 index 000000000..f917cd85a Binary files /dev/null and b/apps/patriotclk/img/icons8-italy-480.png differ diff --git a/apps/patriotclk/img/icons8-lgbt-flag-480.png b/apps/patriotclk/img/icons8-lgbt-flag-480.png new file mode 100644 index 000000000..10f869a0a Binary files /dev/null and b/apps/patriotclk/img/icons8-lgbt-flag-480.png differ diff --git a/apps/patriotclk/img/icons8-netherlands-480.png b/apps/patriotclk/img/icons8-netherlands-480.png new file mode 100644 index 000000000..b271c5448 Binary files /dev/null and b/apps/patriotclk/img/icons8-netherlands-480.png differ diff --git a/apps/patriotclk/img/icons8-new-zealand-480.png b/apps/patriotclk/img/icons8-new-zealand-480.png new file mode 100644 index 000000000..fc1ca7ec1 Binary files /dev/null and b/apps/patriotclk/img/icons8-new-zealand-480.png differ diff --git a/apps/patriotclk/img/icons8-norway-480.png b/apps/patriotclk/img/icons8-norway-480.png new file mode 100644 index 000000000..270f5af8b Binary files /dev/null and b/apps/patriotclk/img/icons8-norway-480.png differ diff --git a/apps/patriotclk/img/icons8-scotland-480.png b/apps/patriotclk/img/icons8-scotland-480.png new file mode 100644 index 000000000..991652211 Binary files /dev/null and b/apps/patriotclk/img/icons8-scotland-480.png differ diff --git a/apps/patriotclk/img/icons8-spain-480.png b/apps/patriotclk/img/icons8-spain-480.png new file mode 100644 index 000000000..19c8dac04 Binary files /dev/null and b/apps/patriotclk/img/icons8-spain-480.png differ diff --git a/apps/patriotclk/img/icons8-sweden-480.png b/apps/patriotclk/img/icons8-sweden-480.png new file mode 100644 index 000000000..60f412840 Binary files /dev/null and b/apps/patriotclk/img/icons8-sweden-480.png differ diff --git a/apps/patriotclk/img/icons8-switzerland-480.png b/apps/patriotclk/img/icons8-switzerland-480.png new file mode 100644 index 000000000..801ba4776 Binary files /dev/null and b/apps/patriotclk/img/icons8-switzerland-480.png differ diff --git a/apps/patriotclk/img/icons8-ukraine-480.png b/apps/patriotclk/img/icons8-ukraine-480.png new file mode 100644 index 000000000..3762c1112 Binary files /dev/null and b/apps/patriotclk/img/icons8-ukraine-480.png differ diff --git a/apps/patriotclk/img/icons8-usa-480.png b/apps/patriotclk/img/icons8-usa-480.png new file mode 100644 index 000000000..d6288404e Binary files /dev/null and b/apps/patriotclk/img/icons8-usa-480.png differ diff --git a/apps/patriotclk/img/icons8-wales-480.png b/apps/patriotclk/img/icons8-wales-480.png new file mode 100644 index 000000000..6c2941342 Binary files /dev/null and b/apps/patriotclk/img/icons8-wales-480.png differ diff --git a/apps/patriotclk/metadata.json b/apps/patriotclk/metadata.json new file mode 100644 index 000000000..689f1422d --- /dev/null +++ b/apps/patriotclk/metadata.json @@ -0,0 +1,18 @@ +{ "id": "patriotclk", + "name": "Patriotic Clock", + "shortName":"Patriot", + "version":"0.02", + "description": "Show your Patriotism with your Country's flag as a clock face (configurable). Swipe down to show widgets and date.", + "icon": "app.png", + "screenshots": [{"url":"screenshot.png"}], + "type": "clock", + "tags": "clock,flag", + "supports" : ["BANGLEJS2"], + "custom": "custom.html", + "storage": [ + {"name":"patriotclk.app.js","url":"app.js"}, + {"name":"patriotclk.bg.img"}, + {"name":"patriotclk.opts"}, + {"name":"patriotclk.img","url":"app-icon.js","evaluate":true} + ] +} diff --git a/apps/patriotclk/screenshot.png b/apps/patriotclk/screenshot.png new file mode 100644 index 000000000..1f8b1f5f5 Binary files /dev/null and b/apps/patriotclk/screenshot.png differ diff --git a/apps/popconlaunch/ChangeLog b/apps/popconlaunch/ChangeLog index 5560f00bc..8a2124e33 100644 --- a/apps/popconlaunch/ChangeLog +++ b/apps/popconlaunch/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.02: Trim old entries from the popcon app cache diff --git a/apps/popconlaunch/README.md b/apps/popconlaunch/README.md index 2814082a7..18a5354a4 100644 --- a/apps/popconlaunch/README.md +++ b/apps/popconlaunch/README.md @@ -3,6 +3,6 @@ Popcon Display apps sorted by regular use. No config - install the app and all your launchers will sort apps by most popular, based off launch counts within the last month, and then sort them by the most recently launched app. -:warning: Warning: this app overrides [`Storage.readJSON`], so may slow down your watch when using apps that perform I/O. +⚠️ Warning: this app overrides [`Storage.readJSON`], so may slow down your watch when using apps that perform I/O. [`Storage.readJSON`]: https://www.espruino.com/ReferenceBANGLEJS2#l_Storage_readJSON diff --git a/apps/popconlaunch/boot.js b/apps/popconlaunch/boot.js index eb3f18e1b..9124344b2 100644 --- a/apps/popconlaunch/boot.js +++ b/apps/popconlaunch/boot.js @@ -1,6 +1,7 @@ { var oldRead_1 = require("Storage").readJSON; - var monthAgo_1 = Date.now() - 1000 * 86400 * 28; + var oneMonth_1 = 1000 * 86400 * 28; + var monthAgo_1 = Date.now() - oneMonth_1; var cache_1; var ensureCache_1 = function () { if (!cache_1) { @@ -10,8 +11,20 @@ } return cache_1; }; - var saveCache_1 = function (orderChanged) { - require("Storage").writeJSON("popcon.cache.json", cache_1); + var trimCache_1 = function (cache) { + var threeMonthsBack = Date.now() - oneMonth_1 * 3; + var del = []; + for (var k in cache) + if (cache[k].last < threeMonthsBack) + del.push(k); + for (var _i = 0, del_1 = del; _i < del_1.length; _i++) { + var k = del_1[_i]; + delete cache[k]; + } + }; + var saveCache_1 = function (cache, orderChanged) { + trimCache_1(cache); + require("Storage").writeJSON("popcon.cache.json", cache); if (orderChanged) { var info = oldRead_1("popcon.info", true); info.cacheBuster = !info.cacheBuster; @@ -74,7 +87,7 @@ ent.pop++; ent.last = Date.now(); var orderChanged = sortCache_1(); - saveCache_1(orderChanged); + saveCache_1(cache_3, orderChanged); } return oldLoad_1(src); }; diff --git a/apps/popconlaunch/boot.ts b/apps/popconlaunch/boot.ts index a7ac73518..306d4844a 100644 --- a/apps/popconlaunch/boot.ts +++ b/apps/popconlaunch/boot.ts @@ -1,9 +1,6 @@ { type Timestamp = number; - -const oldRead = require("Storage").readJSON; -const monthAgo = Date.now() - 1000 * 86400 * 28; -let cache: undefined | { +type Cache = { [key: string]: { sortorder: number, pop: number, // amount of launches @@ -11,6 +8,11 @@ let cache: undefined | { } }; +const oldRead = require("Storage").readJSON; +const oneMonth = 1000 * 86400 * 28; +const monthAgo = Date.now() - oneMonth; +let cache: undefined | Cache; + const ensureCache = (): NonNull