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,5 +20,6 @@
# hide the original source file name. # hide the original source file name.
#-renamesourcefileattribute SourceFile #-renamesourcefileattribute SourceFile
# Class for seperated android headless background task
# [capacitor-background-fetch] # [capacitor-background-fetch]
-keep class **BackgroundFetchHeadlessTask { *; } #-keep class **BackgroundFetchHeadlessTask { *; }

View File

@@ -61,15 +61,13 @@
<key>UISupportedInterfaceOrientations</key> <key>UISupportedInterfaceOrientations</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array> </array>
<key>UISupportedInterfaceOrientations~ipad</key> <key>UISupportedInterfaceOrientations~ipad</key>
<array> <array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string> <string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array> </array>
<key>UIViewControllerBasedStatusBarAppearance</key> <key>UIViewControllerBasedStatusBarAppearance</key>
<false/> <false/>

View File

@@ -26,6 +26,7 @@ def capacitor_pods
pod 'CapacitorShare', :path => '../../node_modules/@capacitor/share' pod 'CapacitorShare', :path => '../../node_modules/@capacitor/share'
pod 'CapacitorSplashScreen', :path => '../../node_modules/@capacitor/splash-screen' pod 'CapacitorSplashScreen', :path => '../../node_modules/@capacitor/splash-screen'
pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar' pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'
pod 'HugotomaziCapacitorNavigationBar', :path => '../../node_modules/@hugotomazi/capacitor-navigation-bar'
pod 'TransistorsoftCapacitorBackgroundFetch', :path => '../../node_modules/@transistorsoft/capacitor-background-fetch' pod 'TransistorsoftCapacitorBackgroundFetch', :path => '../../node_modules/@transistorsoft/capacitor-background-fetch'
pod 'CapacitorSecureStoragePlugin', :path => '../../node_modules/capacitor-secure-storage-plugin' pod 'CapacitorSecureStoragePlugin', :path => '../../node_modules/capacitor-secure-storage-plugin'
pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins' pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'

102
package-lock.json generated
View File

@@ -562,21 +562,21 @@
}, },
"dependencies": { "dependencies": {
"@babel/core": { "@babel/core": {
"version": "7.19.1", "version": "7.19.3",
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.19.1.tgz", "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.19.3.tgz",
"integrity": "sha512-1H8VgqXme4UXCRv7/Wa1bq7RVymKOzC7znjyFM8KiEzwFqcKUKYNoQef4GhdklgNvoBXyW4gYhuBNCM5o1zImw==", "integrity": "sha512-WneDJxdsjEvyKtXKsaBGbDeiyOjR5vYq4HcShxnIbG0qixpoHjI3MqeZM9NDvsojNCEBItQE4juOo/bU6e72gQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@ampproject/remapping": "^2.1.0", "@ampproject/remapping": "^2.1.0",
"@babel/code-frame": "^7.18.6", "@babel/code-frame": "^7.18.6",
"@babel/generator": "^7.19.0", "@babel/generator": "^7.19.3",
"@babel/helper-compilation-targets": "^7.19.1", "@babel/helper-compilation-targets": "^7.19.3",
"@babel/helper-module-transforms": "^7.19.0", "@babel/helper-module-transforms": "^7.19.0",
"@babel/helpers": "^7.19.0", "@babel/helpers": "^7.19.0",
"@babel/parser": "^7.19.1", "@babel/parser": "^7.19.3",
"@babel/template": "^7.18.10", "@babel/template": "^7.18.10",
"@babel/traverse": "^7.19.1", "@babel/traverse": "^7.19.3",
"@babel/types": "^7.19.0", "@babel/types": "^7.19.3",
"convert-source-map": "^1.7.0", "convert-source-map": "^1.7.0",
"debug": "^4.1.0", "debug": "^4.1.0",
"gensync": "^1.0.0-beta.2", "gensync": "^1.0.0-beta.2",
@@ -593,12 +593,12 @@
} }
}, },
"@babel/generator": { "@babel/generator": {
"version": "7.19.0", "version": "7.19.3",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.19.0.tgz", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.19.3.tgz",
"integrity": "sha512-S1ahxf1gZ2dpoiFgA+ohK9DIpz50bJ0CWs7Zlzb54Z4sG8qmdIrGrVqmy1sAtTVRb+9CU6U8VqT9L0Zj7hxHVg==", "integrity": "sha512-fqVZnmp1ncvZU757UzDheKZpfPgatqY59XtW2/j/18H7u76akb8xqvjw82f+i2UKd/ksYsSick/BCLQUUtJ/qQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/types": "^7.19.0", "@babel/types": "^7.19.3",
"@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/gen-mapping": "^0.3.2",
"jsesc": "^2.5.1" "jsesc": "^2.5.1"
} }
@@ -729,9 +729,9 @@
} }
}, },
"@babel/compat-data": { "@babel/compat-data": {
"version": "7.19.1", "version": "7.19.3",
"resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.19.1.tgz", "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.19.3.tgz",
"integrity": "sha512-72a9ghR0gnESIa7jBN53U32FOVCEoztyIlKaNoU05zRhEecduGK9L9c3ww7Mp06JiR+0ls0GBPFJQwwtjn9ksg==", "integrity": "sha512-prBHMK4JYYK+wDjJF1q99KK4JLL+egWS4nmNqdlMUgCExMZ+iZW0hGhyC3VEbsPjvaN0TBhW//VIFwBrk8sEiw==",
"dev": true "dev": true
}, },
"@babel/core": { "@babel/core": {
@@ -810,12 +810,12 @@
} }
}, },
"@babel/helper-compilation-targets": { "@babel/helper-compilation-targets": {
"version": "7.19.1", "version": "7.19.3",
"resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.19.1.tgz", "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.19.3.tgz",
"integrity": "sha512-LlLkkqhCMyz2lkQPvJNdIYU7O5YjWRgC2R4omjCTpZd8u8KMQzZvX4qce+/BluN1rcQiV7BoGUpmQ0LeHerbhg==", "integrity": "sha512-65ESqLGyGmLvgR0mst5AdW1FkNlj9rQsCKduzEoEPhBCDFGXvz2jW6bXFG6i0/MrV2s7hhXjjb2yAzcPuQlLwg==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/compat-data": "^7.19.1", "@babel/compat-data": "^7.19.3",
"@babel/helper-validator-option": "^7.18.6", "@babel/helper-validator-option": "^7.18.6",
"browserslist": "^4.21.3", "browserslist": "^4.21.3",
"semver": "^6.3.0" "semver": "^6.3.0"
@@ -1193,9 +1193,9 @@
} }
}, },
"@babel/parser": { "@babel/parser": {
"version": "7.19.1", "version": "7.19.3",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.19.1.tgz", "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.19.3.tgz",
"integrity": "sha512-h7RCSorm1DdTVGJf3P2Mhj3kdnkmF/EiysUkzS2TdgAYqyjFdMQJbVuXOBej2SBJaXan/lIVtT6KkGbyyq753A==", "integrity": "sha512-pJ9xOlNWHiy9+FuFP09DEAFbAn4JskgRsVcc169w2xRBC3FRGuQEwjeIMMND9L2zc0iEhO/tGv4Zq+km+hxNpQ==",
"dev": true "dev": true
}, },
"@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": { "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": {
@@ -2002,30 +2002,30 @@
} }
}, },
"@babel/traverse": { "@babel/traverse": {
"version": "7.19.1", "version": "7.19.3",
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.19.1.tgz", "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.19.3.tgz",
"integrity": "sha512-0j/ZfZMxKukDaag2PtOPDbwuELqIar6lLskVPPJDjXMXjfLb1Obo/1yjxIGqqAJrmfaTIY3z2wFLAQ7qSkLsuA==", "integrity": "sha512-qh5yf6149zhq2sgIXmwjnsvmnNQC2iw70UFjp4olxucKrWd/dvlUsBI88VSLUsnMNF7/vnOiA+nk1+yLoCqROQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/code-frame": "^7.18.6", "@babel/code-frame": "^7.18.6",
"@babel/generator": "^7.19.0", "@babel/generator": "^7.19.3",
"@babel/helper-environment-visitor": "^7.18.9", "@babel/helper-environment-visitor": "^7.18.9",
"@babel/helper-function-name": "^7.19.0", "@babel/helper-function-name": "^7.19.0",
"@babel/helper-hoist-variables": "^7.18.6", "@babel/helper-hoist-variables": "^7.18.6",
"@babel/helper-split-export-declaration": "^7.18.6", "@babel/helper-split-export-declaration": "^7.18.6",
"@babel/parser": "^7.19.1", "@babel/parser": "^7.19.3",
"@babel/types": "^7.19.0", "@babel/types": "^7.19.3",
"debug": "^4.1.0", "debug": "^4.1.0",
"globals": "^11.1.0" "globals": "^11.1.0"
}, },
"dependencies": { "dependencies": {
"@babel/generator": { "@babel/generator": {
"version": "7.19.0", "version": "7.19.3",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.19.0.tgz", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.19.3.tgz",
"integrity": "sha512-S1ahxf1gZ2dpoiFgA+ohK9DIpz50bJ0CWs7Zlzb54Z4sG8qmdIrGrVqmy1sAtTVRb+9CU6U8VqT9L0Zj7hxHVg==", "integrity": "sha512-fqVZnmp1ncvZU757UzDheKZpfPgatqY59XtW2/j/18H7u76akb8xqvjw82f+i2UKd/ksYsSick/BCLQUUtJ/qQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/types": "^7.19.0", "@babel/types": "^7.19.3",
"@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/gen-mapping": "^0.3.2",
"jsesc": "^2.5.1" "jsesc": "^2.5.1"
} }
@@ -2050,13 +2050,13 @@
} }
}, },
"@babel/types": { "@babel/types": {
"version": "7.19.0", "version": "7.19.3",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.19.0.tgz", "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.19.3.tgz",
"integrity": "sha512-YuGopBq3ke25BVSiS6fgF49Ul9gH1x70Bcr6bqRLjWCkcX8Hre1/5+z+IiWOIerRMSSEfGZVB9z9kyq7wVs9YA==", "integrity": "sha512-hGCaQzIY22DJlDh9CH7NOxgKkFjBk0Cw9xDO1Xmh2151ti7wiGfQ3LauXzL4HP1fmFlTX6XjpRETTpUcv7wQLw==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/helper-string-parser": "^7.18.10", "@babel/helper-string-parser": "^7.18.10",
"@babel/helper-validator-identifier": "^7.18.6", "@babel/helper-validator-identifier": "^7.19.1",
"to-fast-properties": "^2.0.0" "to-fast-properties": "^2.0.0"
} }
}, },
@@ -2267,21 +2267,21 @@
}, },
"dependencies": { "dependencies": {
"@babel/core": { "@babel/core": {
"version": "7.19.1", "version": "7.19.3",
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.19.1.tgz", "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.19.3.tgz",
"integrity": "sha512-1H8VgqXme4UXCRv7/Wa1bq7RVymKOzC7znjyFM8KiEzwFqcKUKYNoQef4GhdklgNvoBXyW4gYhuBNCM5o1zImw==", "integrity": "sha512-WneDJxdsjEvyKtXKsaBGbDeiyOjR5vYq4HcShxnIbG0qixpoHjI3MqeZM9NDvsojNCEBItQE4juOo/bU6e72gQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@ampproject/remapping": "^2.1.0", "@ampproject/remapping": "^2.1.0",
"@babel/code-frame": "^7.18.6", "@babel/code-frame": "^7.18.6",
"@babel/generator": "^7.19.0", "@babel/generator": "^7.19.3",
"@babel/helper-compilation-targets": "^7.19.1", "@babel/helper-compilation-targets": "^7.19.3",
"@babel/helper-module-transforms": "^7.19.0", "@babel/helper-module-transforms": "^7.19.0",
"@babel/helpers": "^7.19.0", "@babel/helpers": "^7.19.0",
"@babel/parser": "^7.19.1", "@babel/parser": "^7.19.3",
"@babel/template": "^7.18.10", "@babel/template": "^7.18.10",
"@babel/traverse": "^7.19.1", "@babel/traverse": "^7.19.3",
"@babel/types": "^7.19.0", "@babel/types": "^7.19.3",
"convert-source-map": "^1.7.0", "convert-source-map": "^1.7.0",
"debug": "^4.1.0", "debug": "^4.1.0",
"gensync": "^1.0.0-beta.2", "gensync": "^1.0.0-beta.2",
@@ -2298,12 +2298,12 @@
} }
}, },
"@babel/generator": { "@babel/generator": {
"version": "7.19.0", "version": "7.19.3",
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.19.0.tgz", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.19.3.tgz",
"integrity": "sha512-S1ahxf1gZ2dpoiFgA+ohK9DIpz50bJ0CWs7Zlzb54Z4sG8qmdIrGrVqmy1sAtTVRb+9CU6U8VqT9L0Zj7hxHVg==", "integrity": "sha512-fqVZnmp1ncvZU757UzDheKZpfPgatqY59XtW2/j/18H7u76akb8xqvjw82f+i2UKd/ksYsSick/BCLQUUtJ/qQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@babel/types": "^7.19.0", "@babel/types": "^7.19.3",
"@jridgewell/gen-mapping": "^0.3.2", "@jridgewell/gen-mapping": "^0.3.2",
"jsesc": "^2.5.1" "jsesc": "^2.5.1"
} }
@@ -8041,9 +8041,9 @@
} }
}, },
"electron-to-chromium": { "electron-to-chromium": {
"version": "1.4.264", "version": "1.4.265",
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.264.tgz", "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.265.tgz",
"integrity": "sha512-AZ6ZRkucHOQT8wke50MktxtmcWZr67kE17X/nAXFf62NIdMdgY6xfsaJD5Szoy84lnkuPWH+4tTNE3s2+bPCiw==", "integrity": "sha512-38KaYBNs0oCzWCpr6j7fY/W9vF0vSp4tKFIshQTgdZMhUpkxgotkQgjJP6iGMdmlsgMs3i0/Hkko4UXLTrkYVQ==",
"dev": true "dev": true
}, },
"elementtree": { "elementtree": {

View File

@@ -104,6 +104,7 @@ export class AppComponent implements AfterContentInit {
color: getComputedStyle(document.documentElement) color: getComputedStyle(document.documentElement)
.getPropertyValue('--ion-background-color') .getPropertyValue('--ion-background-color')
.trim(), .trim(),
darkButtons: true,
}); });
} }
await this.authNotificationsInit(); await this.authNotificationsInit();

View File

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

View File

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

View File

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

View File

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

View File

@@ -44,6 +44,12 @@
'settings.calendar.sync.syncWithCalendar' | translate 'settings.calendar.sync.syncWithCalendar' | translate
}}</ion-label> }}</ion-label>
</ion-item> </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-item>
<ion-toggle <ion-toggle
[disabled]="isWeb" [disabled]="isWeb"
@@ -59,6 +65,7 @@
'settings.calendar.sync.eventNotifications' | translate 'settings.calendar.sync.eventNotifications' | translate
}}</ion-label> }}</ion-label>
</ion-item> </ion-item>
-->
<ion-item> <ion-item>
<ion-button <ion-button
[disabled]="isWeb || !syncEnabled" [disabled]="isWeb || !syncEnabled"