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

Ship the new WebUI #590

Merged
merged 8 commits into from
Oct 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions add-on/src/lib/ipfs-client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function initIpfsClient (opts) {
}

const instance = await client.init(opts)
await _reloadIpfsClientDependents()
_reloadIpfsClientDependents() // async (API is present)
return instance
}

Expand All @@ -26,18 +26,24 @@ async function destroyIpfsClient () {
await client.destroy()
} finally {
client = null
await _reloadIpfsClientDependents()
await _reloadIpfsClientDependents() // sync (API stopped working)
}
}
}

function _isWebuiTab (url) {
const bundled = !url.startsWith('http') && url.includes('/webui/index.html#/')
const ipns = url.includes('/webui.ipfs.io/#/')
Copy link
Member Author

@lidel lidel Oct 4, 2018

Choose a reason for hiding this comment

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

@olizilla FYI this is part of #590. It will detect webui loaded from:

  • https://webui.ipfs.io
  • http://127.0.0.1:8080/ipns/webui.ipfs.io

And reload it when companion API state changes (on/off/port change etc)

Copy link
Member

Choose a reason for hiding this comment

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

#/ will only be added by the app after the initial bundle has loaded (unless the user has bookmarked it explicitly)...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that was on purpose to remove false-positive matches on random websites and avoid double-reload when quickly switching between backends.

return bundled || ipns
}

async function _reloadIpfsClientDependents () {
if (browser.tabs && browser.tabs.query) {
const tabs = await browser.tabs.query({})
if (tabs) {
tabs.forEach((tab) => {
// detect bundled webui in any of open tabs
if (!tab.url.startsWith('http') && tab.url.includes('/webui/index.html#/')) {
if (_isWebuiTab(tab.url)) {
browser.tabs.reload(tab.id)
console.log('[ipfs-companion] reloading bundled webui')
}
Expand Down
1 change: 1 addition & 0 deletions add-on/src/popup/browser-action/context-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = function contextActions ({
})}
${navItem({
text: browser.i18n.getMessage(contextMenuCopyRawCid),
disabled: !activePinControls,
onClick: () => onCopy(contextMenuCopyRawCid)
})}
${!isPinned ? (
Expand Down