From 107468bcdca05745d8ade9ca4201b43b87eb6e81 Mon Sep 17 00:00:00 2001 From: Erik Andresen Date: Mon, 16 Oct 2023 19:08:35 +0200 Subject: [PATCH] calendar: drop settings.ndColors, fixes widgets --- apps/calendar/ChangeLog | 2 ++ apps/calendar/README.md | 6 +--- apps/calendar/calendar.js | 72 +++++++++++++++++++------------------ apps/calendar/metadata.json | 2 +- apps/calendar/settings.js | 13 ------- 5 files changed, 41 insertions(+), 54 deletions(-) diff --git a/apps/calendar/ChangeLog b/apps/calendar/ChangeLog index 106827aad..206b3080e 100644 --- a/apps/calendar/ChangeLog +++ b/apps/calendar/ChangeLog @@ -16,3 +16,5 @@ 0.14: Add support for holidays 0.15: Edit holidays on device in settings 0.16: Add menu to fast open settings to edit holidays + Drop "B2 Colors" setting, use theme dark indicator instead + Display Widgets in menus diff --git a/apps/calendar/README.md b/apps/calendar/README.md index 5f90d0d52..03a151bf5 100644 --- a/apps/calendar/README.md +++ b/apps/calendar/README.md @@ -1,6 +1,6 @@ # Calendar -Basic calendar +Monthly calendar, displays holidays uploaded from the web interface and scheduled events. ## Usage @@ -11,7 +11,3 @@ Basic calendar - 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 - -- B2 Colors: use non-dithering colors (default, recommended for Bangle 2) or the original color scheme. diff --git a/apps/calendar/calendar.js b/apps/calendar/calendar.js index 2c54f1174..4d0db5867 100644 --- a/apps/calendar/calendar.js +++ b/apps/calendar/calendar.js @@ -32,30 +32,30 @@ const date = new Date(); const timeutils = require("time_utils"); let settings = require('Storage').readJSON("calendar.json", true) || {}; let startOnSun = ((require("Storage").readJSON("setting.json", true) || {}).firstDayOfWeek || 0) === 0; - // all alarms that run on a specific date -const events = (require("Storage").readJSON("sched.json",1) || []).filter(a => a.on && a.date).map(a => { - const date = new Date(a.date); - const time = timeutils.decodeTime(a.t); - date.setHours(time.h); - date.setMinutes(time.m); - date.setSeconds(time.s); - 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); -}); +let events; -if (settings.ndColors === undefined) { - settings.ndColors = !g.theme.dark; -} +const loadEvents = () => { + // all alarms that run on a specific date + events = (require("Storage").readJSON("sched.json",1) || []).filter(a => a.on && a.date).map(a => { + const date = new Date(a.date); + const time = timeutils.decodeTime(a.t); + date.setHours(time.h); + date.setMinutes(time.m); + date.setSeconds(time.s); + 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); + }); +}; -if (settings.ndColors === true) { +if (!g.theme.dark) { bgColor = white; bgColorMonth = blue; bgColorDow = black; @@ -249,26 +249,30 @@ const showMenu = function() { "< Back": () => { require("widget_utils").hide(); E.showMenu(); - drawCalendar(date); setUI(); }, + /*LANG*/"Exit": () => load(), /*LANG*/"Settings": () => { const appSettings = eval(require('Storage').read('calendar.settings.js')); - appSettings(showMenu); + appSettings(() => { + loadEvents(); + showMenu(); + }); }, - /*LANG*/"Launch Alarms": () => { - load("alarm.app.js"); - }, - /*LANG*/"Exit": () => load(), }; - if (!require("Storage").read("alarm.app.js")) { - delete menu[/*LANG*/"Launch Alarms"]; + if (require("Storage").read("alarm.app.js")) { + menu[/*LANG*/"Launch Alarms"] = () => { + load("alarm.app.js"); + }; } require("widget_utils").show(); E.showMenu(menu); }; const setUI = function() { + require("widget_utils").hide(); // No space for widgets! + drawCalendar(date); + Bangle.setUI({ mode : "custom", swipe: (dirLR, dirUD) => { @@ -314,7 +318,6 @@ const setUI = function() { menu["< Back"] = () => { require("widget_utils").hide(); E.showMenu(); - drawCalendar(date); setUI(); }; require("widget_utils").show(); @@ -323,9 +326,8 @@ const setUI = function() { }); }; -require("Font8x12").add(Graphics); -drawCalendar(date); -setUI(); +loadEvents(); Bangle.loadWidgets(); -require("widget_utils").hide(); // No space for widgets! +require("Font8x12").add(Graphics); +setUI(); } diff --git a/apps/calendar/metadata.json b/apps/calendar/metadata.json index a1ec183cb..e263efe35 100644 --- a/apps/calendar/metadata.json +++ b/apps/calendar/metadata.json @@ -2,7 +2,7 @@ "id": "calendar", "name": "Calendar", "version": "0.16", - "description": "Simple calendar", + "description": "Monthly calendar, displays holidays uploaded from the web interface and scheduled events.", "icon": "calendar.png", "screenshots": [{"url":"screenshot_calendar.png"}], "tags": "calendar,tool", diff --git a/apps/calendar/settings.js b/apps/calendar/settings.js index 40eca9f68..434aa74f5 100644 --- a/apps/calendar/settings.js +++ b/apps/calendar/settings.js @@ -2,12 +2,6 @@ var FILE = "calendar.json"; const HOLIDAY_FILE = "calendar.days.json"; var settings = require('Storage').readJSON(FILE, true) || {}; - if (settings.ndColors === undefined) - if (process.env.HWVERSION == 2) { - settings.ndColors = true; - } else { - settings.ndColors = false; - } const holidays = require("Storage").readJSON(HOLIDAY_FILE,1).sort((a,b) => new Date(a.date) - new Date(b.date)) || []; function writeSettings() { @@ -132,13 +126,6 @@ E.showMenu({ "": { "title": "Calendar" }, "< Back": () => back(), - 'B2 Colors': { - value: settings.ndColors, - onchange: v => { - settings.ndColors = v; - writeSettings(); - } - }, /*LANG*/"Edit Holidays": () => editdates(), /*LANG*/"Add Holiday": () => { holidays.push({