refactor: improve device interface types (#996)

This commit is contained in:
Mo
2022-04-22 13:54:34 -05:00
committed by GitHub
parent 68ad0f17ae
commit abb85b3f11
22 changed files with 296 additions and 235 deletions

View File

@@ -0,0 +1,26 @@
import { Environment, RawKeychainValue } from '@standardnotes/snjs'
import { WebOrDesktopDevice } from '@/Device/WebOrDesktopDevice'
const KEYCHAIN_STORAGE_KEY = 'keychain'
export class WebDevice extends WebOrDesktopDevice {
environment = Environment.Web
async getKeychainValue(): Promise<RawKeychainValue> {
const value = localStorage.getItem(KEYCHAIN_STORAGE_KEY)
if (value) {
return JSON.parse(value)
}
return {}
}
async setKeychainValue(value: RawKeychainValue): Promise<void> {
localStorage.setItem(KEYCHAIN_STORAGE_KEY, JSON.stringify(value))
}
async clearRawKeychainValue(): Promise<void> {
localStorage.removeItem(KEYCHAIN_STORAGE_KEY)
}
}