Skip to content

Commit 07494c9

Browse files
authored
Merge pull request #12 from InfiniteLibrary/builder
Package the app
2 parents 288627c + a99b27b commit 07494c9

35 files changed

+68
-110
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"import/no-unresolved": ["error", { "ignore": ["electron"] }],
1515
"import/no-extraneous-dependencies": "off",
1616
"import/no-dynamic-require": "off",
17+
"jsx-a11y/no-static-element-interactions": "off",
1718
"no-console": "off",
1819
"no-plusplus": "off",
1920
"no-underscore-dangle": "off",

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.png binary
33
*.ico binary
44
*.icns binary
5+
*.ttf binary

app/app.html

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,6 @@
99
integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN"
1010
crossorigin="anonymous"
1111
>
12-
<script>
13-
(function() {
14-
if (!process.env.HOT) {
15-
const link = document.createElement('link');
16-
link.rel = 'stylesheet';
17-
link.href = './dist/style.css';
18-
// HACK: Writing the script path should be done with webpack
19-
document.getElementsByTagName('head')[0].appendChild(link);
20-
}
21-
}());
22-
</script>
2312
</head>
2413
<body>
2514
<div id="root"></div>

app/app.icns

-429 KB
Binary file not shown.
File renamed without changes.

app/components/BookDetails/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import './BookDetails.scss';
55
export default class BookDetails extends Component {
66
render() {
77
const book = this.props.book;
8-
console.log(this.props.book);
9-
108
const bookSummary = {
11-
__html: book.summary || 'No Description Available.' };
9+
__html: book.summary || 'No Description Available.'
10+
};
1211

1312
return (
1413
<div className="book-details">

app/components/Epub/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ class Epub extends Component {
7171
});
7272
}
7373

74-
componentWillUnmount() {
75-
this.rendition.off('keyup', this.keyListener);
76-
document.removeEventListener('keyup', this.keyListener, false);
77-
}
78-
7974
componentWillUpdate(nextProps) {
8075
if (nextProps.location !== this.props.location) {
8176
this.rendition.display(nextProps.location);
@@ -90,8 +85,15 @@ class Epub extends Component {
9085
}
9186
}
9287

88+
componentWillUnmount() {
89+
this.rendition.off('keyup', this.keyListener);
90+
document.removeEventListener('keyup', this.keyListener, false);
91+
}
92+
9393
display(what) {
94-
this.rendition && this.rendition.display(what);
94+
if (this.rendition) {
95+
this.rendition.display(what);
96+
}
9597
}
9698

9799
render() {

app/components/Reader/index.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ class Reader extends Component {
99
constructor(props) {
1010
super(props);
1111
this.handleReady = this.handleReady.bind(this);
12+
this.handleNavReady = this.handleNavReady.bind(this);
1213
}
1314

14-
_navigationReady(nav) {
15+
state = {
16+
isLoading: true,
17+
nav: [],
18+
location: 0
19+
};
20+
21+
handleNavReady(nav) {
1522
this.setState({ ...this.state, nav });
1623
}
1724

18-
_onNavClick(item) {
25+
handleNavClick(item) {
1926
this.setState({ ...this.state, location: item.href });
2027
}
2128

@@ -24,24 +31,13 @@ class Reader extends Component {
2431
}
2532

2633
tocToggle() {
27-
let navMenu = document.getElementById('toc-nav');
34+
const navMenu = document.getElementById('toc-nav');
2835

2936
if (navMenu.classList.contains('is-visible')) {
3037
navMenu.classList.remove('is-visible');
3138
} else {
3239
navMenu.classList.add('is-visible');
3340
}
34-
35-
}
36-
37-
state = {
38-
isLoading: true,
39-
nav: [],
40-
location : 0
41-
};
42-
43-
handleReady() {
44-
this.setState({ ...this.state, isLoading: false });
4541
}
4642

4743
render() {
@@ -53,14 +49,15 @@ class Reader extends Component {
5349
<ul>
5450
<h2>Table of Contents</h2>
5551
{
56-
this.state.nav.map((item, index) =>
57-
<li>
58-
<a key={`navitem_${index}`}
59-
className="reader__toc__item"
60-
onClick={() => {
61-
this._onNavClick(item)
62-
this.tocToggle()
63-
}}>
52+
this.state.nav.map(item =>
53+
<li key={item.id}>
54+
<a
55+
className="reader__toc__item"
56+
onClick={() => {
57+
this.handleNavClick(item);
58+
this.tocToggle();
59+
}}
60+
>
6461
{item.label}
6562
</a>
6663
</li>
@@ -82,7 +79,7 @@ class Reader extends Component {
8279
</div>
8380
</div>
8481
<div className="nav-right">
85-
<a className="nav-item" onClick={() => { this.tocToggle()}}>
82+
<a className="nav-item" onClick={() => { this.tocToggle(); }}>
8683
<span className="icon">
8784
<i className="fa fa-navicon" />
8885
</span>
@@ -92,9 +89,8 @@ class Reader extends Component {
9289
{this.state.isLoading && <Loader />}
9390
<Epub
9491
src={`${getStreamHost()}/${book.id}/${download}/`}
95-
onNavigationReady={ this._navigationReady.bind(this) }
96-
onLocationChanged={(location) => console.log(location)}
97-
onReady={ this.handleReady.bind(this) }
92+
onNavigationReady={this.handleNavReady}
93+
onReady={this.handleReady}
9894
location={this.state.location}
9995
/>
10096
</div>

app/containers/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import React, { Component } from 'react';
55

66
let booksPath;
77
if (process.env.NODE_ENV === 'development') {
8-
booksPath = path.resolve('resources', 'books.json');
8+
booksPath = path.resolve('app', 'books.json');
99
} else {
10-
booksPath = path.resolve(process.resourcesPath, 'books.json');
10+
booksPath = path.resolve(process.resourcesPath, 'app.asar', 'books.json');
1111
}
1212

1313
export default class App extends Component {

app/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "electron-react-boilerplate",
3-
"productName": "electron-react-boilerplate",
4-
"version": "1.0.0",
5-
"description": "Electron application boilerplate based on React, React Router, Webpack, React Hot Loader for rapid application development",
2+
"name": "infinite-electron",
3+
"productName": "Infinite Library Reader",
4+
"version": "0.1.0",
5+
"description": "An Electron based reader for Project Gutenberg books",
66
"main": "./main.js",
77
"author": {
88
"name": "Infinite Library",

app/static/epub.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
}
2424

2525
.book-theme p {
26-
font-weight: 300;
2726
font-size: 18px;
2827
line-height: 1.5;
2928
}
-162 KB
Binary file not shown.
28 Bytes
Binary file not shown.
-143 KB
Binary file not shown.
26 Bytes
Binary file not shown.
30 Bytes
Binary file not shown.

app/streamer/index.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@ import express from 'express';
22
import StreamZip from 'node-stream-zip';
33
import path from 'path';
44
import portfinder from 'portfinder';
5-
import fs from 'mz/fs';
5+
import fs from 'fs';
6+
import pify from 'pify';
67
import fetch from 'node-fetch';
78
import mime from 'mime';
89
import Url from 'url';
910

11+
const access = pify(fs.access);
12+
1013
class Streamer {
1114
constructor(repo, port) {
1215
this.app = express();
1316
this.repo = repo || __dirname;
1417
this.port = port;
1518
this.server = undefined;
1619
this._zips = {};
17-
this.staticPath = path.resolve(__dirname, '..', 'static');
20+
if (process.env.NODE_ENV === 'development') {
21+
this.staticPath = path.resolve(__dirname, '..', 'static');
22+
} else {
23+
this.staticPath = path.resolve(process.resourcesPath, 'app.asar', 'static');
24+
}
1825
}
1926

2027
start() {
@@ -28,11 +35,11 @@ class Streamer {
2835
.then(this.open)
2936
.then((zip) => this.get(zip, req.params.asset))
3037
.then((stream) => {
31-
let asset = req.params.asset;
32-
let path = Url.parse(asset).pathname || '';
33-
let mimeType = mime.lookup(path);
38+
const asset = req.params.asset;
39+
const assetPath = Url.parse(asset).pathname || '';
40+
const mimeType = mime.lookup(assetPath);
3441
res.contentType(mimeType);
35-
stream.pipe(res)
42+
stream.pipe(res);
3643
})
3744
.catch((err) => {
3845
console.error(err);
@@ -73,7 +80,7 @@ class Streamer {
7380

7481
resolveEpub(id, url) {
7582
const bookPath = path.join(this.repo, id);
76-
return fs.access(bookPath, fs.constants.R_OK)
83+
return access(bookPath, fs.constants.R_OK)
7784
.then(
7885
() => bookPath,
7986
// If the book doesn't exist, download it:

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "main.js",
77
"scripts": {
88
"test": "npm run lint",
9-
"lint": "eslint --cache --format=node_modules/eslint-formatter-pretty .",
9+
"lint": "eslint --cache --ignore-path .gitignore --format=node_modules/eslint-formatter-pretty .",
1010
"lint-fix": "npm run lint -- --fix",
1111
"hot-server": "cross-env NODE_ENV=development node --max_old_space_size=2096 -r babel-register server.js",
1212
"build-main": "cross-env NODE_ENV=production node -r babel-register ./node_modules/webpack/bin/webpack --config webpack.config.electron.js --progress --profile --colors",
@@ -23,8 +23,8 @@
2323
},
2424
"browserslist": "electron 1.4",
2525
"build": {
26-
"productName": "ElectronReact",
27-
"appId": "org.develar.ElectronReact",
26+
"productName": "Infinity Library Reader",
27+
"appId": "org.infinity.reader",
2828
"category": "public.app-category.tools",
2929
"dmg": {
3030
"contents": [
@@ -44,10 +44,13 @@
4444
"files": [
4545
"dist/",
4646
"node_modules/",
47+
"static/",
4748
"app.html",
4849
"main.js",
4950
"main.js.map",
50-
"package.json"
51+
"books.json",
52+
"package.json",
53+
"*.png"
5154
],
5255
"win": {
5356
"target": "nsis"
@@ -139,10 +142,11 @@
139142
"epubjs": "beta",
140143
"font-awesome": "^4.7.0",
141144
"lunr": "^0.7.2",
145+
"mime": "^1.3.4",
142146
"mkdirp": "^0.5.1",
143-
"mz": "^2.6.0",
144147
"node-fetch": "^1.6.3",
145148
"node-stream-zip": "^1.3.7",
149+
"pify": "^2.3.0",
146150
"portfinder": "^1.0.13",
147151
"react": "^15.4.2",
148152
"react-dom": "^15.4.2",

resources/icon.icns

20.1 KB
Binary file not shown.

resources/icon.ico

0 Bytes
Binary file not shown.

resources/icon.png

-17.9 KB
Loading

resources/icons/1024x1024.png

-156 KB
Binary file not shown.

resources/icons/128x128.png

-10.2 KB
Loading

resources/icons/16x16.png

-288 Bytes
Loading

resources/icons/24x24.png

-791 Bytes
Loading

resources/icons/256x256.png

-17.9 KB
Loading

resources/icons/32x32.png

-433 Bytes
Loading

resources/icons/48x48.png

-2.47 KB
Loading

resources/icons/512x512.png

-58.4 KB
Loading

resources/icons/64x64.png

-3.66 KB
Loading

resources/icons/96x96.png

-6.96 KB
Loading

webpack.config.base.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export default validate({
1212
test: /\.css$/,
1313
loader: 'style!css'
1414
},
15+
{
16+
test: /\.scss$/,
17+
loader: 'style!css!sass'
18+
},
1519
{
1620
test: /\.jsx?$/,
1721
loaders: ['babel-loader'],

webpack.config.development.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export default validate(merge(baseConfig, {
2828

2929
module: {
3030
loaders: [
31-
{ test: /\.scss$/, loader: 'style!css!sass' },
3231
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff' },
3332
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff' },
3433
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream' },

webpack.config.production.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import path from 'path';
66
import webpack from 'webpack';
77
import validate from 'webpack-validator';
8-
import ExtractTextPlugin from 'extract-text-webpack-plugin';
98
import merge from 'webpack-merge';
109
import HtmlWebpackPlugin from 'html-webpack-plugin';
1110
import BabiliPlugin from 'babili-webpack-plugin';
@@ -23,28 +22,12 @@ export default validate(merge(baseConfig, {
2322

2423
module: {
2524
loaders: [
26-
// Extract all .global.css to style.css as is
27-
{
28-
test: /\.scss$/,
29-
loader: ExtractTextPlugin.extract(
30-
'style-loader',
31-
'css-loader',
32-
'sass-loader'
33-
)
34-
},
35-
3625
// Fonts
3726
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff' },
3827
{ test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/font-woff' },
3928
{ test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=application/octet-stream' },
4029
{ test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'file' },
41-
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml' },
42-
43-
// Images
44-
{
45-
test: /\.(?:ico|gif|png|jpg|jpeg|webp)$/,
46-
loader: 'url-loader'
47-
}
30+
{ test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&mimetype=image/svg+xml' }
4831
]
4932
},
5033

@@ -76,8 +59,6 @@ export default validate(merge(baseConfig, {
7659
deadcode: false,
7760
}),
7861

79-
new ExtractTextPlugin('style.css', { allChunks: true }),
80-
8162
/**
8263
* Dynamically generate index.html page
8364
*/

0 commit comments

Comments
 (0)