Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clkinfomsg: clockinfo for displaying messages count #3587

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/clkinfomsg/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.01: First release
18 changes: 18 additions & 0 deletions apps/clkinfomsg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Messages Clockinfo

A simple messages counter for clockinfo enabled watchfaces

## Usage

You can choose between read and unread counter.
Tap to go to messages UI.

## Todo / Known Issues

* GB triggers for message read on phone are not handled
* Icons are not consistent
* Maybe use messageicons for handling icon from last notification

## Attributions

All icons used in this app are from [icons8](https://icons8.com).
Binary file added apps/clkinfomsg/app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions apps/clkinfomsg/clkinfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
(function() {

var unreadImg = function() {
return atob("GBiBAAAAAAAAAAAAAB//+D///D///D///D///D///D///D5mfD5mfD///D///D///D///D///D///B//+APgAAOAAAOAAAAAAAAAAA==");
}
var allImg = function() {
return atob("GBiBAAAAAAAAAAB+AAD/AAPDwA8A8B4AeDgAHDgAHDwAPD8A/D/D/D/n/D///D///D///D///D///D///B//+AAAAAAAAAAAAAAAAA==");
}

var debug = function(o) {
//console.log(o);
}
var msgUnread;
var msgAll;
var msgs = require("messages");

var getAllMGS = function() {
kamilkrz marked this conversation as resolved.
Show resolved Hide resolved
if (msgAll === undefined) {
debug("msgAll is undefined");
msgAll = msgs.getMessages().filter(m => !['call', 'map', 'music'].includes(m.id)).map(m => m.src).length;
}
return msgAll;
}


var getUnreadMGS = function() {
if (msgUnread === undefined) {
debug("msgUnread is undefined");
msgUnread = msgs.getMessages().filter(m => m.new && !['call', 'map', 'music'].includes(m.id)).map(m => m.src).length;
}
return msgUnread;
}

var msgCounter = function(type, msg) {
var msgsNow = msgs.getMessages(msg);
msgUnread = msgsNow.filter(m => m.new && !['call', 'map', 'music'].includes(m.id)).map(m => m.src).length;
kamilkrz marked this conversation as resolved.
Show resolved Hide resolved
if (msgUnread === undefined) {
msgUnread = "?";
}
msgAll = msgsNow.filter(m => !['call', 'map', 'music'].includes(m.id)).map(m => m.src).length;
if (msgAll === undefined) {
kamilkrz marked this conversation as resolved.
Show resolved Hide resolved
msgAll = "?";
}
info.items[0].emit("redraw");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens here if items[1] is being displayed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need some guidance - is there a chance to have context here about current CI is being shown? I don't like idea of refreshing all CI modules but in my opinion its best place to do it here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure - what we have is good, the bangle health clkinfo is similar:

function batteryUpdateHandler() { bangleItems[0].emit("redraw"); }
function stepUpdateHandler() { bangleItems[1].emit("redraw"); }

If you wanted, you could change the show function to note down which clkinfo is visible, then msgCounter could call .emit("redraw") on that, but I think what you have is fine

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge, but feel free to open another PR if you want to tweak it :)

}

var info = {
name: "Messages",
img: unreadImg(),
items: [
{ name : "Unread",
get : () => {
return {
text : getUnreadMGS(),
img : unreadImg()
};
},
show : function() {
Bangle.on("message", msgCounter);
},
hide : function() {
Bangle.removeListener("message", msgCounter);
},
run : () => {
require("messages").openGUI();
}
},
{ name : "All",
get : () => {
return {
text : getAllMGS(),
img : allImg() // TODO This is omited if category image is not set
};
},
show : function() {
Bangle.on("message", msgCounter);
},
hide : function() {
Bangle.removeListener("message", msgCounter);
},
run : () => {
require("messages").openGUI();
}
}
]
};
return info;
})
15 changes: 15 additions & 0 deletions apps/clkinfomsg/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ "id": "clkinfomsg",
"name": "Messages Clockinfo",
"version":"0.01",
"description": "For clocks that display 'clockinfo', this displays the messages count",
"icon": "app.png",
"type": "clkinfo",
"screenshots": [{"url":"screenshot.png"}],
"readme":"README.md",
"tags": "clkinfo",
"supports" : ["BANGLEJS2"],
"dependencies" : { "messages":"app" },
"storage": [
{"name":"clkinfomsg.clkinfo.js","url":"clkinfo.js"}
]
}
Binary file added apps/clkinfomsg/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading