fix: background fetch crashing android app

This commit is contained in:
Rainer Killinger
2022-09-30 08:25:00 +00:00
parent 2ddffe6d4f
commit 3316ad9169
10 changed files with 83 additions and 67 deletions

View File

@@ -20,8 +20,7 @@ import moment, {duration, Moment, unitOfTime} from 'moment';
import {Dialog} from '@capacitor/dialog';
import {CalendarInfo} from './calendar-info';
import {Subject} from 'rxjs';
const CALENDAR_NAME = 'StApps';
import {ConfigProvider} from '../config/config.provider';
const RECURRENCE_PATTERNS: Partial<
Record<unitOfTime.Diff, string | undefined>
@@ -38,15 +37,23 @@ export class CalendarService {
goToDateClicked = this.goToDate.asObservable();
calendarName = 'StApps';
// eslint-disable-next-line @typescript-eslint/no-empty-function
constructor(readonly calendar: Calendar) {}
constructor(
readonly calendar: Calendar,
private readonly configProvider: ConfigProvider,
) {
this.calendarName =
(this.configProvider.getValue('name') as string) ?? 'StApps';
}
async createCalendar(): Promise<CalendarInfo | undefined> {
await this.calendar.createCalendar({
calendarName: CALENDAR_NAME,
calendarName: this.calendarName,
calendarColor: '#ff8740',
});
return this.findCalendar(CALENDAR_NAME);
return this.findCalendar(this.calendarName);
}
async listCalendars(): Promise<CalendarInfo[] | undefined> {
@@ -60,8 +67,8 @@ export class CalendarService {
}
async purge(): Promise<CalendarInfo | undefined> {
if (await this.findCalendar(CALENDAR_NAME)) {
await this.calendar.deleteCalendar(CALENDAR_NAME);
if (await this.findCalendar(this.calendarName)) {
await this.calendar.deleteCalendar(this.calendarName);
}
return await this.createCalendar();
}