1
0
Fork 0

Merge branch 'espruino:master' into master

master
Peer David 2022-03-11 15:08:03 +01:00 committed by GitHub
commit c99fd2e145
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 78 additions and 29 deletions

View File

@ -2,3 +2,4 @@
0.02: added settings menu to change color 0.02: added settings menu to change color
0.03: fix metadata.json to allow setting as clock 0.03: fix metadata.json to allow setting as clock
0.04: added heart rate which is switched on when cycled to it through up/down touch on rhs 0.04: added heart rate which is switched on when cycled to it through up/down touch on rhs
0.05: changed text to uppercase, just looks better, removed colons on text

View File

@ -109,10 +109,10 @@ function updateSunRiseSunSet(now, lat, lon, line){
const infoData = { const infoData = {
ID_DATE: { calc: () => {var d = (new Date()).toString().split(" "); return d[2] + ' ' + d[1] + ' ' + d[3];} }, ID_DATE: { calc: () => {var d = (new Date()).toString().split(" "); return d[2] + ' ' + d[1] + ' ' + d[3];} },
ID_DAY: { calc: () => {var d = require("locale").dow(new Date()).toLowerCase(); return d[0].toUpperCase() + d.substring(1);} }, ID_DAY: { calc: () => {var d = require("locale").dow(new Date()).toLowerCase(); return d[0].toUpperCase() + d.substring(1);} },
ID_SR: { calc: () => 'Sunrise: ' + sunRise }, ID_SR: { calc: () => 'Sunrise ' + sunRise },
ID_SS: { calc: () => 'Sunset: ' + sunSet }, ID_SS: { calc: () => 'Sunset ' + sunSet },
ID_STEP: { calc: () => 'Steps: ' + getSteps() }, ID_STEP: { calc: () => 'Steps ' + getSteps() },
ID_BATT: { calc: () => 'Battery: ' + E.getBattery() + '%' }, ID_BATT: { calc: () => 'Battery ' + E.getBattery() + '%' },
ID_HRM: { calc: () => hrmCurrent } ID_HRM: { calc: () => hrmCurrent }
}; };
@ -158,7 +158,7 @@ function drawInfo() {
g.setColor('#f00'); // red g.setColor('#f00'); // red
drawHeartIcon(); drawHeartIcon();
} else { } else {
g.drawString((infoData[infoMode].calc()), w/2, infoLine); g.drawString((infoData[infoMode].calc().toUpperCase()), w/2, infoLine);
} }
} }

View File

@ -1,6 +1,6 @@
{ "id": "daisy", { "id": "daisy",
"name": "Daisy", "name": "Daisy",
"version":"0.04", "version":"0.05",
"dependencies": {"mylocation":"app"}, "dependencies": {"mylocation":"app"},
"description": "A clock based on the Pastel clock with large ring guage for steps", "description": "A clock based on the Pastel clock with large ring guage for steps",
"icon": "app.png", "icon": "app.png",

View File

@ -38,3 +38,4 @@
Now attempt to use Large/Big/Medium fonts, and allow minimum font size to be configured Now attempt to use Large/Big/Medium fonts, and allow minimum font size to be configured
0.24: Remove left-over debug statement 0.24: Remove left-over debug statement
0.25: Fix widget memory usage issues if message received and watch repeatedly calls Bangle.drawWidgets (fix #1550) 0.25: Fix widget memory usage issues if message received and watch repeatedly calls Bangle.drawWidgets (fix #1550)
0.26: Setting to auto-open music

View File

@ -13,12 +13,13 @@ and `Messages`:
* `Vibrate` - This is the pattern of buzzes that should be made when a new message is received * `Vibrate` - This is the pattern of buzzes that should be made when a new message is received
* `Repeat` - How often should buzzes repeat - the default of 4 means the Bangle will buzz every 4 seconds * `Repeat` - How often should buzzes repeat - the default of 4 means the Bangle will buzz every 4 seconds
* `Unread Timer` - when a new message is received we go into the Messages app. * `Unread Timer` - When a new message is received we go into the Messages app.
If there is no user input for this amount of time then the app will exit and return If there is no user input for this amount of time then the app will exit and return
to the clock where a ringing bell will be shown in the Widget bar. to the clock where a ringing bell will be shown in the Widget bar.
* `Min Font` - the minimum font size used when displaying messages on the screen. A bigger font * `Min Font` - The minimum font size used when displaying messages on the screen. A bigger font
is chosen if there isn't much message text, but this specifies the smallest the font should get before is chosen if there isn't much message text, but this specifies the smallest the font should get before
it starts getting clipped. it starts getting clipped.
* `Auto-Open Music` - Should the app automatically open when the phone starts playing music?
## New Messages ## New Messages

View File

@ -26,6 +26,8 @@ var fontSmall = "6x8";
var fontMedium = g.getFonts().includes("6x15")?"6x15":"6x8:2"; var fontMedium = g.getFonts().includes("6x15")?"6x15":"6x8:2";
var fontBig = g.getFonts().includes("12x20")?"12x20":"6x8:2"; var fontBig = g.getFonts().includes("12x20")?"12x20":"6x8:2";
var fontLarge = g.getFonts().includes("6x15")?"6x15:2":"6x8:4"; var fontLarge = g.getFonts().includes("6x15")?"6x15:2":"6x8:4";
var active; // active screen
var openMusic = false; // go back to music screen after we handle something else?
// hack for 2v10 firmware's lack of ':size' font handling // hack for 2v10 firmware's lack of ':size' font handling
try { try {
g.setFont("6x8:2"); g.setFont("6x8:2");
@ -50,10 +52,14 @@ var MESSAGES = require("Storage").readJSON("messages.json",1)||[];
if (!Array.isArray(MESSAGES)) MESSAGES=[]; if (!Array.isArray(MESSAGES)) MESSAGES=[];
var onMessagesModified = function(msg) { var onMessagesModified = function(msg) {
// TODO: if new, show this new one // TODO: if new, show this new one
if (msg && msg.new && !((require('Storage').readJSON('setting.json', 1) || {}).quiet)) { if (msg && msg.id!=="music" && msg.new && !((require('Storage').readJSON('setting.json', 1) || {}).quiet)) {
if (WIDGETS["messages"]) WIDGETS["messages"].buzz(); if (WIDGETS["messages"]) WIDGETS["messages"].buzz();
else Bangle.buzz(); else Bangle.buzz();
} }
if (msg && msg.id=="music") {
if (msg.state && msg.state!="play") openMusic = false; // no longer playing music to go back to
if (active!="music") return; // don't open music over other screens
}
showMessage(msg&&msg.id); showMessage(msg&&msg.id);
}; };
function saveMessages() { function saveMessages() {
@ -135,6 +141,7 @@ function getMessageImageCol(msg,def) {
} }
function showMapMessage(msg) { function showMapMessage(msg) {
active = "map";
var m; var m;
var distance, street, target, eta; var distance, street, target, eta;
m=msg.title.match(/(.*) - (.*)/); m=msg.title.match(/(.*) - (.*)/);
@ -168,12 +175,14 @@ function showMapMessage(msg) {
msg.new = false; msg.new = false;
saveMessages(); saveMessages();
layout = undefined; layout = undefined;
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1}); checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:0});
}); });
} }
var updateLabelsInterval;
function showMusicMessage(msg) { function showMusicMessage(msg) {
var updateLabelsInterval; active = "music";
openMusic = msg.state=="play";
var trackScrollOffset = 0; var trackScrollOffset = 0;
var artistScrollOffset = 0; var artistScrollOffset = 0;
var albumScrollOffset = 0; var albumScrollOffset = 0;
@ -194,10 +203,14 @@ function showMusicMessage(msg) {
function back() { function back() {
clearInterval(updateLabelsInterval); clearInterval(updateLabelsInterval);
updateLabelsInterval = undefined;
openMusic = false;
var wasNew = msg.new;
msg.new = false; msg.new = false;
saveMessages(); saveMessages();
layout = undefined; layout = undefined;
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1}); if (wasNew) checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:0,openMusic:0});
else checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
} }
function updateLabels() { function updateLabels() {
trackName = reduceStringAndPad(msg.track, trackScrollOffset, 13); trackName = reduceStringAndPad(msg.track, trackScrollOffset, 13);
@ -243,6 +256,7 @@ function showMusicMessage(msg) {
} }
function showMessageScroller(msg) { function showMessageScroller(msg) {
active = "scroller";
var bodyFont = fontBig; var bodyFont = fontBig;
g.setFont(bodyFont); g.setFont(bodyFont);
var lines = []; var lines = [];
@ -272,6 +286,7 @@ function showMessageScroller(msg) {
} }
function showMessageSettings(msg) { function showMessageSettings(msg) {
active = "settings";
E.showMenu({"":{"title":/*LANG*/"Message"}, E.showMenu({"":{"title":/*LANG*/"Message"},
"< Back" : () => showMessage(msg.id), "< Back" : () => showMessage(msg.id),
/*LANG*/"View Message" : () => { /*LANG*/"View Message" : () => {
@ -280,12 +295,12 @@ function showMessageSettings(msg) {
/*LANG*/"Delete" : () => { /*LANG*/"Delete" : () => {
MESSAGES = MESSAGES.filter(m=>m.id!=msg.id); MESSAGES = MESSAGES.filter(m=>m.id!=msg.id);
saveMessages(); saveMessages();
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0}); checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
}, },
/*LANG*/"Mark Unread" : () => { /*LANG*/"Mark Unread" : () => {
msg.new = true; msg.new = true;
saveMessages(); saveMessages();
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0}); checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
}, },
/*LANG*/"Delete all messages" : () => { /*LANG*/"Delete all messages" : () => {
E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => { E.showPrompt(/*LANG*/"Are you sure?", {title:/*LANG*/"Delete All Messages"}).then(isYes => {
@ -293,7 +308,7 @@ function showMessageSettings(msg) {
MESSAGES = []; MESSAGES = [];
saveMessages(); saveMessages();
} }
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0}); checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:0,openMusic:0});
}); });
}, },
}); });
@ -301,15 +316,20 @@ function showMessageSettings(msg) {
function showMessage(msgid) { function showMessage(msgid) {
var msg = MESSAGES.find(m=>m.id==msgid); var msg = MESSAGES.find(m=>m.id==msgid);
if (!msg) return checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0}); // go home if no message found if (updateLabelsInterval) {
if (msg.src=="Maps") { clearInterval(updateLabelsInterval);
cancelReloadTimeout(); // don't auto-reload to clock now updateLabelsInterval=undefined;
return showMapMessage(msg);
} }
if (!msg) return checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic}); // go home if no message found
if (msg.id=="music") { if (msg.id=="music") {
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
return showMusicMessage(msg); return showMusicMessage(msg);
} }
if (msg.src=="Maps") {
cancelReloadTimeout(); // don't auto-reload to clock now
return showMapMessage(msg);
}
active = "message";
// Normal text message display // Normal text message display
var title=msg.title, titleFont = fontLarge, lines; var title=msg.title, titleFont = fontLarge, lines;
if (title) { if (title) {
@ -342,7 +362,7 @@ function showMessage(msgid) {
function goBack() { function goBack() {
msg.new = false; saveMessages(); // read mail msg.new = false; saveMessages(); // read mail
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0}); checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:0,openMusic:openMusic});
} }
var buttons = [ var buttons = [
{type:"btn", src:getBackImage(), cb:goBack} // back {type:"btn", src:getBackImage(), cb:goBack} // back
@ -353,7 +373,7 @@ function showMessage(msgid) {
msg.new = false; saveMessages(); msg.new = false; saveMessages();
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
Bangle.messageResponse(msg,true); Bangle.messageResponse(msg,true);
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1}); checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
}}); }});
} }
if (msg.negative) { if (msg.negative) {
@ -362,7 +382,7 @@ function showMessage(msgid) {
msg.new = false; saveMessages(); msg.new = false; saveMessages();
cancelReloadTimeout(); // don't auto-reload to clock now cancelReloadTimeout(); // don't auto-reload to clock now
Bangle.messageResponse(msg,false); Bangle.messageResponse(msg,false);
checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1}); checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1,openMusic:openMusic});
}}); }});
} }
@ -411,15 +431,19 @@ function checkMessages(options) {
return load(); return load();
} }
// we have >0 messages // we have >0 messages
var newMessages = MESSAGES.filter(m=>m.new); var newMessages = MESSAGES.filter(m=>m.new&&m.id!="music");
// If we have a new message, show it // If we have a new message, show it
if (options.showMsgIfUnread && newMessages.length) if (options.showMsgIfUnread && newMessages.length)
return showMessage(newMessages[0].id); return showMessage(newMessages[0].id);
// no new messages: show playing music? (only if we have playing music to show)
if (options.openMusic && MESSAGES.some(m=>m.id=="music" && m.track && m.state=="play"))
return showMessage('music');
// no new messages - go to clock? // no new messages - go to clock?
if (options.clockIfAllRead && newMessages.length==0) if (options.clockIfAllRead && newMessages.length==0)
return load(); return load();
// we don't have to time out of this screen... // we don't have to time out of this screen...
cancelReloadTimeout(); cancelReloadTimeout();
active = "main";
// Otherwise show a menu // Otherwise show a menu
E.showScroller({ E.showScroller({
h : 48, h : 48,
@ -482,5 +506,7 @@ setTimeout(() => {
print("Message not seen - reloading"); print("Message not seen - reloading");
load(); load();
}, unreadTimeoutSecs*1000); }, unreadTimeoutSecs*1000);
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:1}); // only openMusic on launch if music is new
var newMusic = MESSAGES.some(m=>m.id==="music"&&m.new);
checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:1,openMusic:newMusic&&settings.openMusic});
},10); // if checkMessages wants to 'load', do that },10); // if checkMessages wants to 'load', do that

View File

@ -1,3 +1,10 @@
function openMusic() {
// only read settings file for first music message
if ("undefined"==typeof exports._openMusic) {
exports._openMusic = !!((require('Storage').readJSON("messages.settings.json", true) || {}).openMusic);
}
return exports._openMusic;
}
/* Push a new message onto messages queue, event is: /* Push a new message onto messages queue, event is:
{t:"add",id:int, src,title,subject,body,sender,tel, important:bool, new:bool} {t:"add",id:int, src,title,subject,body,sender,tel, important:bool, new:bool}
{t:"add",id:int, id:"music", state, artist, track, etc} // add new {t:"add",id:int, id:"music", state, artist, track, etc} // add new
@ -26,6 +33,9 @@ exports.pushMessage = function(event) {
messages.unshift(event); // add new messages to the beginning messages.unshift(event); // add new messages to the beginning
} }
else Object.assign(messages[mIdx], event); else Object.assign(messages[mIdx], event);
if (event.id=="music" && messages[mIdx].state=="play") {
messages[mIdx].new = true; // new track, or playback (re)started
}
} }
require("Storage").writeJSON("messages.json",messages); require("Storage").writeJSON("messages.json",messages);
// if in app, process immediately // if in app, process immediately
@ -34,8 +44,12 @@ exports.pushMessage = function(event) {
if (event.t=="remove" && !messages.some(m=>m.new)) { if (event.t=="remove" && !messages.some(m=>m.new)) {
if (global.WIDGETS && WIDGETS.messages) WIDGETS.messages.hide(); if (global.WIDGETS && WIDGETS.messages) WIDGETS.messages.hide();
} }
// ok, saved now - we only care if it's new // ok, saved now
if (event.t!="add") { if (event.id=="music" && Bangle.CLOCK && messages[mIdx].new && openMusic()) {
// just load the app to display music: no buzzing
load("messages.app.js");
} else if (event.t!="add") {
// we only care if it's new
return; return;
} else if(event.new == false) { } else if(event.new == false) {
return; return;

View File

@ -1,7 +1,7 @@
{ {
"id": "messages", "id": "messages",
"name": "Messages", "name": "Messages",
"version": "0.25", "version": "0.26",
"description": "App to display notifications from iOS and Gadgetbridge/Android", "description": "App to display notifications from iOS and Gadgetbridge/Android",
"icon": "app.png", "icon": "app.png",
"type": "app", "type": "app",

View File

@ -4,6 +4,7 @@
if (settings.vibrate===undefined) settings.vibrate="."; if (settings.vibrate===undefined) settings.vibrate=".";
if (settings.repeat===undefined) settings.repeat=4; if (settings.repeat===undefined) settings.repeat=4;
if (settings.unreadTimeout===undefined) settings.unreadTimeout=60; if (settings.unreadTimeout===undefined) settings.unreadTimeout=60;
settings.openMusic=!!settings.openMusic;
settings.maxUnreadTimeout=240; settings.maxUnreadTimeout=240;
return settings; return settings;
} }
@ -43,6 +44,11 @@
format: v => [/*LANG*/"Small",/*LANG*/"Medium"][v], format: v => [/*LANG*/"Small",/*LANG*/"Medium"][v],
onchange: v => updateSetting("fontSize", v) onchange: v => updateSetting("fontSize", v)
}, },
/*LANG*/'Auto-Open Music': {
value: !!settings().openMusic,
format: v => v?/*LANG*/'Yes':/*LANG*/'No',
onchange: v => updateSetting("openMusic", v)
},
}; };
E.showMenu(mainmenu); E.showMenu(mainmenu);
}) })

View File

@ -50,5 +50,5 @@ message but then the watch was never viewed. In that case we don't
want to buzz but should still show that there are unread messages. */ want to buzz but should still show that there are unread messages. */
if (global.MESSAGES===undefined) (function() { if (global.MESSAGES===undefined) (function() {
var messages = require("Storage").readJSON("messages.json",1)||[]; var messages = require("Storage").readJSON("messages.json",1)||[];
if (messages.some(m=>m.new)) WIDGETS["messages"].show(true); if (messages.some(m=>m.new&&m.id!="music")) WIDGETS["messages"].show(true);
})(); })();

View File

@ -3,7 +3,7 @@
"name": "Terminal Clock", "name": "Terminal Clock",
"shortName":"Terminal Clock", "shortName":"Terminal Clock",
"description": "A terminal cli like clock displaying multiple sensor data", "description": "A terminal cli like clock displaying multiple sensor data",
"version":"0.01", "version":"0.02",
"icon": "app.png", "icon": "app.png",
"type": "clock", "type": "clock",
"tags": "clock", "tags": "clock",