TOTPFit/page/index.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

2025-02-26 00:33:40 +03:00
import { RenderAddButton } from "./render/totpRenderer";
import { initLoop } from "./render/index/renderer";
import { BasePage } from "@zeppos/zml/base-page";
2025-02-26 01:58:11 +03:00
import { LocalStorage } from "@zos/storage";
2025-02-26 00:33:40 +03:00
const app = getApp();
2025-02-26 01:58:11 +03:00
let waitForFetch = true;
let localStorage = new LocalStorage();
2025-02-26 01:58:11 +03:00
Page(
2025-02-26 00:33:40 +03:00
BasePage({
onInit() {
this.getTOTPData()
.then((x) => {
2025-02-26 01:58:11 +03:00
app._options.globalData.TOTPS = JSON.parse(x) ?? [];
localStorage.setItem(
"TOTPs",
JSON.stringify(app._options.globalData.TOTPS)
);
2025-02-26 00:33:40 +03:00
this.initPage();
})
.catch((x) => {
2025-02-26 01:58:11 +03:00
console.log(`Init failed: ${x}`);
app._options.globalData.TOTPS = JSON.parse(
localStorage.getItem("TOTPs", null) ?? []
);
2025-02-26 00:33:40 +03:00
this.initPage();
});
},
build() {
let fetch = setInterval(() => {
if (waitForFetch) return;
2025-02-26 00:33:40 +03:00
clearInterval(fetch);
const buffer = app._options.globalData.TOTPS;
if (buffer.length < 1) {
RenderAddButton("page/tip");
} else {
initLoop(buffer);
}
}, 100);
},
initPage() {
waitForFetch = false;
},
getTOTPData() {
return this.request({
method: "totps",
});
},
})
);