From 5fa5455e0060f1c525d0486432ff9c6186b40b47 Mon Sep 17 00:00:00 2001
From: Savely Savianok <1986developer@gmail.com>
Date: Wed, 26 Feb 2025 01:22:47 +0300
Subject: [PATCH] feat: added local storage for save totp directly on watches

---
 app.json      | 3 ++-
 page/index.js | 8 ++++++--
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/app.json b/app.json
index 128688a..2f24d70 100644
--- a/app.json
+++ b/app.json
@@ -13,7 +13,8 @@
     "description": "TOTP Authenticator for Amazfit devices"
   },
   "permissions": [
-    "data:os.device.info"
+    "data:os.device.info",
+    "device:os.local_storage"
   ],
   "runtime": {
     "apiVersion": {
diff --git a/page/index.js b/page/index.js
index 686e917..73ab370 100644
--- a/page/index.js
+++ b/page/index.js
@@ -1,19 +1,23 @@
 import { RenderAddButton } from "./render/totpRenderer";
 import { initLoop } from "./render/index/renderer";
 import { BasePage } from "@zeppos/zml/base-page";
+import { LocalStorage } from '@zos/storage';
 
 const app = getApp();
 let waitForFetch = true;
+let localStorage = new LocalStorage();
 Page(
     BasePage({
         onInit() {
             this.getTOTPData()
                 .then((x) => {
-                    app._options.globalData.TOTPS = JSON.parse(x) ?? [];
+                    app._options.globalData.TOTPS = JSON.parse(x) ?? []
+                    localStorage.setItem('TOTPs', JSON.stringify(app._options.globalData.TOTPS))
                     this.initPage();
                 })
                 .catch((x) => {
-                    app._options.globalData.TOTPS = [];
+                    console.log(`Init failed: ${x}`)
+                    app._options.globalData.TOTPS = JSON.parse(localStorage.getItem('TOTPs', null) ?? []);
                     this.initPage();
                 });
         },