aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/scripts/lib')
-rw-r--r--app/scripts/lib/extension-instance.js68
-rw-r--r--app/scripts/lib/extension.js17
-rw-r--r--app/scripts/lib/notification-manager.js74
-rw-r--r--app/scripts/lib/notifications.js67
4 files changed, 74 insertions, 152 deletions
diff --git a/app/scripts/lib/extension-instance.js b/app/scripts/lib/extension-instance.js
deleted file mode 100644
index 628b62e3f..000000000
--- a/app/scripts/lib/extension-instance.js
+++ /dev/null
@@ -1,68 +0,0 @@
-const apis = [
- 'alarms',
- 'bookmarks',
- 'browserAction',
- 'commands',
- 'contextMenus',
- 'cookies',
- 'downloads',
- 'events',
- 'extension',
- 'extensionTypes',
- 'history',
- 'i18n',
- 'idle',
- 'notifications',
- 'pageAction',
- 'runtime',
- 'storage',
- 'tabs',
- 'webNavigation',
- 'webRequest',
- 'windows',
-]
-
-function Extension () {
- const _this = this
-
- apis.forEach(function (api) {
-
- _this[api] = null
-
- try {
- if (chrome[api]) {
- _this[api] = chrome[api]
- }
- } catch (e) {}
-
- try {
- if (window[api]) {
- _this[api] = window[api]
- }
- } catch (e) {}
-
- try {
- if (browser[api]) {
- _this[api] = browser[api]
- }
- } catch (e) {}
- try {
- _this.api = browser.extension[api]
- } catch (e) {}
- })
-
- try {
- if (browser && browser.runtime) {
- this.runtime = browser.runtime
- }
- } catch (e) {}
-
- try {
- if (browser && browser.browserAction) {
- this.browserAction = browser.browserAction
- }
- } catch (e) {}
-
-}
-
-module.exports = Extension
diff --git a/app/scripts/lib/extension.js b/app/scripts/lib/extension.js
deleted file mode 100644
index 6f8b5d800..000000000
--- a/app/scripts/lib/extension.js
+++ /dev/null
@@ -1,17 +0,0 @@
-/* Extension.js
- *
- * A module for unifying browser differences in the WebExtension API.
- *
- * Initially implemented because Chrome hides all of their WebExtension API
- * behind a global `chrome` variable, but we'd like to start grooming
- * the code-base for cross-browser extension support.
- *
- * You can read more about the WebExtension API here:
- * https://developer.mozilla.org/en-US/Add-ons/WebExtensions
- */
-
-const Extension = require('./extension-instance')
-const instance = new Extension()
-window.METAMASK_EXTENSION = instance
-module.exports = instance
-
diff --git a/app/scripts/lib/notification-manager.js b/app/scripts/lib/notification-manager.js
new file mode 100644
index 000000000..55e5b8dd2
--- /dev/null
+++ b/app/scripts/lib/notification-manager.js
@@ -0,0 +1,74 @@
+const extension = require('extensionizer')
+const height = 520
+const width = 360
+
+
+class NotificationManager {
+
+ //
+ // Public
+ //
+
+ showPopup () {
+ this._getPopup((err, popup) => {
+ if (err) throw err
+
+ if (popup) {
+ // bring focus to existing popup
+ extension.windows.update(popup.id, { focused: true })
+ } else {
+ // create new popup
+ extension.windows.create({
+ url: 'notification.html',
+ type: 'popup',
+ width,
+ height,
+ })
+ .catch((reason) => {
+ log.error('failed to create poupup', reason)
+ })
+ }
+ })
+ }
+
+ closePopup () {
+ this._getPopup((err, popup) => {
+ if (err) throw err
+ if (!popup) return
+ extension.windows.remove(popup.id, console.error)
+ })
+ }
+
+ //
+ // Private
+ //
+
+ _getPopup (cb) {
+ this._getWindows((err, windows) => {
+ if (err) throw err
+ cb(null, this._getPopupIn(windows))
+ })
+ }
+
+ _getWindows (cb) {
+ // Ignore in test environment
+ if (!extension.windows) {
+ return cb()
+ }
+
+ extension.windows.getAll({}, (windows) => {
+ cb(null, windows)
+ })
+ }
+
+ _getPopupIn (windows) {
+ return windows ? windows.find((win) => {
+ return (win && win.type === 'popup' &&
+ win.height === height &&
+ win.width === width)
+ }) : null
+ }
+
+}
+
+module.exports = NotificationManager \ No newline at end of file
diff --git a/app/scripts/lib/notifications.js b/app/scripts/lib/notifications.js
deleted file mode 100644
index 0ec01f3a7..000000000
--- a/app/scripts/lib/notifications.js
+++ /dev/null
@@ -1,67 +0,0 @@
-const extension = require('./extension')
-const height = 520
-const width = 360
-
-const notifications = {
- show,
- getPopup,
- closePopup,
-}
-module.exports = notifications
-window.METAMASK_NOTIFIER = notifications
-
-function show () {
- getPopup((err, popup) => {
- if (err) throw err
-
- if (popup) {
- // bring focus to existing popup
- extension.windows.update(popup.id, { focused: true })
- } else {
- // create new popup
- extension.windows.create({
- url: 'notification.html',
- type: 'popup',
- width,
- height,
- })
- .catch((reason) => {
- log.error('failed to create poupup', reason)
- })
- }
- })
-}
-
-function getWindows (cb) {
- // Ignore in test environment
- if (!extension.windows) {
- return cb()
- }
-
- extension.windows.getAll({}, (windows) => {
- cb(null, windows)
- })
-}
-
-function getPopup (cb) {
- getWindows((err, windows) => {
- if (err) throw err
- cb(null, getPopupIn(windows))
- })
-}
-
-function getPopupIn (windows) {
- return windows ? windows.find((win) => {
- return (win && win.type === 'popup' &&
- win.height === height &&
- win.width === width)
- }) : null
-}
-
-function closePopup () {
- getPopup((err, popup) => {
- if (err) throw err
- if (!popup) return
- extension.windows.remove(popup.id, console.error)
- })
-}