From 5fe942446b5b85144516cf3f1ae6cc3715b5ca38 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Thu, 2 Dec 2021 21:54:53 +0800 Subject: [PATCH 01/12] Update app.js --- apps/authentiwatch/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index 85c76b5d1..b3240ddbb 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -235,7 +235,7 @@ function draw() { function onTouch(zone, e) { if (e) { var id = Math.floor((state.listy + (e.y - Bangle.appRect.y)) / tokenentryheight); - if (id == state.curtoken || tokens.length == 0) { + if (id == state.curtoken || tokens.length == 0 || id >= tokens.length) { id = -1; } if (state.curtoken != id) { From d7ec86b716aaaf90d72c758307c0eb31a7ca3c28 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Thu, 2 Dec 2021 21:56:36 +0800 Subject: [PATCH 02/12] Authentiwatch: version 0.04 --- apps.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps.json b/apps.json index 877218135..2af3ab133 100644 --- a/apps.json +++ b/apps.json @@ -4434,7 +4434,7 @@ "shortName": "AuthWatch", "icon": "app.png", "screenshots": [{"url":"screenshot.png"}], - "version": "0.03", + "version": "0.04", "description": "Google Authenticator compatible tool.", "tags": "tool", "interface": "interface.html", From 5856db39e4671807fcf09197d5d65784d669c87f Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Thu, 2 Dec 2021 21:58:13 +0800 Subject: [PATCH 03/12] Update ChangeLog --- apps/authentiwatch/ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/authentiwatch/ChangeLog b/apps/authentiwatch/ChangeLog index 50cf3fcea..1a7b5ee5e 100644 --- a/apps/authentiwatch/ChangeLog +++ b/apps/authentiwatch/ChangeLog @@ -1,3 +1,4 @@ +0.04: Fix tapping at very bottom of list 0.03: Add "Calculating" placeholder, update JSON save format 0.02: Fix JSON save format 0.01: First release From 257e73d8691d03597d4abce34516c90d9610af4f Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Thu, 2 Dec 2021 23:11:58 +0800 Subject: [PATCH 04/12] Update ChangeLog --- apps/authentiwatch/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/authentiwatch/ChangeLog b/apps/authentiwatch/ChangeLog index 1a7b5ee5e..294d680be 100644 --- a/apps/authentiwatch/ChangeLog +++ b/apps/authentiwatch/ChangeLog @@ -1,4 +1,4 @@ -0.04: Fix tapping at very bottom of list +0.04: Fix tapping at very bottom of list, inactivity exits to clock 0.03: Add "Calculating" placeholder, update JSON save format 0.02: Fix JSON save format 0.01: First release From e7dcd59295ae770057f26780a096aea4de945e8b Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Thu, 2 Dec 2021 23:55:46 +0800 Subject: [PATCH 05/12] Exit to clock on inactivity --- apps/authentiwatch/app.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index b3240ddbb..9ed1abff5 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -164,6 +164,10 @@ function drawToken(id, r) { function draw() { var d = new Date(); + if (state.idletimer) { + clearTimeout(state.idletimer); + } + state.idletimer = setTimeout(_=>load(), 10000); if (state.curtoken != -1) { var t = tokens[state.curtoken]; if (state.otp == calculating) { @@ -203,7 +207,8 @@ function draw() { y += tokenentryheight; } if (drewcur) { - // the current token has been drawn - draw it again in 1sec + // the current token has been drawn - schedule a redraw + clearTimeout(state.idletimer); if (state.drawtimer) { clearTimeout(state.drawtimer); } From c537d5c5f775051dc4dad030ac9c059c622d188f Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 3 Dec 2021 00:06:30 +0800 Subject: [PATCH 06/12] Touch resets idle timeout --- apps/authentiwatch/app.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index 9ed1abff5..e399b3e3b 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -110,6 +110,13 @@ var state = { hide:0 }; +function resetIdle() { + if (state.idletimer) { + clearTimeout(state.idletimer); + } + state.idletimer = setTimeout(_=>load(), 10000); +} + function drawToken(id, r) { var x1 = r.x; var y1 = r.y; @@ -164,10 +171,7 @@ function drawToken(id, r) { function draw() { var d = new Date(); - if (state.idletimer) { - clearTimeout(state.idletimer); - } - state.idletimer = setTimeout(_=>load(), 10000); + resetIdle(); if (state.curtoken != -1) { var t = tokens[state.curtoken]; if (state.otp == calculating) { @@ -238,6 +242,7 @@ function draw() { } function onTouch(zone, e) { + resetIdle(); if (e) { var id = Math.floor((state.listy + (e.y - Bangle.appRect.y)) / tokenentryheight); if (id == state.curtoken || tokens.length == 0 || id >= tokens.length) { @@ -265,6 +270,7 @@ function onTouch(zone, e) { } function onDrag(e) { + resetIdle(); if (e.x > g.getWidth() || e.y > g.getHeight()) return; if (e.dx == 0 && e.dy == 0) return; var newy = Math.min(state.listy - e.dy, tokens.length * tokenentryheight - Bangle.appRect.h); @@ -276,6 +282,7 @@ function onDrag(e) { } function onSwipe(e) { + resetIdle(); if (e == 1) { Bangle.showLauncher(); } @@ -291,6 +298,7 @@ function onSwipe(e) { } function bangle1Btn(e) { + resetIdle(); if (tokens.length > 0) { if (state.curtoken == -1) { state.curtoken = state.prevcur; From a75b58df70b1aaf84bd0ba68d1cfe0b2950a94f5 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 3 Dec 2021 12:02:31 +0800 Subject: [PATCH 07/12] Rework idle timeout. --- apps/authentiwatch/app.js | 50 ++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index e399b3e3b..01b30a913 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -110,13 +110,6 @@ var state = { hide:0 }; -function resetIdle() { - if (state.idletimer) { - clearTimeout(state.idletimer); - } - state.idletimer = setTimeout(_=>load(), 10000); -} - function drawToken(id, r) { var x1 = r.x; var y1 = r.y; @@ -153,14 +146,14 @@ function drawToken(id, r) { // counter - draw triangle as swipe hint let yc = (y1 + y2) / 2; g.fillPoly([0, yc, 10, yc - 10, 10, yc + 10, 0, yc]); - adj = 5; + adj = 10; } // digits just below label sz = 30; do { g.setFont("Vector", sz--); } while (g.stringWidth(state.otp) > (r.w - adj)); - g.drawString(state.otp, (x1 + x2) / 2 + adj, y1 + 16, false); + g.drawString(state.otp, (x1 + adj + x2) / 2, y1 + 16, false); } // shaded lines top and bottom g.setColor(0.5, 0.5, 0.5); @@ -170,6 +163,8 @@ function drawToken(id, r) { } function draw() { + var timerfn = load; + var timerdly = 10000; var d = new Date(); resetIdle(); if (state.curtoken != -1) { @@ -216,13 +211,12 @@ function draw() { if (state.drawtimer) { clearTimeout(state.drawtimer); } - var dly; if (tokens[state.curtoken].period > 0) { - dly = (state.otp == calculating) ? 1 : 1000; + timerdly = (state.otp == calculating) ? 1 : 1000; // timed } else { - dly = state.nexttime - d.getTime(); + timerdly = state.nexttime - d.getTime(); // counter } - state.drawtimer = setTimeout(draw, dly); + timerfn = draw; if (tokens[state.curtoken].period <= 0) { state.hide = 0; } @@ -239,10 +233,13 @@ function draw() { g.setFontAlign(0, 0, 0); g.drawString(notokens, Bangle.appRect.x + Bangle.appRect.w / 2, Bangle.appRect.y + Bangle.appRect.h / 2, false); } + if (state.drawtimer) { + clearTimeout(state.drawtimer); + } + state.drawtimer = setTimeout(timerfn, timerdly); } function onTouch(zone, e) { - resetIdle(); if (e) { var id = Math.floor((state.listy + (e.y - Bangle.appRect.y)) / tokenentryheight); if (id == state.curtoken || tokens.length == 0 || id >= tokens.length) { @@ -264,28 +261,20 @@ function onTouch(zone, e) { state.nextTime = 0; state.curtoken = id; state.hide = 2; - draw(); } } + draw(); } function onDrag(e) { - resetIdle(); if (e.x > g.getWidth() || e.y > g.getHeight()) return; if (e.dx == 0 && e.dy == 0) return; var newy = Math.min(state.listy - e.dy, tokens.length * tokenentryheight - Bangle.appRect.h); - newy = Math.max(0, newy); - if (newy != state.listy) { - state.listy = newy; - draw(); - } + state.listy = Math.max(0, newy); + draw(); } function onSwipe(e) { - resetIdle(); - if (e == 1) { - Bangle.showLauncher(); - } if (e == -1 && state.curtoken != -1 && tokens[state.curtoken].period <= 0) { tokens[state.curtoken].period--; let newsettings={tokens:tokens,misc:settings.misc}; @@ -293,12 +282,11 @@ function onSwipe(e) { state.nextTime = 0; state.otp = ""; state.hide = 2; - draw(); } + draw(); } function bangle1Btn(e) { - resetIdle(); if (tokens.length > 0) { if (state.curtoken == -1) { state.curtoken = state.prevcur; @@ -315,6 +303,8 @@ function bangle1Btn(e) { state.curtoken = -1; state.nextTime = 0; onTouch(0, fakee); + } else { + draw(); // resets idle timer } } @@ -322,9 +312,9 @@ Bangle.on('touch', onTouch); Bangle.on('drag' , onDrag ); Bangle.on('swipe', onSwipe); if (typeof BTN2 == 'number') { - setWatch(function(){bangle1Btn(-1); }, BTN1, {edge:"rising", debounce:50, repeat:true}); - setWatch(function(){Bangle.showLauncher();}, BTN2, {edge:"rising", debounce:50, repeat:true}); - setWatch(function(){bangle1Btn( 1); }, BTN3, {edge:"rising", debounce:50, repeat:true}); + setWatch(function(){bangle1Btn(-1);}, BTN1, {edge:"rising", debounce:50, repeat:true}); + setWatch(function(){load(); }, BTN2, {edge:"rising", debounce:50, repeat:true}); + setWatch(function(){bangle1Btn( 1);}, BTN3, {edge:"rising", debounce:50, repeat:true}); } Bangle.loadWidgets(); From 517ff25fc24f586cc7c0334fc9de503a2163e195 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 3 Dec 2021 12:07:26 +0800 Subject: [PATCH 08/12] Update app.js --- apps/authentiwatch/app.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index 01b30a913..6fee5f3ea 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -166,7 +166,6 @@ function draw() { var timerfn = load; var timerdly = 10000; var d = new Date(); - resetIdle(); if (state.curtoken != -1) { var t = tokens[state.curtoken]; if (state.otp == calculating) { From 36ae60a81a2e5492ebaf04c35fb8b24c28f64e01 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 3 Dec 2021 12:15:44 +0800 Subject: [PATCH 09/12] Update app.js --- apps/authentiwatch/app.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index 6fee5f3ea..b0ff24c75 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -206,10 +206,6 @@ function draw() { } if (drewcur) { // the current token has been drawn - schedule a redraw - clearTimeout(state.idletimer); - if (state.drawtimer) { - clearTimeout(state.drawtimer); - } if (tokens[state.curtoken].period > 0) { timerdly = (state.otp == calculating) ? 1 : 1000; // timed } else { From 184a57ef4251029fa1daa18e259b27e3e5ec3663 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 3 Dec 2021 12:24:46 +0800 Subject: [PATCH 10/12] Update app.js --- apps/authentiwatch/app.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index b0ff24c75..2c6d09619 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -10,6 +10,8 @@ const calculating = "Calculating"; const notokens = "No tokens"; const notsupported = "Not supported"; +// sample settings: +// {tokens:[{"algorithm":"SHA1","digits":6,"period":30,"issuer":"","account":"","secret":"Bbb","label":"Aaa"}],misc:{}} var settings = require("Storage").readJSON("authentiwatch.json", true) || {tokens:[],misc:{}}; if (settings.data ) tokens = settings.data ; /* v0.02 settings */ if (settings.tokens) tokens = settings.tokens; /* v0.03+ settings */ From 77967c037e3793f38f2634554a4c3b616c47867f Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 3 Dec 2021 22:39:39 +0800 Subject: [PATCH 11/12] Update app.js --- apps/authentiwatch/app.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/authentiwatch/app.js b/apps/authentiwatch/app.js index 2c6d09619..c0cb608c0 100644 --- a/apps/authentiwatch/app.js +++ b/apps/authentiwatch/app.js @@ -165,7 +165,7 @@ function drawToken(id, r) { } function draw() { - var timerfn = load; + var timerfn = exitApp; var timerdly = 10000; var d = new Date(); if (state.curtoken != -1) { @@ -305,12 +305,16 @@ function bangle1Btn(e) { } } +function exitApp() { + Bangle.showLauncher(); +} + Bangle.on('touch', onTouch); Bangle.on('drag' , onDrag ); Bangle.on('swipe', onSwipe); if (typeof BTN2 == 'number') { setWatch(function(){bangle1Btn(-1);}, BTN1, {edge:"rising", debounce:50, repeat:true}); - setWatch(function(){load(); }, BTN2, {edge:"rising", debounce:50, repeat:true}); + setWatch(function(){exitApp(); }, BTN2, {edge:"rising", debounce:50, repeat:true}); setWatch(function(){bangle1Btn( 1);}, BTN3, {edge:"rising", debounce:50, repeat:true}); } Bangle.loadWidgets(); From 5c1798b82483898323a1a7573524ddc47e88c13a Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Fri, 3 Dec 2021 22:42:33 +0800 Subject: [PATCH 12/12] Update ChangeLog --- apps/authentiwatch/ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/authentiwatch/ChangeLog b/apps/authentiwatch/ChangeLog index 294d680be..e1b8ed5bc 100644 --- a/apps/authentiwatch/ChangeLog +++ b/apps/authentiwatch/ChangeLog @@ -1,4 +1,4 @@ -0.04: Fix tapping at very bottom of list, inactivity exits to clock +0.04: Fix tapping at very bottom of list, exit on inactivity 0.03: Add "Calculating" placeholder, update JSON save format 0.02: Fix JSON save format 0.01: First release