Resolve "Error: Database not created"

This commit is contained in:
Thea Schöbl
2022-02-23 14:58:33 +00:00
parent 75f4644940
commit aabb29ad05
5 changed files with 50 additions and 27 deletions

View File

@@ -13,9 +13,33 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {StorageProvider} from '../../storage/storage.provider';
export const CALENDAR_SYNC_SETTINGS_KEY = 'calendarSettings';
export const CALENDAR_SYNC_ENABLED_KEY = 'sync';
export const CALENDAR_NOTIFICATIONS_ENABLED_KEY = 'notifications';
export type CALENDAR_SYNC_KEYS =
| typeof CALENDAR_SYNC_ENABLED_KEY
| typeof CALENDAR_NOTIFICATIONS_ENABLED_KEY;
/**
*
*/
export async function getCalendarSetting(
storageProvider: StorageProvider,
key: CALENDAR_SYNC_KEYS,
defaultValue = false,
): Promise<boolean> {
try {
return await storageProvider.get<boolean>(calendarSettingStorageKey(key));
} catch {
return defaultValue;
}
}
/**
*
*/
export function calendarSettingStorageKey(key: string): string {
return `${CALENDAR_SYNC_SETTINGS_KEY}.${key}`;
}

View File

@@ -33,7 +33,8 @@ import {
CALENDAR_NOTIFICATIONS_ENABLED_KEY,
CALENDAR_SYNC_ENABLED_KEY,
CALENDAR_SYNC_KEYS,
CALENDAR_SYNC_SETTINGS_KEY,
calendarSettingStorageKey,
getCalendarSetting,
} from './calendar-sync-settings-keys';
@Component({
@@ -71,10 +72,11 @@ export class CalendarSyncSettingsComponent implements OnInit {
);
}
async getSetting(key: CALENDAR_SYNC_KEYS) {
return (await this.storageProvider.get(
`${CALENDAR_SYNC_SETTINGS_KEY}.${key}`,
)) as boolean;
async getSetting(
key: CALENDAR_SYNC_KEYS,
defaultValue = false,
): Promise<boolean> {
return getCalendarSetting(this.storageProvider, key, defaultValue);
}
async syncCalendar(sync: boolean) {
@@ -98,10 +100,7 @@ export class CalendarSyncSettingsComponent implements OnInit {
async setSetting(settings: Partial<Record<CALENDAR_SYNC_KEYS, boolean>>) {
await Promise.all(
map(settings, (setting, key) =>
this.storageProvider.put(
`${CALENDAR_SYNC_SETTINGS_KEY}.${key}`,
setting,
),
this.storageProvider.put(calendarSettingStorageKey(key), setting),
),
);