-
Notifications
You must be signed in to change notification settings - Fork 325
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
UX fixes around embedded js-ipfs and automatic mode #381
Conversation
e6eb2ba
to
53ef74a
Compare
I've not seen that before. Stack trace please? |
@alanshaw I added mentioned change to this PR, full stacktrace is at Jenkins: PR-381/3/pipeline#step-7-log-10. Perhaps I should just refactor/move feature detection to separate module? |
6d679b9
to
0cc1ad1
Compare
Fixed it by extracting feature detection code into Do you see anything that could be improved before we merge this? |
I'll take a look at these as soon as I can |
Next time could you split changes for multiple issues like this into multiple PRs? It's much easier for me when reviewing to see which changes relate to which issues when they're separate. |
Yeah, my bad. I realized there is a size problem around 4th "fix" in this PR. |
add-on/src/lib/feature-detector.js
Outdated
return { | ||
getState () { | ||
return getState() | ||
}, |
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.
I'd rather not duplicate this if possible - what's the reasoning behind it?
add-on/src/lib/feature-detector.js
Outdated
inBrowserWithNativeProtocol () { | ||
return runtimeHasNativeProtocol | ||
} | ||
} |
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.
Would these be better expressed as things that this browser is
and has
, so:
inFirefox
=>isFirefox
inAndroid
=>isAndroid
inBrowserWithNativeProtocol
=>hasProtocolHandler
(or whatever)
Do these need to be functions? They're not performing any computation. I'd be tempted to just return a frozen object with the computed values.
embeddedNodeIsActive
feels like the odd one out here, it's not a feature of the browser and is easily detected. I'd vote for removing it from here and simply performing this check inline.
add-on/src/lib/ipfs-companion.js
Outdated
if (state.ipfsNodeType === 'embedded' && browser && browser.protocol && browser.protocol.registerStringProtocol) { | ||
return {path, localAddress: `ipfs://${hash}`} | ||
if (featureDetector.embeddedNodeIsActive() && featureDetector.inBrowserWithNativeProtocol()) { | ||
return {path, nativeAddress: `ipfs://${hash}`} |
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.
Just {path, url: `ipfs://${hash}`}
?
add-on/src/lib/ipfs-companion.js
Outdated
return {path, localAddress: url} | ||
// open at public GW (will be redirected to local elsewhere, if enabled) | ||
const url = new URL(path, state.pubGwURLString).toString() | ||
return {path, nativeAddress: url} |
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.
Just {path, url}
?
add-on/src/lib/ipfs-companion.js
Outdated
const path = `/ipfs/${hash}` | ||
if (state.ipfsNodeType === 'embedded' && browser && browser.protocol && browser.protocol.registerStringProtocol) { | ||
return {path, localAddress: `ipfs://${hash}`} | ||
if (featureDetector.embeddedNodeIsActive() && featureDetector.inBrowserWithNativeProtocol()) { |
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.
I appreciate this isn't your change, but why does the node type matter here? ping @olizilla?
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.
Good question. Logically, if we've been able to registerStringProtocol handler then ipfs://
addresses should work. I think when I wrote this I was only using the embedded js-ipfs node in the registerStringProtocol handler function, but now we support using either. It should be safe to remove the node type test.
add-on/src/lib/ipfs-request.js
Outdated
@@ -43,7 +49,7 @@ function createRequestModifier (getState, dnsLink, ipfsPathValidator) { | |||
} | |||
// Detect valid /ipfs/ and /ipns/ on any site | |||
if (ipfsPathValidator.publicIpfsOrIpnsResource(request.url)) { | |||
return redirectToCustomGateway(request.url, state.gwURL) | |||
return redirectToIpfsTransport(request.url, state, featureDetector) |
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.
I don't know what a IpfsTransport
is, how about just redirectToGateway
(could be custom or public)
add-on/src/lib/ipfs-request.js
Outdated
function redirectToCustomGateway (requestUrl, gwUrl) { | ||
function redirectToIpfsTransport (requestUrl, state, featureDetector) { | ||
// TODO: redirect to `ipfs://` if inBrowserWithNativeProtocol() === true | ||
const gwUrl = featureDetector.embeddedNodeIsActive() ? state.pubGwURL : state.gwURL |
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.
Nitpick but, I vote to keep this function simple, as it was, and perform the feature detection before it is called.
@alanshaw simplified things just like you sugested in #381 (review):
Ok to merge? |
🚀 👍 |
- suspend automatic mode while embedded node is active - redirect to public gateway instead of custom one when running js-ipfs - fix UX when starting with external API being offline (#373) - extract some reusable feature-detection functions - open public gateway instead of custom one when uploading a file using embedded js-ipfs under Firefox - some tests
TODO: fix tests
- there's no pinning in js-ipfs yet - closes #380
- platform and browser vendor features are detected once and cached - easier to test
- state-based checks are inlined - remaining runtime checks are no longer functions, but precomputed booleans
1d29651
to
bd3368d
Compare
I started dog-fooding embedded mode in Firefox and fixed some UX bugs related to it.
using embedded js-ipfs under Firefox
runtime-checks.js
+ testsKnown Issues (to be addressed in separate PR)