55 行
1.7 KiB
TypeScript
55 行
1.7 KiB
TypeScript
|
|
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||
|
|
|
||
|
|
const KEY_TOKEN = '@xuqm:license:token'
|
||
|
|
const KEY_DEVICE_ID = '@xuqm:license:deviceId'
|
||
|
|
const KEY_STATUS = '@xuqm:license:status'
|
||
|
|
const KEY_STATUS_TIME = '@xuqm:license:statusTime'
|
||
|
|
const KEY_APP_KEY = '@xuqm:license:appKey'
|
||
|
|
|
||
|
|
export async function getToken(): Promise<string | null> {
|
||
|
|
return AsyncStorage.getItem(KEY_TOKEN)
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function setToken(token: string | null): Promise<void> {
|
||
|
|
if (token == null) { await AsyncStorage.removeItem(KEY_TOKEN); return }
|
||
|
|
await AsyncStorage.setItem(KEY_TOKEN, token)
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getDeviceId(): Promise<string | null> {
|
||
|
|
return AsyncStorage.getItem(KEY_DEVICE_ID)
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function setDeviceId(id: string): Promise<void> {
|
||
|
|
await AsyncStorage.setItem(KEY_DEVICE_ID, id)
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getStatus(): Promise<string | null> {
|
||
|
|
return AsyncStorage.getItem(KEY_STATUS)
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function setStatus(status: string | null): Promise<void> {
|
||
|
|
if (status == null) { await AsyncStorage.removeItem(KEY_STATUS); return }
|
||
|
|
await AsyncStorage.setItem(KEY_STATUS, status)
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getStatusTime(): Promise<number> {
|
||
|
|
const v = await AsyncStorage.getItem(KEY_STATUS_TIME)
|
||
|
|
return v ? Number(v) : 0
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function setStatusTime(ms: number): Promise<void> {
|
||
|
|
await AsyncStorage.setItem(KEY_STATUS_TIME, String(ms))
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getStoredAppKey(): Promise<string | null> {
|
||
|
|
return AsyncStorage.getItem(KEY_APP_KEY)
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function setStoredAppKey(appKey: string): Promise<void> {
|
||
|
|
await AsyncStorage.setItem(KEY_APP_KEY, appKey)
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function clearAll(): Promise<void> {
|
||
|
|
await AsyncStorage.multiRemove([KEY_TOKEN, KEY_DEVICE_ID, KEY_STATUS, KEY_STATUS_TIME, KEY_APP_KEY])
|
||
|
|
}
|