Merge pull request #984 from mozilla/droid-ui-2

wip on using shared ui in android
This commit is contained in:
Danny Coates 2018-11-06 11:33:10 -08:00 committed by GitHub
commit 064077d706
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 108 additions and 184 deletions

3
.gitignore vendored
View File

@ -6,8 +6,7 @@ dist
.nyc_output .nyc_output
.tox .tox
.pytest_cache .pytest_cache
android/app/src/main/assets/vendor.js android/app/src/main/assets
android/app/src/main/assets/android.js
ios/send-ios/assets/ios.js ios/send-ios/assets/ios.js
ios/send-ios/assets/vendor.js ios/send-ios/assets/vendor.js
ios/send-ios.xcodeproj/project.xcworkspace/xcuserdata/* ios/send-ios.xcodeproj/project.xcworkspace/xcuserdata/*

View File

@ -20,12 +20,42 @@ window.DEFAULTS = {
}; };
const choo = require('choo'); const choo = require('choo');
const html = require('choo/html');
const assets = require('../common/assets');
const header = require('../app/ui/header');
const locale = require('../common/locales');
const home = require('../app/ui/home');
const app = choo(); const app = choo();
function body(main) {
return function(state, emit) {
return html`<body class="flex flex-col items-center font-sans bg-blue-lightest md:h-screen md:bg-grey-lightest">
${header(state, emit)}
<a id="hamburger" class="absolute pin-t pin-r z-50" href="#" onclick=${clickPreferences}>
<img src=${assets.get('preferences.png')} />
</a>
${main(state, emit)}
</body>`;
function clickPreferences(event) {
event.preventDefault();
emit('pushState', '/preferences');
}
};
}
app.use((state, emitter) => {
state.translate = locale.getTranslator();
state.capabilities = {}; //TODO
// for debugging
window.appState = state;
window.appEmit = emitter.emit.bind(emitter);
});
app.use(require('./stores/state').default); app.use(require('./stores/state').default);
app.use(require('../app/fileManager').default); app.use(require('../app/fileManager').default);
app.use(require('./stores/intents').default); app.use(require('./stores/intents').default);
app.route('/', require('./pages/home').default); app.route('/', body(home));
app.route('/options', require('./pages/options').default); app.route('/options', require('./pages/options').default);
app.route('/upload', require('./pages/upload').default); app.route('/upload', require('./pages/upload').default);
app.route('/share/:id', require('./pages/share').default); app.route('/share/:id', require('./pages/share').default);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 305 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1,124 +0,0 @@
html {
height: 100vh;
}
body {
box-sizing: border-box;
margin: 0;
min-height: 100vh;
background-image: repeating-linear-gradient(
45deg,
white,
white 5px,
#ea000e 5px,
#ea000e 25px,
white 25px,
white 30px,
#0083ff 30px,
#0083ff 50px
);
}
#white {
display: flex;
flex-direction: column;
min-height: 100vh;
background-color: white;
margin: 0 10px;
padding: 10px;
text-align: center;
}
#centering {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
height: 100%;
width: 100%;
}
#label {
position: fixed;
right: 2em;
bottom: 1em;
}
#label img {
height: 60px;
width: 60px;
}
#input {
display: none;
}
#url {
display: none;
}
#copy-link {
text-align: right;
}
#copy-image {
position: relative;
top: 6px;
height: 30px;
width: 30px;
}
.spacer {
height: 12em;
}
#send-another {
margin-bottom: 1em;
height: 60px;
width: 60px;
position: fixed;
right: 2em;
bottom: 1em;
}
.card {
margin: 6px;
padding: 6px;
border: 1px solid white;
border-radius: 5px;
box-shadow: 5px 5px 5px 5px #d5d5d5;
text-align: left;
}
.progress {
display: inline-block;
height: 4px;
border-radius: 2px;
background-color: #1b96ef;
color: white;
}
.cancel {
text-align: right;
}
#preferences {
text-align: left;
}
#hamburger {
position: fixed;
right: 2em;
top: 1em;
}
#top-banner {
position: fixed;
top: 1em;
left: 2em;
}
#options {
text-align: left;
}

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Firefox Send</title>
<link href="index.css" rel="stylesheet">
</head>
<body>
<script src="vendor.js"></script>
<script src="android.js"></script>
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

View File

@ -56,7 +56,7 @@ class MainActivity : AppCompatActivity(), AdvancedWebView.Listener {
// val stream = contentResolver.openInputStream(imageUri) // val stream = contentResolver.openInputStream(imageUri)
} }
} }
mWebView!!.loadUrl("file:///android_asset/index.html") mWebView!!.loadUrl("file:///android_asset/android.html")
} }
@SuppressLint("NewApi") @SuppressLint("NewApi")

View File

@ -1,21 +1,10 @@
const child_process = require('child_process'); const child_process = require('child_process');
const fs = require('fs');
const path = require('path'); const path = require('path');
child_process.execSync('npm run build'); child_process.execSync('npm run build');
child_process.execSync(
const prefix = path.join('..', '..', 'dist'); `cp -R ${path.resolve(__dirname, '../dist')} ${path.resolve(
const json_string = fs.readFileSync(path.join(prefix, 'manifest.json')); __dirname,
const manifest = JSON.parse(json_string); 'app/src/main/assets'
)}`
const android_filename = manifest['android.js'];
fs.writeFileSync(
'src/main/assets/android.js',
fs.readFileSync(`${prefix}${android_filename}`)
);
const vendor_filename = manifest['vendor.js'];
fs.writeFileSync(
'src/main/assets/vendor.js',
fs.readFileSync(`${prefix}${vendor_filename}`)
); );

View File

@ -12,9 +12,6 @@ export default function initialState(state, emitter) {
getAsset(name) { getAsset(name) {
return `${state.prefix}/${name}`; return `${state.prefix}/${name}`;
}, },
translate: (...toTranslate) => {
return toTranslate.map(o => JSON.stringify(o)).toString();
},
raven: { raven: {
captureException: e => { captureException: e => {
console.error('ERROR ' + e + ' ' + e.stack); console.error('ERROR ' + e + ' ' + e.stack);

View File

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@ -0,0 +1,57 @@
const path = require('path');
const html = require('choo/html');
const NAME = 'AndroidIndexPlugin';
function chunkFileNames(compilation) {
const names = {};
for (const chunk of compilation.chunks) {
for (const file of chunk.files) {
if (!/\.map$/.test(file)) {
names[`${chunk.name}${path.extname(file)}`] = file;
}
}
}
return names;
}
class AndroidIndexPlugin {
apply(compiler) {
const assets = {};
compiler.hooks.compilation.tap(NAME, compilation => {
compilation.hooks.moduleAsset.tap(NAME, (mod, file) => {
if (mod.userRequest) {
assets[
path.join(path.dirname(file), path.basename(mod.userRequest))
] = file;
}
});
});
compiler.hooks.emit.tap(NAME, compilation => {
const files = chunkFileNames(compilation);
const page = html`
<html lang="en-US">
<head>
<title>Firefox Send</title>
<link href="${files['app.css']}" rel="stylesheet">
<script src="${files['vendor.js']}"></script>
<script src="${assets['public/locales/en-US/send.ftl']}"></script>
<script src="${files['android.js']}"></script>
</head>
<body>
</body>
</html>
`
.toString()
.replace(/\n\s{6}/g, '\n');
compilation.assets['android.html'] = {
source() {
return page;
},
size() {
return page.length;
}
};
});
}
}
module.exports = AndroidIndexPlugin;

6
package-lock.json generated
View File

@ -16053,9 +16053,9 @@
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
}, },
"puppeteer": { "puppeteer": {
"version": "1.10.0", "version": "1.9.0",
"resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.10.0.tgz", "resolved": "https://registry.npmjs.org/puppeteer/-/puppeteer-1.9.0.tgz",
"integrity": "sha512-3i28X/ucX8t3eL4TZA60FLMOQNKqudFSOGDHr0cT7T4dE027CrcS885aAqjdxNybhMPliM5yImNsKJ6SQrPzhw==", "integrity": "sha512-GH4PmhJf9wBRAPvtJkEJLAvdNNOofZortmBZSj8cGWYni98GUFqsf66blOEfJbo5B8l0KG5HR2d/W2MejnUrzg==",
"dev": true, "dev": true,
"requires": { "requires": {
"debug": "^3.1.0", "debug": "^3.1.0",

View File

@ -103,7 +103,7 @@
"postcss-preset-env": "^6.3.1", "postcss-preset-env": "^6.3.1",
"prettier": "^1.14.3", "prettier": "^1.14.3",
"proxyquire": "^2.1.0", "proxyquire": "^2.1.0",
"puppeteer": "^1.10.0", "puppeteer": "1.9.0",
"raven-js": "^3.27.0", "raven-js": "^3.27.0",
"redis-mock": "^0.37.0", "redis-mock": "^0.37.0",
"require-from-string": "^2.0.2", "require-from-string": "^2.0.2",

View File

@ -1,5 +1,3 @@
const fs = require('fs');
const path = require('path');
const assets = require('../../common/assets'); const assets = require('../../common/assets');
const locales = require('../../common/locales'); const locales = require('../../common/locales');
const routes = require('../routes'); const routes = require('../routes');
@ -12,21 +10,6 @@ const config = require('../config');
const ID_REGEX = '([0-9a-fA-F]{10})'; const ID_REGEX = '([0-9a-fA-F]{10})';
const androidIndex = fs.readFileSync(
path.resolve(__dirname, '../../android/app/src/main/assets/index.html'),
'utf8'
);
function android(req, res) {
res.set('Content-Type', 'text/html');
res.send(
androidIndex
.replace('index.css', '/android_asset/index.css')
.replace('vendor.js', assets.get('vendor.js'))
.replace('android.js', assets.get('android.js'))
);
}
module.exports = function(app, devServer) { module.exports = function(app, devServer) {
const wsapp = express(); const wsapp = express();
expressWs(wsapp, null, { perMessageDeflate: false }); expressWs(wsapp, null, { perMessageDeflate: false });
@ -36,6 +19,13 @@ module.exports = function(app, devServer) {
assets.setMiddleware(devServer.middleware); assets.setMiddleware(devServer.middleware);
locales.setMiddleware(devServer.middleware); locales.setMiddleware(devServer.middleware);
app.use(morgan('dev', { stream: process.stderr })); app.use(morgan('dev', { stream: process.stderr }));
function android(req, res) {
const index = devServer.middleware.fileSystem.readFileSync(
devServer.middleware.getFilenameFromUrl('/android.html')
);
res.set('Content-Type', 'text/html');
res.send(index);
}
if (process.env.ANDROID) { if (process.env.ANDROID) {
// map all html routes to the android index.html // map all html routes to the android index.html
app.get('/', android); app.get('/', android);

View File

@ -3,6 +3,7 @@ const webpack = require('webpack');
const CopyPlugin = require('copy-webpack-plugin'); const CopyPlugin = require('copy-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin'); const ManifestPlugin = require('webpack-manifest-plugin');
const VersionPlugin = require('./build/version_plugin'); const VersionPlugin = require('./build/version_plugin');
const AndroidIndexPlugin = require('./build/android_index_plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin'); const ExtractTextPlugin = require('extract-text-webpack-plugin');
const webJsOptions = { const webJsOptions = {
@ -182,11 +183,6 @@ const web = {
{ {
context: 'public', context: 'public',
from: '*.*' from: '*.*'
},
{
context: 'android/app/src/main/assets',
from: '*.*',
to: 'android_asset'
} }
]), ]),
new webpack.IgnorePlugin(/\.\.\/dist/), // used in common/*.js new webpack.IgnorePlugin(/\.\.\/dist/), // used in common/*.js
@ -196,6 +192,7 @@ const web = {
filename: '[name].[hash:8].css' filename: '[name].[hash:8].css'
}), }),
new VersionPlugin(), new VersionPlugin(),
new AndroidIndexPlugin(),
new ManifestPlugin() // used by server side to resolve hashed assets new ManifestPlugin() // used by server side to resolve hashed assets
], ],
devtool: 'source-map', devtool: 'source-map',