From 3066b9ef0c4b12423166b87681fa42c9674ccf7e Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Wed, 6 Mar 2019 12:04:26 -0500 Subject: [PATCH] add ui server --- .babelrc | 8 +-- package.json | 13 ++-- src/{renderer => platforms}/web/publish.js | 0 src/platforms/web/server.js | 8 +++ src/renderer/app.js | 62 ------------------- src/renderer/web/index.js | 2 - src/renderer/web/stubs.js | 29 --------- src/ui/component/app/view.jsx | 2 - src/ui/component/dateTime/view.jsx | 6 +- .../component/fileViewer/internal/player.jsx | 2 +- src/ui/component/header/view.jsx | 5 +- src/ui/component/splash/view.jsx | 17 ----- .../wunderbar/internal/autocomplete.jsx | 6 +- src/ui/i18n/index.js | 2 +- src/ui/test.jsx | 1 - webpack.base.config.js | 3 +- webpack.electron.config.js | 10 --- webpack.web.config.js | 10 +-- 18 files changed, 38 insertions(+), 148 deletions(-) rename src/{renderer => platforms}/web/publish.js (100%) create mode 100644 src/platforms/web/server.js delete mode 100644 src/renderer/app.js delete mode 100644 src/renderer/web/index.js delete mode 100644 src/renderer/web/stubs.js delete mode 100644 src/ui/test.jsx diff --git a/.babelrc b/.babelrc index f9f5b62a7..df5b644aa 100644 --- a/.babelrc +++ b/.babelrc @@ -2,9 +2,9 @@ "presets": ["@babel/react", "@babel/flow"], "plugins": [ "react-hot-loader/babel", - ["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true }], - "@babel/plugin-transform-flow-strip-types", - "@babel/plugin-proposal-class-properties", - "babel-plugin-add-module-exports" + ["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": true }], + "@babel/plugin-transform-flow-strip-types", + "@babel/plugin-proposal-class-properties", + "babel-plugin-add-module-exports" ] } diff --git a/package.json b/package.json index a545d5de4..e6e92e0a4 100644 --- a/package.json +++ b/package.json @@ -23,20 +23,21 @@ "compile:electron": "webpack --progress --config webpack.electron.config.js", "compile:web": "webpack --progress --config webpack.web.config.js", "compile": "yarn compile:electron && yarn compile:web", - "build": "yarn compile && electron-builder build", - "build:dir": "yarn build -- --dir -c.compression=store -c.mac.identity=null", "dev:electron": "webpack-dev-server --hot --progress --config webpack.electron.config.js", "dev:web": "webpack-dev-server --hot --progress --config webpack.web.config.js", "dev:internal-apis": "LBRY_API_URL='http://localhost:8080' yarn dev:electron", + "run:electron": "electron ./dist/electron/main.js", + "run:web": "yarn compile:web && node ./dist/web/server.js", + "pack": "electron-builder --dir", + "dist": "electron-builder", + "build": "yarn compile && electron-builder build", + "build:dir": "yarn build -- --dir -c.compression=store -c.mac.identity=null", "lint": "eslint 'src/**/*.{js,jsx}' --fix && flow", "format": "prettier 'src/**/*.{js,jsx,scss,json}' --write", "flow-defs": "flow-typed install", "precommit": "lint-staged", "preinstall": "yarn cache clean lbry-redux && yarn cache clean lbryinc", - "postinstall": "electron-builder install-app-deps && node build/downloadDaemon.js", - "run:electron": "electron ./dist/electron/main.js", - "pack": "electron-builder --dir", - "dist": "electron-builder" + "postinstall": "electron-builder install-app-deps && node build/downloadDaemon.js" }, "dependencies": { "@babel/polyfill": "^7.2.5", diff --git a/src/renderer/web/publish.js b/src/platforms/web/publish.js similarity index 100% rename from src/renderer/web/publish.js rename to src/platforms/web/publish.js diff --git a/src/platforms/web/server.js b/src/platforms/web/server.js new file mode 100644 index 000000000..0404ecba5 --- /dev/null +++ b/src/platforms/web/server.js @@ -0,0 +1,8 @@ +const express = require('express'); +const path = require('path'); +const app = express(); +const port = 1337; + +app.use(express.static(__dirname)); + +app.listen(port, () => console.log(`UI server listening at localhost://${port}`)); diff --git a/src/renderer/app.js b/src/renderer/app.js deleted file mode 100644 index 4f8512f85..000000000 --- a/src/renderer/app.js +++ /dev/null @@ -1,62 +0,0 @@ -/* eslint-disable no-redeclare */ -import store from 'store'; -import Path from 'path'; -// @if TARGET='app' -import y18n from 'y18n'; -import { remote } from 'electron'; -import isDev from 'electron-is-dev'; -// @endif -// @if TARGET='web' -import { y18n } from 'web/stubs'; -// @endif - -// @if TARGET='app' -const env = process.env.NODE_ENV || 'production'; -const i18n = y18n({ - directory: Path.join(remote.app.getAppPath(), '/../static/locales').replace(/\\/g, '\\\\'), - updateFiles: false, - locale: 'en', -}); -// @endif -// @if TARGET='web' -const env = process.env.NODE_ENV || 'development'; -const i18n = y18n({ - updateFiles: false, - locale: 'en', -}); -// @endif - -const logs = []; -const app = { - env, - store, - i18n, - logs, - log(message) { - logs.push(message); - }, -}; - -// @if TARGET='app' -// Workaround for https://github.com/electron-userland/electron-webpack/issues/52 -if (!isDev) { - window.staticResourcesPath = Path.join(remote.app.getAppPath(), '../static').replace( - /\\/g, - '\\\\' - ); -} else { - window.staticResourcesPath = ''; -} -// @endif - -// eslint-disable-next-line no-underscore-dangle -global.__ = i18n.__; -// eslint-disable-next-line no-underscore-dangle -global.__n = i18n.__n; -global.app = app; - -// Lbryinc needs access to the redux store for dispatching auth-releated actions -global.store = app.store; - -export default app; -/* eslint-enable no-redeclare */ diff --git a/src/renderer/web/index.js b/src/renderer/web/index.js deleted file mode 100644 index cb0ddbe75..000000000 --- a/src/renderer/web/index.js +++ /dev/null @@ -1,2 +0,0 @@ -import '../index'; -import './publish'; diff --git a/src/renderer/web/stubs.js b/src/renderer/web/stubs.js deleted file mode 100644 index 94bddc0a3..000000000 --- a/src/renderer/web/stubs.js +++ /dev/null @@ -1,29 +0,0 @@ -const callable = () => { - throw Error('Need to fix this stub'); -}; -const returningCallable = value => () => value; - -export const remote = { - dialog: { - showOpenDialog: callable, - }, - getCurrentWindow: callable, - app: { - getAppPath: callable, - }, - BrowserWindow: { - getFocusedWindow: callable, - }, - Menu: { - getApplicationMenu: callable, - }, - require: callable, -}; - -export const y18n = () => ({ - getLocale: returningCallable('en'), - __: value => value, - __n: value => value, -}); - -export const isDev = false; diff --git a/src/ui/component/app/view.jsx b/src/ui/component/app/view.jsx index a40f7bf0b..cee6db32c 100644 --- a/src/ui/component/app/view.jsx +++ b/src/ui/component/app/view.jsx @@ -113,9 +113,7 @@ class App extends React.PureComponent {
{enhancedLayout && } - {/* @if TARGET='app' */} - {/* @endif */}
diff --git a/src/ui/component/dateTime/view.jsx b/src/ui/component/dateTime/view.jsx index 259bbaa20..9457302d3 100644 --- a/src/ui/component/dateTime/view.jsx +++ b/src/ui/component/dateTime/view.jsx @@ -44,6 +44,10 @@ class DateTime extends React.PureComponent { const { date, formatOptions, timeAgo } = this.props; const show = this.props.show || DateTime.SHOW_BOTH; const locale = i18n.getLocale(); + const locales = ['en-US']; + if (locale) { + locales.push(locale); + } if (timeAgo) { return date ? {moment(date).from(moment())} : ; @@ -53,7 +57,7 @@ class DateTime extends React.PureComponent { {date && (show === DateTime.SHOW_BOTH || show === DateTime.SHOW_DATE) && - date.toLocaleDateString([locale, 'en-US'], formatOptions)} + date.toLocaleDateString(locales, formatOptions)} {show === DateTime.SHOW_BOTH && ' '} {date && (show === DateTime.SHOW_BOTH || show === DateTime.SHOW_TIME) && diff --git a/src/ui/component/fileViewer/internal/player.jsx b/src/ui/component/fileViewer/internal/player.jsx index 6f7fe1cdc..343e5122f 100644 --- a/src/ui/component/fileViewer/internal/player.jsx +++ b/src/ui/component/fileViewer/internal/player.jsx @@ -4,8 +4,8 @@ import * as React from 'react'; // @if TARGET='app' import { remote } from 'electron'; import fs from 'fs'; -import path from 'path'; // @endif +import path from 'path'; import player from 'render-media'; import FileRender from 'component/fileRender'; import LoadingScreen from 'component/common/loading-screen'; diff --git a/src/ui/component/header/view.jsx b/src/ui/component/header/view.jsx index d9f11185b..a7eb1c103 100644 --- a/src/ui/component/header/view.jsx +++ b/src/ui/component/header/view.jsx @@ -80,7 +80,6 @@ const Header = (props: Props) => { - {/* @if TARGET='app' */}
- {/* @endif */}
); }; diff --git a/src/ui/component/splash/view.jsx b/src/ui/component/splash/view.jsx index 246c3a8af..57c0a5a53 100644 --- a/src/ui/component/splash/view.jsx +++ b/src/ui/component/splash/view.jsx @@ -92,18 +92,9 @@ export default class SplashScreen extends React.PureComponent { } updateStatus() { - // @if TARGET='app' Lbry.status().then(status => { this.updateStatusCallback(status); }); - // @endif - // @if TARGET='web' - Lbry.status().then(status => { - Lbry.account_list().then(accountList => { - this.updateStatusCallback(status, accountList); - }); - }); - // @endif } updateStatusCallback(status: Status, accountList: any) { @@ -123,19 +114,11 @@ export default class SplashScreen extends React.PureComponent { const { wallet, blockchain_headers: blockchainHeaders } = status; // If the wallet is locked, stop doing anything and make the user input their password - // @if TARGET='app' if (wallet && wallet.is_locked) { // Clear the error timeout, it might sit on this step for a while until someone enters their password if (this.timeout) { clearTimeout(this.timeout); } - // @endif - // @if TARGET='web' - if (account_list && account_list.encrypted) { - this.setState({ - isRunning: true, - }); - // @endif // Make sure there isn't another active modal (like INCOMPATIBLE_DAEMON) if (launchedModal === false && !modal) { diff --git a/src/ui/component/wunderbar/internal/autocomplete.jsx b/src/ui/component/wunderbar/internal/autocomplete.jsx index 653433152..a35a0a6c2 100644 --- a/src/ui/component/wunderbar/internal/autocomplete.jsx +++ b/src/ui/component/wunderbar/internal/autocomplete.jsx @@ -15,9 +15,9 @@ https://github.com/reactjs/react-autocomplete/issues/239 */ /* eslint-disable */ -const React = require('react'); -const { findDOMNode } = require('react-dom'); -const scrollIntoView = require('dom-scroll-into-view'); +import React from 'react'; +import { findDOMNode } from 'react-dom'; +import scrollIntoView from 'dom-scroll-into-view'; const IMPERATIVE_API = [ 'blur', diff --git a/src/ui/i18n/index.js b/src/ui/i18n/index.js index 9414d2261..b4b3e4c94 100644 --- a/src/ui/i18n/index.js +++ b/src/ui/i18n/index.js @@ -10,7 +10,7 @@ const i18n = y18n({ // @if TARGET='web' const i18n = { setLocale: () => {}, - getLocale: () => {}, + getLocale: () => null, __: x => x, __n: x => x, }; diff --git a/src/ui/test.jsx b/src/ui/test.jsx deleted file mode 100644 index 15091a09a..000000000 --- a/src/ui/test.jsx +++ /dev/null @@ -1 +0,0 @@ -export default () =>

Hello world

; diff --git a/webpack.base.config.js b/webpack.base.config.js index 5c84de536..8eddd9bc7 100644 --- a/webpack.base.config.js +++ b/webpack.base.config.js @@ -1,7 +1,6 @@ const path = require('path'); const merge = require('webpack-merge'); const { DefinePlugin, ProvidePlugin } = require('webpack'); -const nodeExternals = require('webpack-node-externals'); const UI_ROOT = path.resolve(__dirname, 'src/ui/'); const STATIC_ROOT = path.resolve(__dirname, 'static/'); @@ -33,7 +32,7 @@ const baseConfig = { use: { loader: 'file-loader', options: { - outputPath: 'ui/imgs', + outputPath: 'ui/img', name: '[name].[ext]', }, }, diff --git a/webpack.electron.config.js b/webpack.electron.config.js index 1ae4fd73d..60a2c2229 100644 --- a/webpack.electron.config.js +++ b/webpack.electron.config.js @@ -37,11 +37,6 @@ const mainConfig = { }, ], }, - resolve: { - alias: { - // 'src/electron': path.resolve(__dirname, 'src/platforms/electron'); - }, - }, plugins: [ new CopyWebpackPlugin([ { @@ -91,11 +86,6 @@ const renderConfig = { }, ], }, - resolve: { - alias: { - // 'src/electron': path.resolve(__dirname, 'src/platforms/electron'); - }, - }, plugins: [ new CopyWebpackPlugin([ { diff --git a/webpack.web.config.js b/webpack.web.config.js index 1823241cf..fcd949ec4 100644 --- a/webpack.web.config.js +++ b/webpack.web.config.js @@ -5,6 +5,7 @@ const CopyWebpackPlugin = require('copy-webpack-plugin'); const STATIC_ROOT = path.resolve(__dirname, 'static/'); const DIST_ROOT = path.resolve(__dirname, 'dist/'); +const WEB_PLATFORM_ROOT = path.resolve(__dirname, 'src/platforms/web/'); const webConfig = { target: 'web', @@ -41,15 +42,14 @@ const webConfig = { }, plugins: [ new CopyWebpackPlugin([ - { - from: `${STATIC_ROOT}/`, - to: `${DIST_ROOT}/web/static/`, - ignore: ['font/**/*', 'index.html', 'daemon/*'], - }, { from: `${STATIC_ROOT}/index.html`, to: `${DIST_ROOT}/web/index.html`, }, + { + from: `${WEB_PLATFORM_ROOT}/server.js`, + to: `${DIST_ROOT}/web/server.js`, + }, ]), ], };