Skip to content
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

Merged
merged 5 commits into from
Feb 20, 2018

Conversation

lidel
Copy link
Member

@lidel lidel commented Feb 11, 2018

I started dog-fooding embedded mode in Firefox and fixed some UX bugs related to it.

  • suspend redirect to custom gateway (and automatic mode) when embedded node is active
  • redirect to public gateway instead of custom one when running js-ipfs

    This works fine in Firefox/Chrome, but may need additional work in separate PR to get optimal UX under Brave (eg. we probably want to redirect IPFS resources to ipfs:// instead of keeping URL of public gateway).

  • fix UX when starting with external API being offline (close Daemon is off but redirect is still enabled #373)
  • extract some reusable feature-detection functions
  • open public gateway instead of custom one when uploading a file
    using embedded js-ipfs under Firefox
  • separate redirect tests for embedded and external modes
  • make it work under Chrome
  • Pinning does not work on Firefox when using js-ipfs node (close Pinning does not work on Firefox when using js-ipfs node #380)
  • Move runtime feature detection to runtime-checks.js + tests

Known Issues (to be addressed in separate PR)

@lidel lidel added the UX label Feb 11, 2018
@lidel lidel added this to the 2018-Q1 milestone Feb 11, 2018
@lidel lidel self-assigned this Feb 11, 2018
@lidel lidel force-pushed the fix/automatic-mode-when-start-offline branch from e6eb2ba to 53ef74a Compare February 11, 2018 19:27
@lidel lidel requested review from alanshaw and olizilla and removed request for alanshaw February 11, 2018 19:34
@lidel lidel changed the title UX fixes around embedded js-ipfs and automatic mode [WIP] UX fixes around embedded js-ipfs and automatic mode Feb 11, 2018
@lidel
Copy link
Member Author

lidel commented Feb 11, 2018

I was able to make it work in Chrome by adding const browser = require('webextension-polyfill') to add-on/src/lib/state.js but I get ReferenceError: chrome is not defined when I run test suite (yarn test).

@alanshaw, @olizilla did you see this error before by any chance?

@alanshaw
Copy link
Member

alanshaw commented Feb 12, 2018

I've not seen that before. Stack trace please?

@lidel
Copy link
Member Author

lidel commented Feb 12, 2018

@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?

@lidel lidel force-pushed the fix/automatic-mode-when-start-offline branch from 6d679b9 to 0cc1ad1 Compare February 19, 2018 12:51
@lidel lidel changed the title [WIP] UX fixes around embedded js-ipfs and automatic mode UX fixes around embedded js-ipfs and automatic mode Feb 19, 2018
@lidel
Copy link
Member Author

lidel commented Feb 19, 2018

Fixed it by extracting feature detection code into feature-detector.js (0cc1ad1)
I don't like the name, but does the job + is finally testable.

Do you see anything that could be improved before we merge this?

@alanshaw
Copy link
Member

I'll take a look at these as soon as I can

@alanshaw
Copy link
Member

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.

@lidel
Copy link
Member Author

lidel commented Feb 20, 2018

Yeah, my bad. I realized there is a size problem around 4th "fix" in this PR.
It was supposed to be much smaller. 😞

return {
getState () {
return getState()
},
Copy link
Member

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?

inBrowserWithNativeProtocol () {
return runtimeHasNativeProtocol
}
}
Copy link
Member

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.

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}`}
Copy link
Member

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}`}?

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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just {path, url}?

const path = `/ipfs/${hash}`
if (state.ipfsNodeType === 'embedded' && browser && browser.protocol && browser.protocol.registerStringProtocol) {
return {path, localAddress: `ipfs://${hash}`}
if (featureDetector.embeddedNodeIsActive() && featureDetector.inBrowserWithNativeProtocol()) {
Copy link
Member

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?

Copy link
Member

@olizilla olizilla Feb 20, 2018

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.

@@ -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)
Copy link
Member

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)

function redirectToCustomGateway (requestUrl, gwUrl) {
function redirectToIpfsTransport (requestUrl, state, featureDetector) {
// TODO: redirect to `ipfs://` if inBrowserWithNativeProtocol() === true
const gwUrl = featureDetector.embeddedNodeIsActive() ? state.pubGwURL : state.gwURL
Copy link
Member

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.

@lidel
Copy link
Member Author

lidel commented Feb 20, 2018

@alanshaw simplified things just like you sugested in #381 (review):

  • state-based checks are inlined
  • remaining runtime checks are no longer functions but precomputed booleans

Ok to merge?

@alanshaw
Copy link
Member

🚀 👍

- 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
@lidel lidel force-pushed the fix/automatic-mode-when-start-offline branch from 1d29651 to bd3368d Compare February 20, 2018 16:18
@lidel lidel merged commit f91107d into master Feb 20, 2018
@lidel lidel deleted the fix/automatic-mode-when-start-offline branch February 20, 2018 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pinning does not work on Firefox when using js-ipfs node Daemon is off but redirect is still enabled
3 participants