calendar: drop settings.ndColors, fixes widgets

pull/3051/head
Erik Andresen 2023-10-16 19:08:35 +02:00
parent 404ceca0b2
commit 107468bcdc
5 changed files with 41 additions and 54 deletions

View File

@ -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

View File

@ -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.

View File

@ -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();
}

View File

@ -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",

View File

@ -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({