feat(staging): added transfer for data from settings app(part 2)
This commit is contained in:
parent
f21678b219
commit
3b2e4992a3
@ -1,13 +1,16 @@
|
||||
import { BaseSideService } from "@zeppos/zml/base-side"
|
||||
|
||||
AppSideService(
|
||||
BaseSideService(
|
||||
{
|
||||
onInit(){
|
||||
settings.settingsStorage.addListener('change', async ({ key, newValue, oldValue }) => {
|
||||
console.log(key)
|
||||
console.log(newValue)
|
||||
const totps = settings.settingsStorage.getItem('TOTPs')
|
||||
const dataBuffer = Buffer.from(totps)
|
||||
messaging.peerSocket.send(dataBuffer.buffer)
|
||||
})
|
||||
|
||||
},
|
||||
onRequest(req, res){
|
||||
if(req.method === 'totps'){
|
||||
res(null, settings.settingsStorage.getItem('TOTPs'))
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
36
app.js
36
app.js
@ -1,25 +1,15 @@
|
||||
import { BaseApp } from "@zeppos/zml/base-app"
|
||||
import { TOTP } from "./lib/totp-quickjs"
|
||||
import { LocalStorage } from "@zos/storage"
|
||||
|
||||
const localStorage = new LocalStorage()
|
||||
App({
|
||||
globalData: {
|
||||
TOTPS: localStorage.getItem('TOTPs') || []
|
||||
},
|
||||
onCreate(options) {
|
||||
// localStorage.setItem('TOTPs', [
|
||||
// new TOTP('JBSWY3DPEHPK3PXP', 'totp.danhersam.com', 'I1122222222', 6, 30, 0, 'SHA-1'),
|
||||
// new TOTP('JBSWY3DPEHPK3PXP', 'totp.danhersam.com', 'I2', 6, 30, 5, 'SHA-1'),
|
||||
// new TOTP('JBSWY3DPEHPK3PXP', 'totp.danhersam.com', 'I3', 6, 30, -5, 'SHA-1'),
|
||||
// new TOTP('JBSWY3DPEHPK3PXP', 'totp.danhersam.com', 'I4', 6, 30, 0, 'SHA-1'),
|
||||
// new TOTP('JBSWY3DPEHPK3PXP', 'totp.danhersam.com', 'I5', 6, 30, 0, 'SHA-1'),
|
||||
// new TOTP('JBSWY3DPEHPK3PXP', 'totp.danhersam.com', 'I6', 6, 30, 0, 'SHA-1'),
|
||||
// new TOTP('JBSWY3DPEHPK3PXP', 'totp.danhersam.com', 'I7', 6, 30, 0, 'SHA-1'),
|
||||
// new TOTP('JBSWY3DPEHPK3PXP', 'totp.danhersam.com', 'I8', 6, 30, 0, 'SHA-1')
|
||||
// ])
|
||||
},
|
||||
|
||||
onDestroy(options) {
|
||||
console.log('app on destroy invoke')
|
||||
}
|
||||
})
|
||||
App(
|
||||
BaseApp(
|
||||
{
|
||||
globalData: {
|
||||
TOTPS: []
|
||||
},
|
||||
onCreate() {
|
||||
},
|
||||
onDestroy() {
|
||||
}
|
||||
})
|
||||
)
|
6
app.json
6
app.json
@ -18,9 +18,9 @@
|
||||
],
|
||||
"runtime": {
|
||||
"apiVersion": {
|
||||
"compatible": "3.5.0",
|
||||
"target": "3.5.0",
|
||||
"minVersion": "3.5"
|
||||
"compatible": "3.0.0",
|
||||
"target": "3.0.0",
|
||||
"minVersion": "3.0"
|
||||
}
|
||||
},
|
||||
"targets": {
|
||||
|
@ -1,23 +1,47 @@
|
||||
import { setStatusBarVisible } from '@zos/ui'
|
||||
import { RenderAddButton } from './render/totpRenderer'
|
||||
import { initLoop } from './render/index/renderer'
|
||||
import { BasePage } from '@zeppos/zml/base-page'
|
||||
import { LocalStorage } from "@zos/storage"
|
||||
|
||||
const localStorage = new LocalStorage()
|
||||
const app = getApp()
|
||||
let waitForFetch = true;
|
||||
Page(
|
||||
BasePage({
|
||||
onInit() {
|
||||
this.getTOTPData().then((x) => {
|
||||
console.log(x)
|
||||
localStorage.setItem('TOTPs', x)
|
||||
app._options.globalData.TOTPS = x
|
||||
this.initPage();
|
||||
})
|
||||
.catch((x) => {
|
||||
app._options.globalData.TOTPS = localStorage.getItem('TOTPs')
|
||||
this.initPage()
|
||||
})
|
||||
},
|
||||
build() {
|
||||
let fetch = setInterval(() => {
|
||||
if(waitForFetch)
|
||||
return;
|
||||
|
||||
Page({
|
||||
onInit() {
|
||||
//If app has no saved TOTPs
|
||||
if (app._options.globalData.TOTPS.length < 1)
|
||||
setStatusBarVisible(true)
|
||||
else
|
||||
setStatusBarVisible(false)
|
||||
},
|
||||
build() {
|
||||
const buffer = app._options.globalData.TOTPS
|
||||
if (buffer.length < 1)
|
||||
RenderAddButton('page/tip')
|
||||
else{
|
||||
initLoop(buffer)
|
||||
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'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
@ -1,6 +1,6 @@
|
||||
import { deleteWidget, prop } from "@zos/ui";
|
||||
import { prop } from "@zos/ui";
|
||||
import { TOTP } from "../../../lib/totp-quickjs";
|
||||
import { RenderAddButton, RenderExpireBar, RenderOTPValue, RenderTOTPContainer } from '../totpRenderer'
|
||||
import { RenderExpireBar, RenderOTPValue, RenderTOTPContainer } from '../totpRenderer'
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -12,6 +12,7 @@ const containerRadius = 20 //Corner radius of container
|
||||
|
||||
const textColor = 0xa0a0a0 //Color of TOTP description text
|
||||
const textSize = 24 //Size of TOTP description text
|
||||
const statusBarPading = 65
|
||||
|
||||
/** Function for render box container for TOTP values
|
||||
*
|
||||
@ -112,4 +113,4 @@ export function RenderAddButton(pagePath) {
|
||||
})
|
||||
}
|
||||
|
||||
function getYPos(position) { return position * (buttonHeight + 10) }
|
||||
function getYPos(position) { return position * (buttonHeight + 10) + statusBarPading }
|
49
page/tip.js
49
page/tip.js
@ -2,27 +2,30 @@ import { createWidget, widget, align } from "@zos/ui";
|
||||
import { getDeviceInfo } from "@zos/device";
|
||||
import { onGesture, GESTURE_LEFT } from '@zos/interaction'
|
||||
import { back } from "@zos/router";
|
||||
Page({
|
||||
onInit(){
|
||||
onGesture({
|
||||
callback(event) {
|
||||
if(event === GESTURE_LEFT){
|
||||
back()
|
||||
import { BasePage } from "@zeppos/zml/base-page";
|
||||
Page(
|
||||
BasePage({
|
||||
onInit() {
|
||||
onGesture({
|
||||
callback(event) {
|
||||
if (event === GESTURE_LEFT) {
|
||||
back()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
build() {
|
||||
const {width, height} = getDeviceInfo()
|
||||
createWidget(widget.TEXT, {
|
||||
x: 0,
|
||||
w: width,
|
||||
h: height,
|
||||
color: 0xffffff,
|
||||
text_size: 30,
|
||||
align_h: align.CENTER_H,
|
||||
align_v: align.CENTER_V,
|
||||
text: 'To add TOTP record open\n settings on Zepp app'
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
build() {
|
||||
const { width, height } = getDeviceInfo()
|
||||
createWidget(widget.TEXT, {
|
||||
x: 0,
|
||||
w: width,
|
||||
h: height,
|
||||
color: 0xffffff,
|
||||
text_size: 30,
|
||||
align_h: align.CENTER_H,
|
||||
align_v: align.CENTER_V,
|
||||
text: 'To add TOTP record open\n settings on Zepp app'
|
||||
})
|
||||
}
|
||||
})
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user