-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
68 additions
and
50 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,27 +1,30 @@ | ||
/* global browser */ | ||
/* global browser, cloneInto */ | ||
// window.wrappedJSObject.ipfs = false | ||
console.log('declared a public ipfs object!') | ||
|
||
const myPort = browser.runtime.connect({name: 'port-from-cs'}) | ||
|
||
const makeCall = (method, cb) => { | ||
myPort.onMessage.addListener(function (m) { | ||
myPort.onMessage.removeListener(this) | ||
cb(m.response) | ||
// myPort.onMessage.removeListener(this) | ||
cb(cloneInto(m, window, {cloneFunctions: true})) | ||
}) | ||
myPort.postMessage({method}) | ||
} | ||
|
||
const createFunc = (method, callback) => { | ||
return () => { | ||
makeCall(method, callback) | ||
} | ||
} | ||
|
||
const ipfs = { | ||
id: (callback) => createFunc('id', callback) | ||
id: (callback) => { makeCall('id', callback) } | ||
} | ||
|
||
window.ipfs = ipfs | ||
// ipfs.id((id) => { | ||
// console.log('lol', id) | ||
// }) | ||
|
||
window.wrappedJSObject.ipfs = cloneInto( | ||
ipfs, | ||
window, | ||
{cloneFunctions: true}) | ||
|
||
// window.ipfs = ipfs | ||
// unsafeWindow.clonedContentScriptObject = cloneInto(ipfs, unsafeWindow) | ||
// unsafeWindow.assignedContentScriptObject = ipfs; |
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,45 +1,33 @@ | ||
/* global browser */ | ||
let node = null | ||
require('setimmediate') // TODO js-ipfs fails without this in the ID call | ||
const spawn = require('./spawn-node.js') | ||
browser.browserAction.setIcon({path: '/icons/ipfs-offline.svg'}) | ||
|
||
spawn({}, (err, ipfsNode) => { | ||
if (err) throw err | ||
node = ipfsNode | ||
}) | ||
|
||
const methods = { | ||
'id': (node, send) => { | ||
node.id((err, id) => { | ||
if (err) throw err | ||
send(id) | ||
}) | ||
} | ||
} | ||
browser.browserAction.setIcon({path: '/icons/ipfs.svg'}) | ||
|
||
browser.runtime.onConnect.addListener((port) => { | ||
port.onMessage.addListener((m) => { | ||
if (methods[m.method] !== undefined) { | ||
methods[m.method](node, (res) => { | ||
port.postMessage({response: res}) | ||
const methods = { | ||
'id': (send) => { | ||
console.log('method#id') | ||
ipfsNode.id((err, id) => { | ||
if (err) throw err | ||
console.log('responding') | ||
send(id) | ||
}) | ||
} | ||
} | ||
|
||
browser.runtime.onConnect.addListener((port) => { | ||
port.onMessage.addListener((m) => { | ||
if (methods[m.method] !== undefined) { | ||
console.log('can make this call') | ||
methods[m.method]((res) => { | ||
console.log('made it and responding!') | ||
port.postMessage(res) | ||
}) | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
const handleErr = (err) => { | ||
console.log('Something threw an error') | ||
if (err) throw err | ||
} | ||
|
||
browser.tabs.query({}).then((tabs) => { | ||
console.log(tabs) | ||
}, handleErr).catch(handleErr) | ||
|
||
// var addonScriptObject = {"greeting" : "hello from add-on"}; | ||
// contentWindow.addonScriptObject = cloneInto(addonScriptObject, contentWindow); | ||
|
||
browser.tabs.executeScript({ | ||
file: '/page-script.js' | ||
}).then(() => { | ||
console.log('injected') | ||
}, handleErr).catch(handleErr) |
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