mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Merge pull request #596 from MetaMask/EdgeCompatibility
Edge compatibility
This commit is contained in:
commit
791e80988d
@ -3,6 +3,7 @@
|
||||
"short_name": "Metamask",
|
||||
"version": "2.10.0",
|
||||
"manifest_version": 2,
|
||||
"author": "https://metamask.io",
|
||||
"description": "Ethereum Browser Extension",
|
||||
"commands": {
|
||||
"_execute_browser_action": {
|
||||
@ -28,7 +29,8 @@
|
||||
"scripts": [
|
||||
"scripts/chromereload.js",
|
||||
"scripts/background.js"
|
||||
]
|
||||
],
|
||||
"persistent": true
|
||||
},
|
||||
"browser_action": {
|
||||
"default_icon": {
|
||||
|
@ -324,13 +324,13 @@ window.LiveReloadOptions = { host: 'localhost' };
|
||||
this.pluginIdentifiers = {}
|
||||
this.console = this.window.console && this.window.console.log && this.window.console.error ? this.window.location.href.match(/LR-verbose/) ? this.window.console : {
|
||||
log: function () {},
|
||||
error: this.window.console.error.bind(this.window.console),
|
||||
error: console.error,
|
||||
} : {
|
||||
log: function () {},
|
||||
error: function () {},
|
||||
}
|
||||
if (!(this.WebSocket = this.window.WebSocket || this.window.MozWebSocket)) {
|
||||
this.console.error('LiveReload disabled because the browser does not seem to support web sockets')
|
||||
console.error('LiveReload disabled because the browser does not seem to support web sockets')
|
||||
return
|
||||
}
|
||||
if ('LiveReloadOptions' in window) {
|
||||
@ -344,7 +344,7 @@ window.LiveReloadOptions = { host: 'localhost' };
|
||||
} else {
|
||||
this.options = Options.extract(this.window.document)
|
||||
if (!this.options) {
|
||||
this.console.error('LiveReload disabled because it could not find its own <SCRIPT> tag')
|
||||
console.error('LiveReload disabled because it could not find its own <SCRIPT> tag')
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -43,20 +43,20 @@ function setupStreams(){
|
||||
name: 'contentscript',
|
||||
target: 'inpage',
|
||||
})
|
||||
pageStream.on('error', console.error.bind(console))
|
||||
pageStream.on('error', console.error)
|
||||
var pluginPort = extension.runtime.connect({name: 'contentscript'})
|
||||
var pluginStream = new PortStream(pluginPort)
|
||||
pluginStream.on('error', console.error.bind(console))
|
||||
pluginStream.on('error', console.error)
|
||||
|
||||
// forward communication plugin->inpage
|
||||
pageStream.pipe(pluginStream).pipe(pageStream)
|
||||
|
||||
// connect contentscript->inpage reload stream
|
||||
var mx = ObjectMultiplex()
|
||||
mx.on('error', console.error.bind(console))
|
||||
mx.on('error', console.error)
|
||||
mx.pipe(pageStream)
|
||||
var reloadStream = mx.createStream('reload')
|
||||
reloadStream.on('error', console.error.bind(console))
|
||||
reloadStream.on('error', console.error)
|
||||
|
||||
// if we lose connection with the plugin, trigger tab refresh
|
||||
pluginStream.on('close', function () {
|
||||
|
@ -46,12 +46,23 @@ function Extension () {
|
||||
_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
|
||||
|
@ -14,9 +14,10 @@ function show () {
|
||||
return extension.windows.update(popup.id, { focused: true })
|
||||
}
|
||||
|
||||
|
||||
extension.windows.create({
|
||||
url: 'notification.html',
|
||||
type: 'detached_panel',
|
||||
type: 'popup',
|
||||
focused: true,
|
||||
width: 360,
|
||||
height: 500,
|
||||
|
@ -74,22 +74,12 @@ function getCurrentDomain (cb) {
|
||||
})
|
||||
}
|
||||
|
||||
function clearNotifications(){
|
||||
extension.notifications.getAll(function (object) {
|
||||
for (let notification in object){
|
||||
extension.notifications.clear(notification)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function setupApp (err, opts) {
|
||||
if (err) {
|
||||
alert(err.stack)
|
||||
throw err
|
||||
}
|
||||
|
||||
clearNotifications()
|
||||
|
||||
var container = document.getElementById('app-content')
|
||||
|
||||
MetaMaskUi({
|
||||
|
17
gulpfile.js
17
gulpfile.js
@ -34,6 +34,7 @@ gulp.task('copy:locales', copyTask({
|
||||
destinations: [
|
||||
'./dist/firefox/_locales',
|
||||
'./dist/chrome/_locales',
|
||||
'./dist/edge/_locales',
|
||||
]
|
||||
}))
|
||||
gulp.task('copy:images', copyTask({
|
||||
@ -41,6 +42,7 @@ gulp.task('copy:images', copyTask({
|
||||
destinations: [
|
||||
'./dist/firefox/images',
|
||||
'./dist/chrome/images',
|
||||
'./dist/edge/images',
|
||||
],
|
||||
}))
|
||||
gulp.task('copy:fonts', copyTask({
|
||||
@ -48,6 +50,7 @@ gulp.task('copy:fonts', copyTask({
|
||||
destinations: [
|
||||
'./dist/firefox/fonts',
|
||||
'./dist/chrome/fonts',
|
||||
'./dist/edge/fonts',
|
||||
],
|
||||
}))
|
||||
gulp.task('copy:reload', copyTask({
|
||||
@ -55,6 +58,7 @@ gulp.task('copy:reload', copyTask({
|
||||
destinations: [
|
||||
'./dist/firefox/scripts',
|
||||
'./dist/chrome/scripts',
|
||||
'./dist/edge/scripts',
|
||||
],
|
||||
pattern: '/chromereload.js',
|
||||
}))
|
||||
@ -63,6 +67,7 @@ gulp.task('copy:root', copyTask({
|
||||
destinations: [
|
||||
'./dist/firefox',
|
||||
'./dist/chrome',
|
||||
'./dist/edge',
|
||||
],
|
||||
pattern: '/*',
|
||||
}))
|
||||
@ -131,13 +136,18 @@ gulp.task('zip:chrome', () => {
|
||||
return gulp.src('dist/chrome/**')
|
||||
.pipe(zip(`metamask-chrome-${manifest.version}.zip`))
|
||||
.pipe(gulp.dest('builds'));
|
||||
});
|
||||
})
|
||||
gulp.task('zip:firefox', () => {
|
||||
return gulp.src('dist/firefox/**')
|
||||
.pipe(zip(`metamask-firefox-${manifest.version}.zip`))
|
||||
.pipe(gulp.dest('builds'));
|
||||
});
|
||||
gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox'))
|
||||
})
|
||||
gulp.task('zip:edge', () => {
|
||||
return gulp.src('dist/edge/**')
|
||||
.pipe(zip(`metamask-edge-${manifest.version}.zip`))
|
||||
.pipe(gulp.dest('builds'));
|
||||
})
|
||||
gulp.task('zip', gulp.parallel('zip:chrome', 'zip:firefox', 'zip:edge'))
|
||||
|
||||
// high level tasks
|
||||
|
||||
@ -200,6 +210,7 @@ function bundleTask(opts) {
|
||||
.pipe(sourcemaps.write('./')) // writes .map file
|
||||
.pipe(gulp.dest('./dist/firefox/scripts'))
|
||||
.pipe(gulp.dest('./dist/chrome/scripts'))
|
||||
.pipe(gulp.dest('./dist/edge/scripts'))
|
||||
.pipe(livereload())
|
||||
|
||||
)
|
||||
|
@ -9,6 +9,34 @@ var Extension = require(path.join(__dirname, '..', '..', 'app', 'scripts', 'lib'
|
||||
|
||||
describe('extension', function() {
|
||||
|
||||
describe('extension.getURL', function() {
|
||||
const desiredResult = 'http://the-desired-result.io'
|
||||
|
||||
describe('in Chrome or Firefox', function() {
|
||||
GLOBAL.chrome.extension = {
|
||||
getURL: () => desiredResult
|
||||
}
|
||||
|
||||
it('returns the desired result', function() {
|
||||
const extension = new Extension()
|
||||
const result = extension.extension.getURL()
|
||||
assert.equal(result, desiredResult)
|
||||
})
|
||||
})
|
||||
|
||||
describe('in Microsoft Edge', function() {
|
||||
GLOBAL.browser.extension = {
|
||||
getURL: () => desiredResult
|
||||
}
|
||||
|
||||
it('returns the desired result', function() {
|
||||
const extension = new Extension()
|
||||
const result = extension.extension.getURL()
|
||||
assert.equal(result, desiredResult)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('with chrome global', function() {
|
||||
let extension
|
||||
|
||||
@ -45,4 +73,5 @@ describe('extension', function() {
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
})
|
||||
|
@ -14,7 +14,9 @@ inherits(PersistentForm, Component)
|
||||
PersistentForm.prototype.componentDidMount = function () {
|
||||
const fields = document.querySelectorAll('[data-persistent-formid]')
|
||||
const store = this.getPersistentStore()
|
||||
fields.forEach((field) => {
|
||||
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
const field = fields[i]
|
||||
const key = field.getAttribute('data-persistent-formid')
|
||||
const cached = store[key]
|
||||
if (cached !== undefined) {
|
||||
@ -22,7 +24,7 @@ PersistentForm.prototype.componentDidMount = function () {
|
||||
}
|
||||
|
||||
field.addEventListener(eventName, this.persistentFieldDidUpdate.bind(this))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
PersistentForm.prototype.getPersistentStore = function () {
|
||||
@ -50,8 +52,10 @@ PersistentForm.prototype.persistentFieldDidUpdate = function (event) {
|
||||
|
||||
PersistentForm.prototype.componentWillUnmount = function () {
|
||||
const fields = document.querySelectorAll('[data-persistent-formid]')
|
||||
fields.forEach((field) => {
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
const field = fields[i]
|
||||
field.removeEventListener(eventName, this.persistentFieldDidUpdate.bind(this))
|
||||
})
|
||||
}
|
||||
this.setPersistentStore({})
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user