Add capacitor
This commit is contained in:
20
src/core/CapacitorStorage.js
Normal file
20
src/core/CapacitorStorage.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Preferences } from '@capacitor/preferences'
|
||||
|
||||
const CONFIG_KEY = 'app_config'
|
||||
|
||||
export function createCapacitorStorage() {
|
||||
return {
|
||||
async load() {
|
||||
const { value } = await Preferences.get({ key: CONFIG_KEY })
|
||||
return value ? JSON.parse(value) : null
|
||||
},
|
||||
async save(data) {
|
||||
await Preferences.set({
|
||||
key: CONFIG_KEY,
|
||||
value: JSON.stringify(data),
|
||||
})
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export default createCapacitorStorage
|
||||
@@ -42,6 +42,9 @@ const initConfigManager = async (runtime, pluginManager) => {
|
||||
storage = createNodeStorage(filesystemPlugin)
|
||||
} else if (runtime === 'web') {
|
||||
storage = createWebStorage()
|
||||
} else if (runtime === 'capacitor') {
|
||||
const { createCapacitorStorage } = await import('./CapacitorStorage.js')
|
||||
storage = createCapacitorStorage()
|
||||
}
|
||||
|
||||
return createConfigManager(storage, pluginManager)
|
||||
|
||||
Reference in New Issue
Block a user