mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-26 18:58:21 +02:00
Android: Got notifications to work
This commit is contained in:
parent
18dc6c826a
commit
67a457b9c5
@ -15,6 +15,20 @@ class PoorManIntervals {
|
|||||||
return PoorManIntervals.intervalId_;
|
return PoorManIntervals.intervalId_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static setTimeout(callback, interval) {
|
||||||
|
PoorManIntervals.intervalId_++;
|
||||||
|
|
||||||
|
PoorManIntervals.intervals_.push({
|
||||||
|
id: PoorManIntervals.intervalId_,
|
||||||
|
callback: callback,
|
||||||
|
interval: interval,
|
||||||
|
lastIntervalTime: time.unixMs(),
|
||||||
|
oneOff: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
return PoorManIntervals.intervalId_;
|
||||||
|
}
|
||||||
|
|
||||||
static intervalById(id) {
|
static intervalById(id) {
|
||||||
for (let i = 0; i < PoorManIntervals.intervals_.length; i++) {
|
for (let i = 0; i < PoorManIntervals.intervals_.length; i++) {
|
||||||
if (PoorManIntervals.intervals_[i].id == id) return PoorManIntervals.intervals_[id];
|
if (PoorManIntervals.intervals_[i].id == id) return PoorManIntervals.intervals_[id];
|
||||||
@ -41,6 +55,9 @@ class PoorManIntervals {
|
|||||||
if (now - interval.lastIntervalTime >= interval.interval) {
|
if (now - interval.lastIntervalTime >= interval.interval) {
|
||||||
interval.lastIntervalTime = now;
|
interval.lastIntervalTime = now;
|
||||||
interval.callback();
|
interval.callback();
|
||||||
|
if (interval.oneOff) {
|
||||||
|
this.clearInterval(interval.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,11 +57,13 @@ class AlarmService {
|
|||||||
let clearAlarm = false;
|
let clearAlarm = false;
|
||||||
|
|
||||||
const makeNotificationFromAlarm = (alarm) => {
|
const makeNotificationFromAlarm = (alarm) => {
|
||||||
return {
|
const output = {
|
||||||
id: alarm.id,
|
id: alarm.id,
|
||||||
date: new Date(note.todo_due),
|
date: new Date(note.todo_due),
|
||||||
title: note.title,
|
title: note.title.substr(0,128),
|
||||||
}
|
}
|
||||||
|
if (note.body) output.body = note.body.substr(0,512);
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isDeleted ||
|
if (isDeleted ||
|
||||||
@ -103,9 +105,6 @@ class AlarmService {
|
|||||||
alarm = await Alarm.byNoteId(note.id);
|
alarm = await Alarm.byNoteId(note.id);
|
||||||
|
|
||||||
const notification = makeNotificationFromAlarm(alarm);
|
const notification = makeNotificationFromAlarm(alarm);
|
||||||
|
|
||||||
if (note.body) notification.body = note.body;
|
|
||||||
|
|
||||||
this.logger().info('Scheduling notification for note ' + note.id, notification);
|
this.logger().info('Scheduling notification for note ' + note.id, notification);
|
||||||
await driver.scheduleNotification(notification);
|
await driver.scheduleNotification(notification);
|
||||||
}
|
}
|
||||||
|
@ -17,11 +17,11 @@ class AlarmServiceDriver {
|
|||||||
async scheduleNotification(notification) {
|
async scheduleNotification(notification) {
|
||||||
const androidNotification = {
|
const androidNotification = {
|
||||||
id: notification.id,
|
id: notification.id,
|
||||||
message: notification.title.substr(0, 100), // No idea what the limits are for title and body but set something reasonable anyway
|
message: notification.title, // No idea what the limits are for title and body but set something reasonable anyway
|
||||||
date: notification.date,
|
date: notification.date,
|
||||||
};
|
};
|
||||||
|
|
||||||
if ('body' in notification) androidNotification.body = notification.body.substr(0, 512);
|
if ('body' in notification) androidNotification.body = notification.body;
|
||||||
|
|
||||||
PushNotification.localNotificationSchedule(androidNotification);
|
PushNotification.localNotificationSchedule(androidNotification);
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,10 @@ const generalMiddleware = store => next => async (action) => {
|
|||||||
if (!await reg.syncTarget().syncStarted()) reg.scheduleSync();
|
if (!await reg.syncTarget().syncStarted()) reg.scheduleSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (['EVENT_NOTE_ALARM_FIELD_CHANGE', 'NOTE_DELETE'].indexOf(action.type) >= 0) {
|
||||||
|
await AlarmService.updateNoteNotification(action.id, action.type === 'NOTE_DELETE');
|
||||||
|
}
|
||||||
|
|
||||||
if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'sync.interval' || action.type == 'SETTING_UPDATE_ALL') {
|
if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'sync.interval' || action.type == 'SETTING_UPDATE_ALL') {
|
||||||
reg.setupRecurrentSync();
|
reg.setupRecurrentSync();
|
||||||
}
|
}
|
||||||
@ -369,32 +373,15 @@ async function initialize(dispatch, backButtonHandler) {
|
|||||||
|
|
||||||
reg.setupRecurrentSync();
|
reg.setupRecurrentSync();
|
||||||
|
|
||||||
if (Setting.value('env') == 'dev') {
|
PoorManIntervals.setTimeout(() => {
|
||||||
// reg.scheduleSync();
|
AlarmService.garbageCollect();
|
||||||
} else {
|
}, 1000 * 60 * 60);
|
||||||
reg.scheduleSync();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//reg.logger().info('Scheduling iOS notification');
|
|
||||||
|
|
||||||
// PushNotificationIOS.scheduleLocalNotification({
|
|
||||||
// alertTitle: "From Joplin",
|
|
||||||
// alertBody : "Testing notification on iOS",
|
|
||||||
// fireDate: new Date(Date.now() + (10 * 1000)),
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// const r = PushNotification.localNotificationSchedule({
|
|
||||||
// id: '222456',
|
|
||||||
// message: "My Notification Message", // (required)
|
|
||||||
// date: new Date(Date.now() + (10 * 1000)) // in 60 secs
|
|
||||||
// });
|
|
||||||
|
|
||||||
//PushNotification.cancelLocalNotifications({ id: '222456' });
|
|
||||||
|
|
||||||
|
reg.scheduleSync().then(() => {
|
||||||
|
// Wait for the first sync before updating the notifications, since synchronisation
|
||||||
|
// might change the notifications.
|
||||||
|
AlarmService.updateAllNotifications();
|
||||||
|
});
|
||||||
|
|
||||||
reg.logger().info('Application initialized');
|
reg.logger().info('Application initialized');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user