1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

iOS: Handle foreground notifications

This commit is contained in:
Laurent Cozic
2017-11-28 20:17:34 +00:00
parent c446e4471d
commit 4df73cd82c
6 changed files with 68 additions and 808 deletions

View File

@@ -20,6 +20,11 @@ class AlarmService {
return this.logger_;
}
static setInAppNotificationHandler(v) {
this.inAppNotificationHandler_ = v;
if (this.driver_.setInAppNotificationHandler) this.driver_.setInAppNotificationHandler(v);
}
static async garbageCollect() {
this.logger().info('Garbage collecting alarms...');
@@ -56,16 +61,6 @@ class AlarmService {
let alarm = noteId ? await Alarm.byNoteId(noteId) : null;
let clearAlarm = false;
const makeNotificationFromAlarm = (alarm) => {
const output = {
id: alarm.id,
date: new Date(note.todo_due),
title: note.title.substr(0,128),
}
if (note.body) output.body = note.body.substr(0,512);
return output;
}
if (isDeleted ||
!Note.needAlarm(note) ||
(alarm && alarm.trigger_time !== note.todo_due))
@@ -80,7 +75,7 @@ class AlarmService {
// For non-persistent notifications however we need to check that the notification has been set because, for example,
// if the app has just started the notifications need to be set again. so we do this below.
if (!driver.hasPersistentNotifications() && !driver.notificationIsSet(alarm.id)) {
const notification = makeNotificationFromAlarm(alarm);
const notification = await Alarm.makeNotification(alarm, note);
this.logger().info('Scheduling (non-persistent) notification for note ' + note.id, notification);
driver.scheduleNotification(notification);
}
@@ -104,7 +99,7 @@ class AlarmService {
// Reload alarm to get its ID
alarm = await Alarm.byNoteId(note.id);
const notification = makeNotificationFromAlarm(alarm);
const notification = await Alarm.makeNotification(alarm, note);
this.logger().info('Scheduling notification for note ' + note.id, notification);
await driver.scheduleNotification(notification);
}