Skip to content

Commit

Permalink
Introduce the Library abstraction
Browse files Browse the repository at this point in the history
Fixes #100.
Closes #107.
  • Loading branch information
baskerville committed May 1, 2020
1 parent 5f402d3 commit 1edfda1
Show file tree
Hide file tree
Showing 67 changed files with 3,202 additions and 2,761 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
/bin
/Settings.toml
/.metadata.json
/.reading-states
/.fat32-epoch
/css/*-user.css
/hyphenation-patterns
/dictionaries
Expand Down
624 changes: 319 additions & 305 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,16 @@ required-features = ["fetcher"]
[dependencies]
bitflags = "1.2.1"
downcast-rs = "1.1.1"
failure = "0.1.6"
failure_derive = "0.1.6"
fnv = "1.0.6"
lazy_static = "1.4.0"
libc = "0.2.67"
png = "0.16.1"
regex = "1.3.4"
serde = "1.0.104"
serde_derive = "1.0.104"
serde_json = "1.0.48"
libc = "0.2.69"
png = "0.16.3"
regex = "1.3.7"
serde = { version = "1.0.106", features = ["derive"] }
serde_json = "1.0.52"
titlecase = "1.1.0"
unicode-normalization = "0.1.12"
glob = "0.3.0"
rand = "0.7.3"
crockford = "1.0.1"
toml = "0.5.6"
zip = "0.5.5"
kl-hyphenate = "0.7.2"
Expand All @@ -50,26 +45,33 @@ rand_xorshift = "0.2.0"
xi-unicode = "0.2.0"
septem = "1.0.1"
byteorder = "1.3.4"
flate2 = "1.0.13"
flate2 = "1.0.14"
levenshtein = "1.0.4"
nix = "0.17.0"
indexmap = { version = "1.3.2", features = ["serde-1"] }
twox-hash = "1.5.0"
anyhow = "1.0.28"
thiserror = "1.0.16"
walkdir = "2.3.1"
globset = "0.4.5"
filetime = "0.2.9"

[dependencies.getopts]
version = "0.2.21"
optional = true

[dependencies.reqwest]
version = "0.10.3"
version = "0.10.4"
features = ["rustls-tls", "json", "blocking"]
default-features = false
optional = true

[dependencies.chrono]
features = ["serde"]
version = "0.4.10"
version = "0.4.11"

[dependencies.sdl2]
version = "0.33.0"
version = "0.34.0"
optional = true

[dependencies.crossbeam-channel]
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@ Any 4.*X*.*Y* firmware, with *X* ≥ 6, will do.

## Supported formats

- PDF and CBZ via [MuPDF](https://mupdf.com/index.html).
- PDF, CBZ, FB2 and XPS via [MuPDF](https://mupdf.com/index.html).
- ePUB through a built-in renderer.
- DJVU via [DjVuLibre](http:https://djvu.sourceforge.net/index.html).

## Features

- Hierarchical categories.
- The metadata for each document is read from a single JSON file.
- Crop the margins.
- Continuous fit-to-width zoom mode with line preserving cuts.
- Rotate the screen (portrait ↔ landscape).
Expand Down
13 changes: 0 additions & 13 deletions doc/CATEGORIES.md

This file was deleted.

9 changes: 0 additions & 9 deletions doc/E-INK.md

This file was deleted.

5 changes: 1 addition & 4 deletions doc/GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ unzip plato-launcher-fmon-VERSION.zip -d SD_ROOT

## Configure

The default library path is `/mnt/onboard` on devices without an external SD card, and `/mnt/sd` otherwise. If your library lives somewhere else, you'll need to create a file named `Settings.toml` in the same directory as the program's binary with the following content:
```toml
library-path = "LIBRARY_PATH"
```
The settings are saved in and read from `Settings.toml`. You can edit this file when *Plato* isn't running or is in shared mode. You can enter the shared mode by connecting your device to a computer.

The default ePUB stylesheet, `css/epub.css`, can be overriden via `css/epub-user.css`.
22 changes: 11 additions & 11 deletions doc/HOOKS.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
Hooks are defined in `Settings.toml`.

Here's an example hook, that launches the default article fetcher included in
Plato's release archive:
*Plato*'s release archive:
```toml
[[home.hooks]]
name = "Articles"
[[libraries.hooks]]
path = "Articles"
program = "bin/article_fetcher/article_fetcher"
sort-method = "added"
second-column = "progress"
```

The `name` key is the name of the category that will trigger the hook. The
The above chunk needs to be added after one of the `[[libraries]]` section.

The `path` key is the path of the directory that will trigger the hook. The
`sort-method` and `second-column` keys are optional.

The *Toogle Hook* sub-menu of the matches menu can be used to trigger a hook when the
corresponding category isn't in the summary bar. Otherwise, you can just tap
the category name in the summary bar. When the hook is triggered, the
associated `program` is spawned. It will receive the category name, wifi and
The *Toogle Select* sub-menu of the library menu can be used to trigger a hook when the
corresponding directory doesn't exit yet. Otherwise, you can just tap
the directory label in the navigation bar. When the hook is triggered, the
associated `program` is spawned. It will receive the directory path, wifi and
online statuses (*true* or *false*) as arguments.

A fetcher can send events to *Plato* through its standard output.
Expand All @@ -28,8 +30,6 @@ Each event is a JSON object with a required `type` key:
// Add a document to the DB. `info` is the camel cased JSON version
// of the `Info` structure defined in `src/metadata.rs`.
{"type": "addDocument", "info": OBJECT}
// Remove a document from the DB. `path` is relative to `library-path`.
{"type": "removeDocument", "path": STRING}
// Enable or disable the WiFi.
{"type": "setWifi", "enable": BOOL}
```
Expand All @@ -39,5 +39,5 @@ On *Plato*'s side, the events are read line by line, one event per line.
When the network becomes operational, *Plato* will send the `SIGUSR1` signal to
all the fetchers.

When the associated category is deselected, *Plato* will send the `SIGTERM`
When the associated directory is deselected, *Plato* will send the `SIGTERM`
signal to the corresponding fetcher.
41 changes: 21 additions & 20 deletions doc/LIBRARY.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,33 @@
## Import Metadata
## Modes

With both modes, the reading states are stored within the `.reading-states` directory.

### Database

The files and directories are read from a cached portion of the filesystem — the database — built and updated during the import phase, stored in `.metadata.json`.

Create an empty database with `plato-import -Z LIBRARY_PATH`.
The shelf displays the descendants of the current directory.

If the command runs successfully, a file named `.metadata.json` will appear in the given directory.
### Filesystem

The initial import is done with `plato-import -I LIBRARY_PATH`. What this does is to search for files in `LIBRARY_PATH` that aren't referenced by `.metadata.json` and save the results in `.metadata-imported.json`.
The files and directories are read directly from the filesystem.

At this stage the imported metadata contains the following keys:
The shelf displays the direct children of the current directory.

- `added`: the date of import.
- `file`: an object with the following keys:
- `path`: the path of the document relative to `LIBRARY_PATH`.
- `kind`: the lowercased file extension.
- `size`: the file size in bytes.
- `categories`: if the document isn't a direct child of `LIBRARY_PATH`, then its relative path will be converted into a category.
## Import Metadata

You can use `plato-import` to off-load the import task to a computer.

The next step is to extract metadata from the ePUB documents: `plato-import -M LIBRARY_PATH`. (Subsequent commands read from **and** write to `.metadata-imported.json`.)
You can import with `plato-import -I LIBRARY_PATH`.

The final step, cleaning up, is achieved with `plato-import -C LIBRARY_PATH`.
If new entries were added, you might populate the metadata with `plato-import -a ADDED_DATETIME -E LIBRARY_PATH` where the argument passed to `-a` is the added date-time of the first added entry (the new entries are at the bottom of the database).

I would recommend adding binding to your text editor to open files at the cursor position (using the double quote characters as boundary) so you can quickly fill out missing information in `.metadata-imported.json`.
You can then edit the database with your text editor to manually fix the metadata.

## Library Synchronization
## Library Backups

You can make a backup of a library with:

Connect your e-reader to your computer. If you're importing for the first time, create and empty database: `plato -Z EREADER_LIBRARY_PATH`. You can then synchronize you device with:
```sh
plato-import -G LIBRARY_PATH EREADER_LIBRARY_PATH`
plato-import -Y LIBRARY_PATH EREADER_LIBRARY_PATH`
rsync -vurt --delete EREADER_LIBRARY_PATH/ COMPUTER_LIBRARY_PATH/`
```

Once you've synchronized all your devices, you might update the local library with `plato-import -G LIBRARY_PATH`.
26 changes: 20 additions & 6 deletions doc/MANUAL.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
# Home

## Summary
The following swipe sequences are recognized:

- Arrow west/east: go to the first/last page.
- Arrow north: set the current directory to the library's path.
- Arrow south: toggle the search bar.

## Address bar

When the navigation bar is present, this optional bar can be shown by swipping from the top bar to the shelf, and hidden by swipping from the shelf to the top bar.

- Tap to select/de-select a category.
- Swipe north to negate/un-negate a category.
- Swipe south from the inside to the outside of the bar to grow it.
- Swipe north from the outside to the inside of the bar to shrink it.
## Navigation bar

This optional bar can be shown by swipping from the top bar to the shelf, and hidden by swipping from the shelf to the top bar.

This bar shows at most `max-levels` directory levels starting at the current directory. It can be used to navigate within the directory hierarchy.

- Tap to select/de-select a directory.
- Swipe north/south to resize.
- Swipe west/east to go to the next/previous page.

## Shelf

This is a view of the books within the current directory.

- Swipe west/east to go to the next/previous page.
- Tap on a book entry to open it.

## Bottom bar

Tap and hold the next/previous page icon to go the last/first page.

Tap the matches count label to bring up the library menu.
Tap the library label to bring up the library menu.

# Reader

Expand Down
8 changes: 6 additions & 2 deletions run-emulator.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#! /bin/sh

if ! [ -e Settings.toml ]; then
echo "library-path = \"${PWD}\"" > Settings.toml
echo "[]" > .metadata.json
cat <<- EOF > Settings.toml
[[libraries]]
name = "Example"
path = "$PWD"
mode = "database"
EOF
fi

./service.sh run_emulator "$@"
Loading

0 comments on commit 1edfda1

Please sign in to comment.