Update app.js

Workaround Bangle1 issues
master
Andrew Gregory 2022-03-20 23:11:18 +08:00 committed by GitHub
parent 1523a15b8e
commit ed36b7286e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 48 deletions

View File

@ -135,8 +135,7 @@ function timerCalc() {
let timerfn = exitApp;
let timerdly = 10000;
let id = state.id;
if (id != -1) {
if (state.hotp.hotp != "") {
if (id != -1 && state.hotp.hotp != "") {
if (tokens[id].period > 0) {
// timed HOTP
if (state.hotp.next < Date.now()) {
@ -164,7 +163,6 @@ function timerCalc() {
timerfn = updateCurrentToken;
}
}
}
if (state.drawtimer) {
clearTimeout(state.drawtimer);
}
@ -183,8 +181,7 @@ function updateProgressBar() {
function drawProgressBar() {
let id = state.id;
if (id != -1) {
if (tokens[id].period > 0) {
if (id != -1 && tokens[id].period > 0) {
let rem = Math.floor((state.hotp.next - Date.now()) / 1000);
if (rem >= 0) {
let y1 = tokenY(id);
@ -208,7 +205,6 @@ function drawProgressBar() {
}
}
}
}
}
// id = token ID number (0...)
@ -265,10 +261,10 @@ function drawToken(id) {
drawProgressBar();
}
}
g.setClipRect(0, 0, g.getWidth(), g.getHeight());
g.setClipRect(0, 0, g.getWidth() - 1, g.getHeight() - 1);
}
function startupDraw() {
function drawAll() {
if (tokens.length > 0) {
let id = 0;
let y = tokenY(id);
@ -391,8 +387,13 @@ function bangle1Btn(e) {
id = E.clip(id, 0, tokens.length - 1);
var fakee = {b:1,x:0,y:0,dx:0};
fakee.dy = state.listy - E.clip(id * TOKEN_HEIGHT - half(AR.h - TOKEN_HEIGHT), 0, tokens.length * TOKEN_HEIGHT - AR.h);
onDrag(fakee);
changeId(id);
//onDrag(fakee);
//changeId(id);
// onDrag() (specifically g.scroll()) doesn't appear to work with the Bangle1
state.id = id;
state.hotp.hotp = CALCULATING;
state.listy -= fakee.dy;
drawAll();
} else {
timerCalc();
}
@ -415,5 +416,5 @@ if (typeof BTN2 == 'number') {
Bangle.loadWidgets();
const AR = Bangle.appRect;
g.clear(); // Clear the screen once, at startup
startupDraw();
drawAll();
Bangle.drawWidgets();