-
-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
profilePic: Add support for profile picture in notifications
- Loading branch information
1 parent
038a3de
commit adfc7a3
Showing
5 changed files
with
55 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
/** | ||
* This file contains the functions which make use of Main process APIs with already functioning code in Renderer process. | ||
*/ | ||
import {Notification} from 'electron'; | ||
import {Notification, nativeImage} from 'electron'; | ||
|
||
export const showDarwinNotification = ( | ||
import fetch from 'node-fetch'; | ||
|
||
export const showDarwinNotification = async ( | ||
event: Electron.IpcMainEvent, | ||
notificationOptions: Electron.NotificationConstructorOptions | ||
notificationOptions: Electron.NotificationConstructorOptions, | ||
profilePicURL: string | ||
) => { | ||
const profilePic = await getNativeImagefromUrl(profilePicURL); | ||
notificationOptions.icon = profilePic; | ||
|
||
const notification = new Notification(notificationOptions); | ||
notification.show(); | ||
|
||
notification.on('reply', (_event, response) => { | ||
event.sender.send('replied', response); | ||
}); | ||
}; | ||
|
||
const getNativeImagefromUrl = async (imageURL: string) => { | ||
try { | ||
const response = await fetch(imageURL); | ||
const buffer = await response.buffer(); | ||
const base64String = buffer.toString('base64'); | ||
const dataUri = `data:image/png;base64,${base64String}`; | ||
const image = nativeImage.createFromDataURL(dataUri); | ||
return image; | ||
} catch (error) { | ||
console.error(error); | ||
return null; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters