-
Notifications
You must be signed in to change notification settings - Fork 4
towards webext-js-ipfs: webpack, refactor, reorg, cleanup, update manifest #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daviddias
wants to merge
5
commits into
victorb:master
Choose a base branch
from
daviddias:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ee6712d
Rename page-script -> content-script
victorb 0f531ee
Explicit mdns=false webrtcstart=true
victorb b329260
Send data fully instead of the stream
victorb 4a86a81
"new" version
victorb 2960a88
towards webext-js-ipfs: webpack, refactor, reorg, cleanup, update man…
daviddias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This file was created by https://github.com/mozilla/web-ext | ||
# Your auto-generated extension ID for addons.mozilla.org is: | ||
{c63fe9b6-dd6c-4267-8ac8-ed4c89480fcc} |
File renamed without changes
File renamed without changes
This file contains hidden or 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 hidden or 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 hidden or 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,25 +1,26 @@ | ||
{ | ||
"name": "js-ipfs-in-the-browser", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "page-script.js", | ||
"name": "webext-js-ipfs", | ||
"version": "0.0.0", | ||
"description": "Bundle js-ipfs into a WebExtension so that it is accessible over window.IPFS", | ||
"main": "src/index.js", | ||
"dependencies": { | ||
"babel-preset-es2015": "^6.22.0", | ||
"babelify": "^7.3.0", | ||
"browserify": "^14.1.0", | ||
"ipfs": "^0.22.0", | ||
"setimmediate": "^1.0.5" | ||
"bl": "^1.2.1", | ||
"browserify-zlib-next": "^1.0.1", | ||
"ipfs": "^0.23.1", | ||
"safe-buffer": "^5.0.1" | ||
}, | ||
"devDependencies": { | ||
"web-ext": "^1.8.1" | ||
"web-ext": "^1.9.1", | ||
"webpack": "^2.5.1" | ||
}, | ||
"scripts": { | ||
"test": "mocha", | ||
"build": "browserify start-daemon.js -o dist/start-daemon.js", | ||
"build": "webpack", | ||
"package": "web-ext build", | ||
"sign": "web-ext sign" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
"keywords": [ | ||
"IPFS", | ||
"WebExtension" | ||
], | ||
"license": "MIT" | ||
} |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/* global browser */ | ||
|
||
const IPFS = require('ipfs') | ||
const bl = require('bl') | ||
|
||
browser.browserAction.setIcon({path: '/icons/ipfs-offline.svg'}) | ||
|
||
const repoPath = 'ipfs-webext-' + Math.random() | ||
|
||
const node = new IPFS({ | ||
repo: repoPath, | ||
config: { | ||
Addresses: { | ||
Swarm: [ | ||
'/libp2p-webrtc-star/dns4/star-signal.cloud.ipfs.team/wss' | ||
] | ||
} | ||
} | ||
}) | ||
|
||
node.on('err', (err) => { | ||
console.log('Error spawning the node', err) | ||
browser.browserAction.setIcon({ path: '/icons/offline.svg' }) | ||
}) | ||
|
||
node.on('ready', () => { | ||
window.ipfs = node | ||
|
||
browser.browserAction.setIcon({ path: '/icons/online.svg' }) | ||
|
||
setInterval(() => { | ||
if (node.isOnline()) { | ||
node.swarm.peers((err, peers) => { | ||
if (err) { | ||
console.log('Error on swarm.peers', err) | ||
} | ||
|
||
const nPeers = peers.length.toString() | ||
browser.browserAction.setBadgeText({nPeers}) | ||
}) | ||
} | ||
}, 1000) | ||
|
||
browser.browserAction.onClicked.addListener(() => { | ||
if (node.isOnline()) { | ||
node.stop(() => { | ||
browser.browserAction.setIcon({path: '/icons/offline.svg'}) | ||
browser.browserAction.setBadgeText({text: 'Offline'}) | ||
}) | ||
} else { | ||
node.start(() => { | ||
browser.browserAction.setIcon({path: '/icons/online.svg'}) | ||
}) | ||
} | ||
}) | ||
|
||
const methods = { | ||
'id': (args, send) => { | ||
node.id((err, id) => send({err: err, res: id})) | ||
}, | ||
'add': (args, send) => { | ||
node.files.add(Buffer.from(args), (err, res) => send({err: err, res: res})) | ||
}, | ||
'cat': (args, send) => { | ||
node.files.cat(args, (err, stream) => { | ||
if (err) { | ||
send({ err: err }) | ||
} | ||
stream.pipe(bl((err, data) => send({ err: err, res: data }))) | ||
}) | ||
} | ||
} | ||
|
||
browser.runtime.onConnect.addListener((port) => { | ||
port.onMessage.addListener((m) => { | ||
if (methods[m.method] !== undefined) { | ||
methods[m.method](m.args, (res) => port.postMessage(res)) | ||
} else { | ||
throw new Error('Method ' + m.method + ' is currently not exposed') | ||
} | ||
}) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
entry: './src/index.js', | ||
output: { | ||
filename: 'dist/bundle.js' | ||
}, | ||
node: { | ||
fs: 'empty', | ||
net: 'empty', | ||
tls: 'empty' | ||
}, | ||
resolve: { | ||
alias: { | ||
zlib: 'browserify-zlib-next' | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be .gitignored
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is needs to be persisted because otherwise it'll always be generated and result in a new extension instead of new version to existing one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it