platforms/extension.js

const extension = require('extensionizer')

/**
 * An object that provides a variety of platform-specific functions.
 *
 * @typedef {object} Platform
 *
 * @property {Function} reload - A function to reload the application.
 * @property {Function} openWindow - Opens a URL in the web browser.
 * @property {Function} getVersion - Gets the current version of MetaMask.
 * @property {Function} openExtensionInBrowser - Opens the MetaMask UI in a full window.
 * @property {Function} getPlatformInfo - Callback function that returns info about the current platform.
 */

class ExtensionPlatform {

  //
  // Public
  //
  reload () {
    extension.runtime.reload()
  }

  openWindow ({ url }) {
    extension.tabs.create({ url })
  }

  getVersion () {
    return extension.runtime.getManifest().version
  }

  openExtensionInBrowser () {
    const extensionURL = extension.runtime.getURL('home.html')
    this.openWindow({ url: extensionURL })
  }

  getPlatformInfo (cb) {
    try {
      extension.runtime.getPlatformInfo((platform) => {
        cb(null, platform)
      })
    } catch (e) {
      cb(e)
    }
  }
}

module.exports = ExtensionPlatform