2022-01-03 23:44:48 +00:00
WIDGETS [ "messages" ] = { area : "tl" , width : 0 , ICONS : [ atob ( "GBiBAAAAAAAAAAAAAAAAAAAAAB//+DAADDAADDAADDwAPD8A/DOBzDDn/DA//DAHvDAPvjAPvjAPvjAPvh///gf/vAAD+AAB8AAAAA==" ) , atob ( "GBiBAAAAAAAAAAAAAAAAAAAAAB//+D///D///A//8CP/xDj/HD48DD+B8D/D+D/3vD/vvj/vvj/vvj/vvh/v/gfnvAAD+AAB8AAAAA==" ) ] , //icons should be equal size or first larger
draw : function ( ) {
2021-12-09 19:54:39 +00:00
Bangle . removeListener ( 'touch' , this . touch ) ;
2021-10-22 10:47:23 +00:00
if ( ! this . width ) return ;
var c = ( Date . now ( ) - this . t ) / 1000 ;
2022-01-03 23:44:48 +00:00
g . reset ( ) . clearRect ( this . x , this . y , this . x + this . width , this . y + this . ICONS [ 0 ] . charCodeAt ( 1 ) ) ;
g . drawImage ( this . ICONS [ c & 1 ] , this . x , this . y ) ;
2021-10-22 10:47:23 +00:00
//if (c<60) Bangle.setLCDPower(1); // keep LCD on for 1 minute
2021-11-25 15:50:07 +00:00
let settings = require ( 'Storage' ) . readJSON ( "messages.settings.json" , true ) || { } ;
if ( settings . repeat === undefined ) settings . repeat = 4 ;
if ( c < 120 && ( Date . now ( ) - this . l ) > settings . repeat * 1000 ) {
2021-10-22 10:47:23 +00:00
this . l = Date . now ( ) ;
2021-11-25 15:50:07 +00:00
WIDGETS [ "messages" ] . buzz ( ) ; // buzz every 4 seconds
2021-10-22 10:47:23 +00:00
}
setTimeout ( ( ) => WIDGETS [ "messages" ] . draw ( ) , 1000 ) ;
2021-12-09 19:54:39 +00:00
if ( process . env . HWVERSION > 1 ) Bangle . on ( 'touch' , this . touch ) ;
2021-12-06 14:27:11 +00:00
} , show : function ( quiet ) {
2021-10-22 10:47:23 +00:00
WIDGETS [ "messages" ] . t = Date . now ( ) ; // first time
WIDGETS [ "messages" ] . l = Date . now ( ) - 10000 ; // last buzz
2021-12-06 14:27:11 +00:00
if ( quiet ) WIDGETS [ "messages" ] . t -= 500000 ; // if quiet, set last time in the past so there is no buzzing
2022-01-03 23:44:48 +00:00
WIDGETS [ "messages" ] . width = this . ICONS [ 0 ] . charCodeAt ( 0 ) ;
2021-10-22 10:47:23 +00:00
Bangle . drawWidgets ( ) ;
Bangle . setLCDPower ( 1 ) ; // turns screen on
2021-11-23 16:28:34 +00:00
} , hide : function ( ) {
delete WIDGETS [ "messages" ] . t ;
delete WIDGETS [ "messages" ] . l ;
WIDGETS [ "messages" ] . width = 0 ;
Bangle . drawWidgets ( ) ;
2021-11-25 15:50:07 +00:00
} , buzz : function ( ) {
let v = ( require ( 'Storage' ) . readJSON ( "messages.settings.json" , true ) || { } ) . vibrate || "." ;
function b ( ) {
var c = v [ 0 ] ;
v = v . substr ( 1 ) ;
if ( c == "." ) Bangle . buzz ( ) . then ( ( ) => setTimeout ( b , 100 ) ) ;
if ( c == "-" ) Bangle . buzz ( 500 ) . then ( ( ) => setTimeout ( b , 100 ) ) ;
}
b ( ) ;
2021-12-09 19:54:39 +00:00
} , touch : function ( b , c ) {
var w = WIDGETS [ "messages" ] ;
2022-01-03 23:44:48 +00:00
if ( ! w || ! w . width || c . x < w . x || c . x > w . x + w . width || c . y < w . y || c . y > w . y + w . ICONS [ 0 ] . charCodeAt ( 1 ) ) return ;
2021-12-09 19:54:39 +00:00
load ( "messages.app.js" ) ;
2021-10-22 10:47:23 +00:00
} } ;
2021-12-06 14:27:11 +00:00
/ * W e m i g h t h a v e r e t u r n e d h e r e i f w e w e r e i n t h e M e s s a g e s a p p f o r 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 ) ;
2022-01-03 23:44:48 +00:00
} ) ( ) ;