From 8a26aaa20150262c66ef832ccb246c879eda7759 Mon Sep 17 00:00:00 2001 From: Diogo Silva Date: Fri, 7 Sep 2018 18:31:16 +0100 Subject: [PATCH] wip: add install steps --- add-on/src/landing-pages/welcome/index.js | 2 +- add-on/src/landing-pages/welcome/page.js | 62 +++++++++++++++++++---- add-on/src/landing-pages/welcome/store.js | 20 +++++++- 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/add-on/src/landing-pages/welcome/index.js b/add-on/src/landing-pages/welcome/index.js index cda481a37..3b9510ace 100644 --- a/add-on/src/landing-pages/welcome/index.js +++ b/add-on/src/landing-pages/welcome/index.js @@ -8,6 +8,6 @@ const createWelcomePage = require('./page') const app = choo() -app.use(createWelcomePageStore(browser.i18n)) +app.use(createWelcomePageStore(browser.i18n, browser.runtime)) app.route('*', createWelcomePage(browser.i18n)) app.mount('#root') diff --git a/add-on/src/landing-pages/welcome/page.js b/add-on/src/landing-pages/welcome/page.js index c287aa19f..c655ef9dd 100644 --- a/add-on/src/landing-pages/welcome/page.js +++ b/add-on/src/landing-pages/welcome/page.js @@ -8,19 +8,15 @@ const libp2pLogo = '../../../images/libp2p.svg' const multiformatsLogo = '../../../images/multiformats.svg' const ipldLogo = '../../../images/ipld.svg' -// Constants -const ipfsLogoWidth = 128 - function createWelcomePage (i18n) { return function welcomePage (state, emit) { + const isIpfsOnline = state.isIpfsOnline + return html`
-
- IPFS Logo -

IPFS Companion

-

You are ready to dive into distributed apps and sites built with IPFS!

- Learn More + ${renderCompanionLogo()} + ${isIpfsOnline ? renderWelcome() : renderInstallSteps()}
@@ -33,6 +29,52 @@ function createWelcomePage (i18n) { } } +/* ======================================================== + Render functions for the left side + ======================================================== */ + +const renderCompanionLogo = () => { + const ipfsLogoWidth = 128 + + return html` +
+ IPFS Logo +

IPFS Companion

+
+ ` +} + +const renderWelcome = () => { + return html` +
+

You are ready to dive into distributed apps and sites built with IPFS!

+ Learn More +
+ ` +} + +const renderInstallSteps = () => { + const copyClass = 'mv0 white f5 lh-copy' + const anchorClass = 'white link underline-under hover-yellow' + + return html` +
+

Is your IPFS daemon running?

+

If you haven't installed IPFS please do so with these instructions.

+

Then make sure to have an IPFS daemon running in your terminal:

+
+ $ ipfs daemon + Initializing daemon... + API server listening on /ip4/127.0.0.1/tcp/5001 +
+
+ ` +} + +/* ======================================================== + Render functions for the right side + ======================================================== */ + const renderResources = () => { const labelClass = 'aqua mb1' const copyClass = 'mt0 mb4 lh-copy' @@ -63,10 +105,10 @@ const renderVideos = () => { const playSvg = () => html` - + - + diff --git a/add-on/src/landing-pages/welcome/store.js b/add-on/src/landing-pages/welcome/store.js index 0f653a354..a485f5c75 100644 --- a/add-on/src/landing-pages/welcome/store.js +++ b/add-on/src/landing-pages/welcome/store.js @@ -1,7 +1,25 @@ 'use strict' +/* eslint-env browser, webextensions */ -function createWelcomePageStore (i18n) { +function createWelcomePageStore (i18n, runtime) { return function welcomePageStore (state, emitter) { + state.isIpfsOnline = null + + const port = runtime.connect({ name: 'browser-action-port' }) + + const onMessage = (message) => { + if (message.statusUpdate) { + const isIpfsOnline = message.statusUpdate.peerCount > -1 + + if (isIpfsOnline !== state.isIpfsOnline) { + state.isIpfsOnline = isIpfsOnline + emitter.emit('render') + } + } + } + + port.onMessage.addListener(onMessage) + emitter.on('DOMContentLoaded', async () => { emitter.emit('render') })