diff --git a/apps.json b/apps.json index 79ec4066c..d5726ad0c 100644 --- a/apps.json +++ b/apps.json @@ -57,7 +57,7 @@ { "id": "messages", "name": "Messages", - "version": "0.08", + "version": "0.09", "description": "App to display notifications from iOS and Gadgetbridge", "icon": "app.png", "type": "app", diff --git a/apps/messages/ChangeLog b/apps/messages/ChangeLog index 5c65b150d..79fea07ea 100644 --- a/apps/messages/ChangeLog +++ b/apps/messages/ChangeLog @@ -8,5 +8,6 @@ Back now marks a message as read Clicking top-left opens a menu which allows you to delete a message or mark unread 0.07: Added settings menu with option to choose vibrate pattern and frequency (fix #909) -0.08: Fix rendering of long messages (fix #969) +0.08: Fix rendering of long messages (fix #969) buzz on new message (fix #999) +0.09: Message now disappears after 60s if no action taken and clock loads (fix 922) diff --git a/apps/messages/README.md b/apps/messages/README.md index c243ec06a..e9aa128d1 100644 --- a/apps/messages/README.md +++ b/apps/messages/README.md @@ -8,9 +8,17 @@ and responded to. It is a replacement for the old `notify`/`gadgetbridge` apps. -## Usage +## Settings + +You can change settings by going to the global `Settings` app, then `App Settings` +and `Messages`: + +* `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 +* `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 +to the clock where `MESSAGES` will be shown in the Widget bar. -... ## Requests diff --git a/apps/messages/app.js b/apps/messages/app.js index 6c9972fd8..398dcac24 100644 --- a/apps/messages/app.js +++ b/apps/messages/app.js @@ -42,7 +42,12 @@ try { }; } - +/** this is a timeout if the app has started and is showing a single message +but the user hasn't seen it (eg no user input) - in which case +we should start a timeout for settings.unreadTimeout to return +to the clock. */ +var unreadTimeout; +/// List of all our messages var MESSAGES = require("Storage").readJSON("messages.json",1)||[]; if (!Array.isArray(MESSAGES)) MESSAGES=[]; var onMessagesModified = function(msg) { @@ -171,8 +176,14 @@ function showMessageSettings(msg) { function showMessage(msgid) { var msg = MESSAGES.find(m=>m.id==msgid); if (!msg) return checkMessages(); // go home if no message found - if (msg.src=="Maps") return showMapMessage(msg); - if (msg.id=="music") return showMusicMessage(msg); + if (msg.src=="Maps") { + cancelReloadTimeout(); // don't auto-reload to clock now + return showMapMessage(msg); + } + if (msg.id=="music") { + cancelReloadTimeout(); // don't auto-reload to clock now + return showMusicMessage(msg); + } // Normal text message display var title=msg.title, titleFont = fontLarge, lines; if (title) { @@ -186,14 +197,15 @@ function showMessage(msgid) { } var buttons = [ {type:"btn", src:getBackImage(), cb:()=>{ - msg.new = false; // read mail - saveMessages(); + msg.new = false; saveMessages(); // read mail + cancelReloadTimeout(); // don't auto-reload to clock now checkMessages({clockIfNoMsg:1,clockIfAllRead:0,showMsgIfUnread:1}); }} // back ]; if (msg.positive) { buttons.push({type:"btn", src:getPosImage(), cb:()=>{ msg.new = false; saveMessages(); + cancelReloadTimeout(); // don't auto-reload to clock now Bangle.messageResponse(msg,true); checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1}); }}); @@ -202,6 +214,7 @@ function showMessage(msgid) { buttons.push({type:"btn", src:getNegImage(), cb:()=>{ console.log("Response"); msg.new = false; saveMessages(); + cancelReloadTimeout(); // don't auto-reload to clock now Bangle.messageResponse(msg,false); checkMessages({clockIfNoMsg:1,clockIfAllRead:1,showMsgIfUnread:1}); }}); @@ -210,7 +223,10 @@ function showMessage(msgid) { var body = (lines.length>4) ? lines.slice(0,4).join("\n")+"..." : lines.join("\n"); layout = new Layout({ type:"v", c: [ {type:"h", fillx:1, bgCol:colBg, c: [ - { type:"btn", src:getMessageImage(msg), cb:()=>showMessageSettings(msg) }, + { type:"btn", src:getMessageImage(msg), cb:()=>{ + cancelReloadTimeout(); // don't auto-reload to clock now + showMessageSettings(msg); + }}, { type:"v", fillx:1, c: [ {type:"txt", font:fontSmall, label:msg.src||"Message", bgCol:colBg, fillx:1, pad:2, halign:1 }, title?{type:"txt", font:titleFont, label:title, bgCol:colBg, fillx:1, pad:2 }:{}, @@ -249,7 +265,8 @@ function checkMessages(options) { // no new messages - go to clock? if (options.clockIfAllRead && newMessages.length==0) return load(); - + // we don't have to time out of this screen... + cancelReloadTimeout(); // Otherwise show a menu E.showScroller({ h : 48, @@ -291,9 +308,23 @@ function checkMessages(options) { }); } +function cancelReloadTimeout() { + if (!unreadTimeout) return; + clearTimeout(unreadTimeout); + unreadTimeout = undefined; +} + + g.clear(); Bangle.loadWidgets(); Bangle.drawWidgets(); setTimeout(() => { + var unreadTimeoutSecs = (require('Storage').readJSON("messages.settings.json", true) || {}).unreadTimeout; + if (unreadTimeoutSecs===undefined) unreadTimeoutSecs=60; + if (unreadTimeoutSecs) + unreadTimeout = setTimeout(function() { + print("Message not seen - reloading"); + load(); + }, unreadTimeoutSecs*1000); checkMessages({clockIfNoMsg:0,clockIfAllRead:0,showMsgIfUnread:1}); },10); // if checkMessages wants to 'load', do that diff --git a/apps/messages/lib.js b/apps/messages/lib.js index 4593c8605..e93a5e2ba 100644 --- a/apps/messages/lib.js +++ b/apps/messages/lib.js @@ -1,10 +1,10 @@ +/* Push a new message onto messages queue, event is: + {t:"add",id:int, src,title,subject,body,sender,tel, important:bool} // add new + {t:"add",id:int, id:"music", state, artist, track, etc} // add new + {t:"remove-",id:int} // remove + {t:"modify",id:int, title:string} // modified +*/ exports.pushMessage = function(event) { - /* event is: - {t:"add",id:int, src,title,subject,body,sender,tel, important:bool} // add new - {t:"add",id:int, id:"music", state, artist, track, etc} // add new - {t:"remove-",id:int} // remove - {t:"modify",id:int, title:string} // modified - */ var messages, inApp = "undefined"!=typeof MESSAGES; if (inApp) messages = MESSAGES; // we're in an app that has already loaded messages @@ -43,6 +43,7 @@ exports.pushMessage = function(event) { WIDGETS.messages.show(); }, 500); } +/// Remove all messages exports.clearAll = function(event) { var messages, inApp = "undefined"!=typeof MESSAGES; if (inApp) { diff --git a/apps/messages/settings.js b/apps/messages/settings.js index ef6266cf6..fd8ce8f39 100644 --- a/apps/messages/settings.js +++ b/apps/messages/settings.js @@ -3,6 +3,7 @@ let settings = require('Storage').readJSON("messages.settings.json", true) || {}; if (settings.vibrate===undefined) settings.vibrate="."; if (settings.repeat===undefined) settings.repeat=4; + if (settings.unreadTimeout===undefined) settings.unreadTimeout=60; return settings; } function updateSetting(setting, value) { @@ -30,6 +31,12 @@ format: v => v+"s", onchange: v => updateSetting("repeat", v) }, + 'Unread timer': { + value: settings().unreadTimeout, + min: 0, max: 240, step : 10, + format: v => v?v+"s":"Off", + onchange: v => updateSetting("unreadTimeout", v) + }, }; E.showMenu(mainmenu); }) diff --git a/apps/messages/widget.js b/apps/messages/widget.js index 3a22b40fd..245a303fc 100644 --- a/apps/messages/widget.js +++ b/apps/messages/widget.js @@ -1,4 +1,3 @@ - WIDGETS["messages"]={area:"tl",width:0,draw:function() { if (!this.width) return; var c = (Date.now()-this.t)/1000; @@ -13,9 +12,10 @@ WIDGETS["messages"]={area:"tl",width:0,draw:function() { WIDGETS["messages"].buzz(); // buzz every 4 seconds } setTimeout(()=>WIDGETS["messages"].draw(), 1000); -},show:function() { +},show:function(quiet) { WIDGETS["messages"].t=Date.now(); // first time WIDGETS["messages"].l=Date.now()-10000; // last buzz + if (quiet) WIDGETS["messages"].t -= 500000; // if quiet, set last time in the past so there is no buzzing WIDGETS["messages"].width=64; Bangle.drawWidgets(); Bangle.setLCDPower(1);// turns screen on @@ -34,3 +34,10 @@ WIDGETS["messages"]={area:"tl",width:0,draw:function() { } b(); }}; +/* We might have returned here if we were in the Messages app for a +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. */ +if (global.MESSAGES===undefined) (function() { + var messages = require("Storage").readJSON("messages.json",1)||[]; + if (messages.some(m=>m.new)) WIDGETS["messages"].show(true); +})();