-
-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathsync_alarm_receiver.ts
More file actions
37 lines (33 loc) · 1.24 KB
/
sync_alarm_receiver.ts
File metadata and controls
37 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { Application, Utils } from '@nativescript/core';
import { SYNC_ALARM_ACTION, SYNC_THROTTLE_ALARM, syncService } from '../services/sync.android';
import { start } from '~/startHandler';
/**
* BroadcastReceiver for handling sync alarms on Android
*/
@NativeClass()
@JavaProxy('__PACKAGE__.SyncAlarmReceiver')
export class SyncAlarmReceiver extends android.content.BroadcastReceiver {
async onReceive(context: android.content.Context, intent: android.content.Intent) {
const action = intent.getAction();
// Check if this is our sync alarm action
if (action !== SYNC_ALARM_ACTION) {
return;
}
const serviceId = intent.getLongExtra('serviceId', -1);
if (serviceId === -1) {
return;
}
DEV_LOG && console.log('SyncAlarmReceiver', 'onReceive', action, serviceId, Application.servicesStarted);
function handleIntent() {
syncService.triggerThrottledSync(serviceId).catch((error) => {
console.error('SyncAlarmReceiver', 'failed to trigger sync', error);
});
}
try {
await start();
handleIntent();
} catch (error) {
console.error(error, error.stack);
}
}
}