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

@@ -28,6 +28,8 @@ export class AboutPageComponent implements OnInit {
version = packageJson.version;
appName: string;
constructor(
private readonly route: ActivatedRoute,
private readonly configProvider: ConfigProvider,
@@ -35,7 +37,7 @@ export class AboutPageComponent implements OnInit {
async ngOnInit() {
const route = this.route.snapshot.url.map(it => it.path).join('/');
this.appName = (this.configProvider.getValue('name') as string) ?? 'StApps';
this.content =
(
this.configProvider.getValue(

View File

@@ -29,7 +29,7 @@
</ion-toolbar>
</ion-header>
<ion-content *ngIf="content">
<pre>StApps v{{ version }}</pre>
<pre>{{ appName }} v{{ version }}</pre>
<about-page-content
*ngFor="let element of content.content"
[content]="element"

View File

@@ -92,8 +92,7 @@ export class ScheduleSyncService implements OnDestroy {
const status = await BackgroundFetch.configure(
{
minimumFetchInterval: 15,
stopOnTerminate: false,
enableHeadless: true,
requiredNetworkType: 1,
},
async taskId => {
await Promise.all([

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();
}

View File

@@ -44,6 +44,12 @@
'settings.calendar.sync.syncWithCalendar' | translate
}}</ion-label>
</ion-item>
<!--
~ TODO:
~ background fetch is too unreliable to suggest our users that
~ they'll get a notification upon change of event/dateseries.
~ This has to be a highly reliable service notifing users via APN/GCM.
<ion-item>
<ion-toggle
[disabled]="isWeb"
@@ -59,6 +65,7 @@
'settings.calendar.sync.eventNotifications' | translate
}}</ion-label>
</ion-item>
-->
<ion-item>
<ion-button
[disabled]="isWeb || !syncEnabled"