Changeset View
Changeset View
Standalone View
Standalone View
desktop/src/push-notifications.js
- This file was added.
// @flow | ||||||||||
// eslint-disable-next-line import/extensions | ||||||||||
tomek: Why do we need to silence this warning? | ||||||||||
ashoatUnsubmitted Not Done Inline Actionsashoat: https://phab.comm.dev/D6694?id=22348#inline-44071 | ||||||||||
import { pushNotifications, Notification } from 'electron/main'; | ||||||||||
async function registerForNotifications(): Promise<?string> { | ||||||||||
if (process.platform !== 'darwin') { | ||||||||||
return null; | ||||||||||
} | ||||||||||
try { | ||||||||||
const token = await pushNotifications.registerForAPNSNotifications(); | ||||||||||
return token; | ||||||||||
} catch (err) { | ||||||||||
console.error(err); | ||||||||||
} | ||||||||||
return null; | ||||||||||
} | ||||||||||
function listenForNotifications(handleClick: (threadID: string) => void) { | ||||||||||
if (process.platform !== 'darwin') { | ||||||||||
return; | ||||||||||
} | ||||||||||
pushNotifications.on('received-apns-notification', (event, userInfo) => { | ||||||||||
if ( | ||||||||||
typeof userInfo.title !== 'string' || | ||||||||||
typeof userInfo.body !== 'string' || | ||||||||||
typeof userInfo.threadID !== 'string' | ||||||||||
) { | ||||||||||
console.error( | ||||||||||
'Notification must contains a string title, body and threadID', | ||||||||||
tomekUnsubmitted Not Done Inline Actions
tomek: | ||||||||||
); | ||||||||||
return; | ||||||||||
} | ||||||||||
const { title, body, threadID } = userInfo; | ||||||||||
const notif = new Notification({ | ||||||||||
title, | ||||||||||
body, | ||||||||||
}); | ||||||||||
notif.on('click', () => { | ||||||||||
handleClick(threadID); | ||||||||||
}); | ||||||||||
notif.show(); | ||||||||||
}); | ||||||||||
} | ||||||||||
export { listenForNotifications, registerForNotifications }; |
Why do we need to silence this warning?