From db9334c084cd4219ae4ec4a60326256d4ea8e330 Mon Sep 17 00:00:00 2001 From: Jessica Schilling Date: Thu, 10 Sep 2020 17:43:46 -0600 Subject: [PATCH 1/7] Stub content for offline page --- add-on/src/landing-pages/offline/index.html | 18 +++++++ add-on/src/landing-pages/offline/index.js | 15 ++++++ add-on/src/landing-pages/offline/offline.css | 13 +++++ add-on/src/landing-pages/offline/page.js | 53 ++++++++++++++++++++ add-on/src/landing-pages/offline/store.js | 40 +++++++++++++++ webpack.config.js | 1 + 6 files changed, 140 insertions(+) create mode 100644 add-on/src/landing-pages/offline/index.html create mode 100644 add-on/src/landing-pages/offline/index.js create mode 100644 add-on/src/landing-pages/offline/offline.css create mode 100644 add-on/src/landing-pages/offline/page.js create mode 100644 add-on/src/landing-pages/offline/store.js diff --git a/add-on/src/landing-pages/offline/index.html b/add-on/src/landing-pages/offline/index.html new file mode 100644 index 000000000..e6ce8ff8a --- /dev/null +++ b/add-on/src/landing-pages/offline/index.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + +
+ + + + + diff --git a/add-on/src/landing-pages/offline/index.js b/add-on/src/landing-pages/offline/index.js new file mode 100644 index 000000000..d792b62fd --- /dev/null +++ b/add-on/src/landing-pages/offline/index.js @@ -0,0 +1,15 @@ +'use strict' +/* eslint-env browser, webextensions */ + +require('./offline.css') + +const browser = require('webextension-polyfill') +const choo = require('choo') +const createOfflinePageStore = require('./store') +const createOfflinePage = require('./page') + +const app = choo() + +app.use(createOfflinePageStore(browser.i18n, browser.runtime)) +app.route('*', createOfflinePage(browser.i18n)) +app.mount('#root') diff --git a/add-on/src/landing-pages/offline/offline.css b/add-on/src/landing-pages/offline/offline.css new file mode 100644 index 000000000..7590711c5 --- /dev/null +++ b/add-on/src/landing-pages/offline/offline.css @@ -0,0 +1,13 @@ +@import url('~tachyons/css/tachyons.css'); +@import url('~ipfs-css/ipfs.css'); +@import url('../../popup/heartbeat.css'); + +/* + https://github.com/tachyons-css/tachyons-queries + Tachyons: $point == large +*/ +@media (min-width: 64em) { +} + +@media (max-height: 800px) { +} diff --git a/add-on/src/landing-pages/offline/page.js b/add-on/src/landing-pages/offline/page.js new file mode 100644 index 000000000..6cc85ae68 --- /dev/null +++ b/add-on/src/landing-pages/offline/page.js @@ -0,0 +1,53 @@ +'use strict' + +const html = require('choo/html') +const logo = require('../../popup/logo') +const { renderTranslatedLinks, renderTranslatedSpans } = require('../../utils/i18n') + +// Assets +const libp2pLogo = '../../../images/libp2p.svg' +const multiformatsLogo = '../../../images/multiformats.svg' +const ipldLogo = '../../../images/ipld.svg' + +// Colors +const colorIpfsLogo = '#57cbd0' +const colorWhite = '#ffffff' +const colorYellow = '#f39021' + +function createOfflinePage (i18n) { + return function offlinePage (state, emit) { + const { isIpfsOnline, peerCount } = state + const openWebUi = (page) => () => emit('openWebUi', page) + + // Set translated title + document.title = i18n.getMessage('page_landingOffline_title') + + return html` +
+
+ +
+
+

Offline error

+

IPFS Companion tried opening the following resource, but failed:

+

window.location.hash123123123123123123123123123

+

+ Your custom local gateway might be offline. You can update your local gateway in the preferences, or try loading this resource from a public gateway instead. +

+
+ + +
+

+ You tried to load a DNSLink-enabled site from a remote host that's currently unavailable. Try loading it from the original host instead. +

+
+ +
+
+
+ ` + } +} + +module.exports = createOfflinePage diff --git a/add-on/src/landing-pages/offline/store.js b/add-on/src/landing-pages/offline/store.js new file mode 100644 index 000000000..e6ccfaf60 --- /dev/null +++ b/add-on/src/landing-pages/offline/store.js @@ -0,0 +1,40 @@ +'use strict' +/* eslint-env browser, webextensions */ +const browser = require('webextension-polyfill') + +function createOfflinePageStore (i18n, runtime) { + return function offlinePageStore (state, emitter) { + state.isIpfsOnline = null + state.peerCount = null + state.webuiRootUrl = null + let port + emitter.on('DOMContentLoaded', async () => { + emitter.emit('render') + port = runtime.connect({ name: 'browser-action-port' }) + port.onMessage.addListener(async (message) => { + if (message.statusUpdate) { + const webuiRootUrl = message.statusUpdate.webuiRootUrl + const peerCount = message.statusUpdate.peerCount + const isIpfsOnline = peerCount > -1 + if (isIpfsOnline !== state.isIpfsOnline || peerCount !== state.peerCount || webuiRootUrl !== state.webuiRootUrl) { + state.webuiRootUrl = webuiRootUrl + state.isIpfsOnline = isIpfsOnline + state.peerCount = peerCount + emitter.emit('render') + } + } + }) + }) + + emitter.on('openWebUi', async (page = '/') => { + const url = `${state.webuiRootUrl}#${page}` + try { + await browser.tabs.create({ url }) + } catch (error) { + console.error(`Unable Open Web UI (${url})`, error) + } + }) + } +} + +module.exports = createOfflinePageStore diff --git a/webpack.config.js b/webpack.config.js index 0e2d5264e..df56924c6 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -141,6 +141,7 @@ const uiConfig = merge(commonConfig, { browserAction: './add-on/src/popup/browser-action/index.js', pageAction: './add-on/src/popup/page-action/index.js', importPage: './add-on/src/popup/quick-import.js', + offlinePage: './add-on/src/landing-pages/offline/index.js', optionsPage: './add-on/src/options/options.js', proxyAclManagerPage: './add-on/src/pages/proxy-acl/index.js', proxyAclDialog: './add-on/src/pages/proxy-access-dialog/index.js', From 296e0ff9aabdbee84e339e092eabb52c534cc3b1 Mon Sep 17 00:00:00 2001 From: Jessica Schilling Date: Thu, 10 Sep 2020 17:53:38 -0600 Subject: [PATCH 2/7] CSS tweak --- add-on/src/landing-pages/offline/page.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/add-on/src/landing-pages/offline/page.js b/add-on/src/landing-pages/offline/page.js index 6cc85ae68..a17d3a071 100644 --- a/add-on/src/landing-pages/offline/page.js +++ b/add-on/src/landing-pages/offline/page.js @@ -24,7 +24,7 @@ function createOfflinePage (i18n) { return html`
-
+
From f9b8933c54e1e724d78fe48f6d4a38ae28339a65 Mon Sep 17 00:00:00 2001 From: Jessica Schilling Date: Fri, 11 Sep 2020 12:50:18 -0600 Subject: [PATCH 3/7] Add third scenario --- add-on/src/landing-pages/offline/page.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/add-on/src/landing-pages/offline/page.js b/add-on/src/landing-pages/offline/page.js index a17d3a071..961e18c75 100644 --- a/add-on/src/landing-pages/offline/page.js +++ b/add-on/src/landing-pages/offline/page.js @@ -39,11 +39,17 @@ function createOfflinePage (i18n) {

- You tried to load a DNSLink-enabled site from a remote host that's currently unavailable. Try loading it from the original host instead. + You tried to load a DNSLink-enabled site from a custom local gateway that's currently unavailable. Try loading it from the original host instead.

+

+ You tried to load a DNSLink-enabled site from a host that's currently unavailable. Try loading it from the local/public gateway instead. +

+
+ +
` From c3f884402cdde2f8b07fced99492ac9d38c27ad4 Mon Sep 17 00:00:00 2001 From: Jessica Schilling Date: Fri, 11 Sep 2020 13:34:46 -0600 Subject: [PATCH 4/7] Remove unneeded code --- add-on/src/landing-pages/offline/index.html | 1 - add-on/src/landing-pages/offline/index.js | 4 -- add-on/src/landing-pages/offline/offline.css | 13 ------- add-on/src/landing-pages/offline/page.js | 15 +------- add-on/src/landing-pages/offline/store.js | 40 -------------------- 5 files changed, 1 insertion(+), 72 deletions(-) delete mode 100644 add-on/src/landing-pages/offline/offline.css delete mode 100644 add-on/src/landing-pages/offline/store.js diff --git a/add-on/src/landing-pages/offline/index.html b/add-on/src/landing-pages/offline/index.html index e6ce8ff8a..533b6d560 100644 --- a/add-on/src/landing-pages/offline/index.html +++ b/add-on/src/landing-pages/offline/index.html @@ -6,7 +6,6 @@ - diff --git a/add-on/src/landing-pages/offline/index.js b/add-on/src/landing-pages/offline/index.js index d792b62fd..4db7b50da 100644 --- a/add-on/src/landing-pages/offline/index.js +++ b/add-on/src/landing-pages/offline/index.js @@ -1,15 +1,11 @@ 'use strict' /* eslint-env browser, webextensions */ -require('./offline.css') - const browser = require('webextension-polyfill') const choo = require('choo') -const createOfflinePageStore = require('./store') const createOfflinePage = require('./page') const app = choo() -app.use(createOfflinePageStore(browser.i18n, browser.runtime)) app.route('*', createOfflinePage(browser.i18n)) app.mount('#root') diff --git a/add-on/src/landing-pages/offline/offline.css b/add-on/src/landing-pages/offline/offline.css deleted file mode 100644 index 7590711c5..000000000 --- a/add-on/src/landing-pages/offline/offline.css +++ /dev/null @@ -1,13 +0,0 @@ -@import url('~tachyons/css/tachyons.css'); -@import url('~ipfs-css/ipfs.css'); -@import url('../../popup/heartbeat.css'); - -/* - https://github.com/tachyons-css/tachyons-queries - Tachyons: $point == large -*/ -@media (min-width: 64em) { -} - -@media (max-height: 800px) { -} diff --git a/add-on/src/landing-pages/offline/page.js b/add-on/src/landing-pages/offline/page.js index 961e18c75..45d208990 100644 --- a/add-on/src/landing-pages/offline/page.js +++ b/add-on/src/landing-pages/offline/page.js @@ -1,23 +1,10 @@ 'use strict' const html = require('choo/html') -const logo = require('../../popup/logo') const { renderTranslatedLinks, renderTranslatedSpans } = require('../../utils/i18n') -// Assets -const libp2pLogo = '../../../images/libp2p.svg' -const multiformatsLogo = '../../../images/multiformats.svg' -const ipldLogo = '../../../images/ipld.svg' - -// Colors -const colorIpfsLogo = '#57cbd0' -const colorWhite = '#ffffff' -const colorYellow = '#f39021' - function createOfflinePage (i18n) { - return function offlinePage (state, emit) { - const { isIpfsOnline, peerCount } = state - const openWebUi = (page) => () => emit('openWebUi', page) + return function offlinePage (emit) { // Set translated title document.title = i18n.getMessage('page_landingOffline_title') diff --git a/add-on/src/landing-pages/offline/store.js b/add-on/src/landing-pages/offline/store.js deleted file mode 100644 index e6ccfaf60..000000000 --- a/add-on/src/landing-pages/offline/store.js +++ /dev/null @@ -1,40 +0,0 @@ -'use strict' -/* eslint-env browser, webextensions */ -const browser = require('webextension-polyfill') - -function createOfflinePageStore (i18n, runtime) { - return function offlinePageStore (state, emitter) { - state.isIpfsOnline = null - state.peerCount = null - state.webuiRootUrl = null - let port - emitter.on('DOMContentLoaded', async () => { - emitter.emit('render') - port = runtime.connect({ name: 'browser-action-port' }) - port.onMessage.addListener(async (message) => { - if (message.statusUpdate) { - const webuiRootUrl = message.statusUpdate.webuiRootUrl - const peerCount = message.statusUpdate.peerCount - const isIpfsOnline = peerCount > -1 - if (isIpfsOnline !== state.isIpfsOnline || peerCount !== state.peerCount || webuiRootUrl !== state.webuiRootUrl) { - state.webuiRootUrl = webuiRootUrl - state.isIpfsOnline = isIpfsOnline - state.peerCount = peerCount - emitter.emit('render') - } - } - }) - }) - - emitter.on('openWebUi', async (page = '/') => { - const url = `${state.webuiRootUrl}#${page}` - try { - await browser.tabs.create({ url }) - } catch (error) { - console.error(`Unable Open Web UI (${url})`, error) - } - }) - } -} - -module.exports = createOfflinePageStore From cea501a8220af04552884656719cfb49e9d3bdb2 Mon Sep 17 00:00:00 2001 From: Jessica Schilling Date: Fri, 11 Sep 2020 13:51:21 -0600 Subject: [PATCH 5/7] Text to i18n keys --- add-on/_locales/en/messages.json | 36 ++++++++++++++++++++++++ add-on/src/landing-pages/offline/page.js | 24 ++++++---------- 2 files changed, 45 insertions(+), 15 deletions(-) diff --git a/add-on/_locales/en/messages.json b/add-on/_locales/en/messages.json index 92db3bc6f..43ccd6b31 100644 --- a/add-on/_locales/en/messages.json +++ b/add-on/_locales/en/messages.json @@ -655,6 +655,42 @@ "message": "Deny", "description": "Button text for denying a permission (page_proxyAccessDialog_allowButton_text)" }, + "page_landingOffline_title": { + "message": "Offline Error | IPFS Companion", + "description": "Page title (page_landingOffline_title)" + }, + "page_landingOffline_subtitle": { + "message": "IPFS Companion tried opening the following resource, but failed:", + "description": "Page subtitle (page_landingOffline_subtitle)" + }, + "page_landingOffline_gatewayOffline_text": { + "message": "Your custom local gateway might be offline. You can update your local gateway in the preferences, or try loading this resource from a public gateway instead.", + "description": "Offline error message copy (page_landingOffline_gatewayOffline_text)" + }, + "page_landingOffline_gatewayOffline_updatePrefsButton_text": { + "message": "Update Preferences", + "description": "Offline error message button text for opening Companion preferences (page_landingOffline_gatewayOffline_updatePrefsButton_text)" + }, + "page_landingOffline_gatewayOffline_publicGatewayButton_text": { + "message": "Try Public Gateway", + "description": "Offline error message button text for loading from public gateway (page_landingOffline_gatewayOffline_publicGatewayButton_text)" + }, + "page_landingOffline_dnsLinkGatewayUnavailable_text": { + "message": "You tried to load a DNSLink-enabled site from a custom local gateway that's currently unavailable. Try loading it from the original host instead.", + "description": "Offline error message copy (page_landingOffline_dnsLinkGatewayUnavailable_text)" + }, + "page_landingOffline_dnsLinkGatewayUnavailable_useOriginalHostButton_text": { + "message": "Use Original Host", + "description": "Offline error message button text for loading from original host (page_landingOffline_dnsLinkGatewayUnavailable_useOriginalHostButton_text)" + }, + "page_landingOffline_dnsLinkHostUnavailable_text": { + "message": "You tried to load a DNSLink-enabled site from a host that's currently unavailable. Try loading it from the local/public gateway instead.", + "description": "Offline error message copy (page_landingOffline_dnsLinkHostUnavailable_text)" + }, + "page_landingOffline_dnsLinkHostUnavailable_useOriginalHostButton_text": { + "message": "Use Local/Public Gateway", + "description": "Offline error message button text for loading from local/public gateway (page_landingOffline_dnsLinkHostUnavailable_useOriginalHostButton_text)" + }, "page_landingWelcome_title": { "message": "Welcome | IPFS Companion", "description": "Page title (page_landingWelcome_title)" diff --git a/add-on/src/landing-pages/offline/page.js b/add-on/src/landing-pages/offline/page.js index 45d208990..4dbf64e3f 100644 --- a/add-on/src/landing-pages/offline/page.js +++ b/add-on/src/landing-pages/offline/page.js @@ -15,27 +15,21 @@ function createOfflinePage (i18n) {
-

Offline error

-

IPFS Companion tried opening the following resource, but failed:

+

${i18n.getMessage('page_landingOffline_title')}

+

${i18n.getMessage('page_landingOffline_subtitle')}

window.location.hash123123123123123123123123123

-

- Your custom local gateway might be offline. You can update your local gateway in the preferences, or try loading this resource from a public gateway instead. -

+

${i18n.getMessage('page_landingOffline_gatewayOffline_text')}

- - + +
-

- You tried to load a DNSLink-enabled site from a custom local gateway that's currently unavailable. Try loading it from the original host instead. -

+

${i18n.getMessage('page_landingOffline_dnsLinkGatewayUnavailable_text')}

- +
-

- You tried to load a DNSLink-enabled site from a host that's currently unavailable. Try loading it from the local/public gateway instead. -

+

${i18n.getMessage('page_landingOffline_dnsLinkHostUnavailable_text')}

- +
From ed6129182f880a5de90696c27564d94ff6ca6394 Mon Sep 17 00:00:00 2001 From: Jessica Schilling Date: Fri, 11 Sep 2020 13:59:04 -0600 Subject: [PATCH 6/7] i18n: disambiguate title/head/subhead --- add-on/_locales/en/messages.json | 8 ++++++-- add-on/src/landing-pages/offline/page.js | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/add-on/_locales/en/messages.json b/add-on/_locales/en/messages.json index 43ccd6b31..43fb0e81d 100644 --- a/add-on/_locales/en/messages.json +++ b/add-on/_locales/en/messages.json @@ -659,9 +659,13 @@ "message": "Offline Error | IPFS Companion", "description": "Page title (page_landingOffline_title)" }, - "page_landingOffline_subtitle": { + "page_landingOffline_head": { + "message": "Offline Error", + "description": "Page header (page_landingOffline_head)" + }, + "page_landingOffline_subhead": { "message": "IPFS Companion tried opening the following resource, but failed:", - "description": "Page subtitle (page_landingOffline_subtitle)" + "description": "Page subheader (page_landingOffline_subhead)" }, "page_landingOffline_gatewayOffline_text": { "message": "Your custom local gateway might be offline. You can update your local gateway in the preferences, or try loading this resource from a public gateway instead.", diff --git a/add-on/src/landing-pages/offline/page.js b/add-on/src/landing-pages/offline/page.js index 4dbf64e3f..f9830b049 100644 --- a/add-on/src/landing-pages/offline/page.js +++ b/add-on/src/landing-pages/offline/page.js @@ -15,8 +15,8 @@ function createOfflinePage (i18n) {
-

${i18n.getMessage('page_landingOffline_title')}

-

${i18n.getMessage('page_landingOffline_subtitle')}

+

${i18n.getMessage('page_landingOffline_head')}

+

${i18n.getMessage('page_landingOffline_subhead')}

window.location.hash123123123123123123123123123

${i18n.getMessage('page_landingOffline_gatewayOffline_text')}

From e76e3e6a2ae65cb9e5f7247e4df651eed9d1ed05 Mon Sep 17 00:00:00 2001 From: Jessica Schilling Date: Fri, 11 Sep 2020 14:03:00 -0600 Subject: [PATCH 7/7] Remove unused vars --- add-on/src/landing-pages/offline/page.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/add-on/src/landing-pages/offline/page.js b/add-on/src/landing-pages/offline/page.js index f9830b049..3d8957398 100644 --- a/add-on/src/landing-pages/offline/page.js +++ b/add-on/src/landing-pages/offline/page.js @@ -1,11 +1,9 @@ 'use strict' const html = require('choo/html') -const { renderTranslatedLinks, renderTranslatedSpans } = require('../../utils/i18n') function createOfflinePage (i18n) { return function offlinePage (emit) { - // Set translated title document.title = i18n.getMessage('page_landingOffline_title')