From d92fa8fb1a3af44a59ad6e57d03f61332c4916ef Mon Sep 17 00:00:00 2001 From: Nicholas Onorato Date: Tue, 8 Mar 2022 20:45:19 -0700 Subject: [PATCH] Added my countdown widget --- apps/widmnth/ChangeLog | 1 + apps/widmnth/README.md | 22 +++++++++++++++++++ apps/widmnth/metadata.json | 14 +++++++++++++ apps/widmnth/widget.js | 42 +++++++++++++++++++++++++++++++++++++ apps/widmnth/widget.png | Bin 0 -> 470 bytes 5 files changed, 79 insertions(+) create mode 100644 apps/widmnth/ChangeLog create mode 100644 apps/widmnth/README.md create mode 100644 apps/widmnth/metadata.json create mode 100644 apps/widmnth/widget.js create mode 100644 apps/widmnth/widget.png diff --git a/apps/widmnth/ChangeLog b/apps/widmnth/ChangeLog new file mode 100644 index 000000000..370f41e8a --- /dev/null +++ b/apps/widmnth/ChangeLog @@ -0,0 +1 @@ +0.01: Simple new widget! diff --git a/apps/widmnth/README.md b/apps/widmnth/README.md new file mode 100644 index 000000000..ef912c739 --- /dev/null +++ b/apps/widmnth/README.md @@ -0,0 +1,22 @@ +# Widget Name + +The days left in month widget is simple and just prints the number of days left in the month in the top left corner. +The idea is to encourage people to keep track of time and keep goals they may have for the month. + +## Usage + +Hopefully you just have to Install it and it'll work. Customizing the location would just be changing tl to tr. + +## Features + +* Shows days left in month +* Only updates at midnight. + + +## Requests + +Complaints,compliments,problems,suggestions,annoyances,bugs, and all other feedback can be filed at [this repo](https://github.com/N-Onorato/BangleApps) + +## Creator + +Nick diff --git a/apps/widmnth/metadata.json b/apps/widmnth/metadata.json new file mode 100644 index 000000000..25f3a8126 --- /dev/null +++ b/apps/widmnth/metadata.json @@ -0,0 +1,14 @@ +{ "id": "widmnth", + "name": "Days left in month widget", + "shortName":"Month Countdown", + "version":"0.01", + "description": "A simple widget that displays the number of days left in the month.", + "icon": "widget.png", + "type": "widget", + "tags": "widget,date,time,countdown,month", + "supports" : ["BANGLEJS","BANGLEJS2"], + "readme": "README.md", + "storage": [ + {"name":"widmnth.wid.js","url":"widget.js"} + ] +} diff --git a/apps/widmnth/widget.js b/apps/widmnth/widget.js new file mode 100644 index 000000000..c4eca155a --- /dev/null +++ b/apps/widmnth/widget.js @@ -0,0 +1,42 @@ + +(() => { + var days_left; + var clearCode; + + function getDaysLeft(day) { + let year = day.getMonth() == 11 ? day.getFullYear() + 1 : day.getFullYear(); // rollover if december. + next_month = new Date(year, (day.getMonth() + 1) % 12, 1, 0, 0, 0); + let days_left = Math.floor((next_month - day) / 86400000); // ms left in month divided by ms in a day + return days_left; + } + + function getTimeTilMidnight(now) { + let midnight = new Date(now.getTime()); + midnight.setHours(23); + midnight.setMinutes(59); + midnight.setSeconds(59); + midnight.setMilliseconds(999); + return (midnight - now) + 1; + } + + function update() { + let now = new Date(); + days_left = getDaysLeft(now); + let ms_til_midnight = getTimeTilMidnight(now); + clearCode = setTimeout(update, ms_til_midnight); + } + + function draw() { + g.reset(); + g.setFont("4x6", 3); + if(!clearCode) update(); // On first run calculate days left and setup interval to update state. + g.drawString(days_left < 10 ? "0" + days_left : days_left.toString(), this.x + 2, this.y + 4); + } + + // add your widget + WIDGETS.widmonthcountdown={ + area:"tl", // tl (top left), tr (top right), bl (bottom left), br (bottom right) + width: 24, + draw:draw + }; +})(); \ No newline at end of file diff --git a/apps/widmnth/widget.png b/apps/widmnth/widget.png new file mode 100644 index 0000000000000000000000000000000000000000..4a042ec05559285fa9ea28f8050432e3110adb5f GIT binary patch literal 470 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnF3?v&v(vJfvg8-ip*Uk#h-Aht{yyNS#ERE!1 z1C1m^c@L~eJGwU0KuhY#>Wp9y9ZeOn#r@$N>?|i;)!H{|fm92W1o;L3M+FQIlw&1< za-0Pok;M!Q+#5icQOZJ~h=GC8z|+MsL}OxdK#*Ib7taw6iNy?TA?pNpaUEh3Fcy0= z=WJfi25Am69j28AB|$+!f@YyiOraYZwoXc$6x3oG!H{!Ib?NIxUR~SD-`^{}#5()n zlGv?bp5;eBePUXgFoA1r>z-r0UR_6z9s3@laBZE@wh4i=?rqJQI=QJ(IKW}?;++@$ zUxvAFKDfB2FKvRP?Ah`uLTkcGO0-y`9YRc0R&qp_tl6=oL{ewL9ns~-_bpnySlMrR z1#3j>iN(xKPoIh%YY*uO*I}ELD9Tc__)wRdYG}9KhOGjP>*7>HleITUD(X2rxSja= zQNo=@4*u1m-PW@j&o#7bUYN$m{kTtU2G{D))w>*$3Up=9ipd_66)Rv|Evjv$qvJ4Z yL0U;kgK0^_*#IM^L#|%F4ni#pnK(KW85k1fyG8kLhC~1Zl)=;0&t;ucLK6TlqO}$P literal 0 HcmV?d00001