1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-26 12:29:06 +01:00

Notification manager method docs.

This commit is contained in:
Dan 2018-04-20 15:48:44 -02:30
parent 71b0de76ff
commit 3ec22dc7e1

View File

@ -12,6 +12,11 @@ class NotificationManager {
* *
*/ */
/**
* Either brings an existing MetaMask notification window into focus, or creates a new notification window. New
* notification windows are given a 'popup' type.
*
*/
showPopup () { showPopup () {
this._getPopup((err, popup) => { this._getPopup((err, popup) => {
if (err) throw err if (err) throw err
@ -32,6 +37,10 @@ class NotificationManager {
}) })
} }
/**
* Closes a MetaMask notification if it window exists.
*
*/
closePopup () { closePopup () {
// closes notification popup // closes notification popup
this._getPopup((err, popup) => { this._getPopup((err, popup) => {
@ -41,10 +50,14 @@ class NotificationManager {
}) })
} }
// /**
// Private * Checks all open MetaMask windows, and returns the first one it finds that is a notification window (i.e. has the
// * type 'popup')
*
* @private
* @param {Function} cb A node style callback that to whcih the found notification window will be passed.
*
*/
_getPopup (cb) { _getPopup (cb) {
this._getWindows((err, windows) => { this._getWindows((err, windows) => {
if (err) throw err if (err) throw err
@ -52,6 +65,13 @@ class NotificationManager {
}) })
} }
/**
* Returns all open MetaMask windows.
*
* @private
* @param {Function} cb A node style callback that to which the windows will be passed.
*
*/
_getWindows (cb) { _getWindows (cb) {
// Ignore in test environment // Ignore in test environment
if (!extension.windows) { if (!extension.windows) {
@ -63,6 +83,13 @@ class NotificationManager {
}) })
} }
/**
* Given an array of windows, returns the first that has a 'popup' type, or null if no such window exists.
*
* @private
* @param {array} windows An array of objects containing data about the open MetaMask extension windows.
*
*/
_getPopupIn (windows) { _getPopupIn (windows) {
return windows ? windows.find((win) => { return windows ? windows.find((win) => {
// Returns notification popup // Returns notification popup