fix, chore, feat: refactor of settings app, fix of Google Auth migration parse, added rename button(testing), added sort feature, added timeout to screen turning off, formated codes with space between 6-digits codes
Co-authored-by: DemiarUA <demiar97@gmail.com> https://github.com/Lisoveliy/totpfit/pull/1
This commit is contained in:
@@ -2,34 +2,37 @@ import { RenderAddButton } from "./render/totpRenderer";
|
||||
import { initLoop } from "./render/index/renderer";
|
||||
import { BasePage } from "@zeppos/zml/base-page";
|
||||
import { LocalStorage } from "@zos/storage";
|
||||
import { setPageBrightTime } from "@zos/display";
|
||||
|
||||
const app = getApp();
|
||||
|
||||
const brightTimeMs = 300000;
|
||||
|
||||
let waitForFetch = true;
|
||||
|
||||
Page(
|
||||
BasePage({
|
||||
onInit() {
|
||||
setPageBrightTime({ brightTime: brightTimeMs });
|
||||
this.getTOTPData()
|
||||
.then((x) => {
|
||||
app._options.globalData.TOTPS = JSON.parse(x) ?? [];
|
||||
|
||||
|
||||
let localStorage = new LocalStorage();
|
||||
localStorage.setItem(
|
||||
"TOTPs",
|
||||
JSON.stringify(app._options.globalData.TOTPS)
|
||||
JSON.stringify(app._options.globalData.TOTPS),
|
||||
);
|
||||
this.initPage();
|
||||
})
|
||||
.catch((x) => {
|
||||
console.log(`Init failed: ${x}`);
|
||||
try{
|
||||
try {
|
||||
let localStorage = new LocalStorage();
|
||||
app._options.globalData.TOTPS = JSON.parse(
|
||||
localStorage.getItem("TOTPs", [])
|
||||
localStorage.getItem("TOTPs", []),
|
||||
);
|
||||
}
|
||||
catch{
|
||||
} catch {
|
||||
app._options.globalData.TOTPS = [];
|
||||
}
|
||||
this.initPage();
|
||||
@@ -56,5 +59,5 @@ Page(
|
||||
method: "totps",
|
||||
});
|
||||
},
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -22,15 +22,16 @@ function renderContainers(buffer) {
|
||||
}
|
||||
|
||||
const renderData = [];
|
||||
|
||||
function renderTOTPs(buffer) {
|
||||
for (let i = 0; i < buffer.length; i++) {
|
||||
let otpData = TOTP.copy(buffer[i]).getOTP();
|
||||
renderData[i] = {
|
||||
OTP: RenderOTPValue(i, otpData.otp),
|
||||
OTP: RenderOTPValue(i, formatOTP(otpData.otp)),
|
||||
expireBar: RenderExpireBar(
|
||||
i,
|
||||
otpData.createdTime,
|
||||
buffer[i].fetchTime
|
||||
buffer[i].fetchTime,
|
||||
),
|
||||
};
|
||||
setInterval(() => {
|
||||
@@ -38,7 +39,7 @@ function renderTOTPs(buffer) {
|
||||
(Date.now() - otpData.createdTime) /
|
||||
1000 /
|
||||
buffer[i].fetchTime -
|
||||
1
|
||||
1,
|
||||
);
|
||||
|
||||
renderData[i].expireBar.setProperty(prop.MORE, {
|
||||
@@ -49,9 +50,15 @@ function renderTOTPs(buffer) {
|
||||
if (otpData.expireTime < Date.now()) {
|
||||
otpData = TOTP.copy(buffer[i]).getOTP();
|
||||
renderData[i].OTP.setProperty(prop.MORE, {
|
||||
text: otpData.otp,
|
||||
text: formatOTP(otpData.otp),
|
||||
});
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
}
|
||||
|
||||
function formatOTP(otp) {
|
||||
if (otp.length === 6) return `${otp.substring(0, 3)} ${otp.substring(3)}`;
|
||||
|
||||
return otp;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ export function RenderOTPValue(position, otpValue) {
|
||||
export function RenderExpireBar(position, createdTime, fetchTime) {
|
||||
const yPos = getYPos(position);
|
||||
const expireDif = Math.abs(
|
||||
(Date.now() - createdTime) / 1000 / fetchTime - 1
|
||||
(Date.now() - createdTime) / 1000 / fetchTime - 1,
|
||||
);
|
||||
return createWidget(widget.ARC, {
|
||||
x: buttonWidth - 50,
|
||||
|
||||
@@ -27,5 +27,5 @@ Page(
|
||||
text: "To add TOTP record open\n settings on Zepp app",
|
||||
});
|
||||
},
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user