Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented page continuing (#29) #39

Merged
merged 4 commits into from
Jul 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const {

const electron = require('electron')

const electronConnect = require('electron-connect');

let win

function createWindow() {
Expand All @@ -34,11 +32,8 @@ function createWindow() {

win.loadURL(`file://${__dirname}/bundle/index.html`)

const client = electronConnect.client.create(win);

win.on("closed", () => {
win = null;
client.sendMessage('closed');
});

}
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"build": "babel src/ -d bundle/",
"dev": "node dev-runner.js",
"clean": "rm bundle/**/**/*.js bundle/**/*.js bundle/*.js ",
"package-x86": "electron-packager . --overwrite --platform=linux --arch=ia32 --icon=assets/img/icon.png --prune=true --out=release-builds --electron-version=1.6.6",
"package-x64": "electron-packager . --overwrite --platform=linux --arch=x64 --icon=assets/img/icon.png --prune=true --out=release-builds --electron-version=1.6.6",
"package-mac-x64": "electron-packager . --overwrite --platform=mas --arch=x64 --icon=assets/img/icons/icon256x256.icns --prune=true --out=release-builds --electron-version=1.6.6",
"package-win-x86": "electron-packager . --overwrite --platform=win32 --arch=x86 --icon=assets/img/icon.png --prune=true --out=release-builds --electron-version=1.6.6",
"package-win-x64": "electron-packager . --overwrite --platform=win32 --arch=x64 --icon=assets/img/icon.png --prune=true --out=release-builds --electron-version=1.6.6",
"package-x86": "electron-packager . --overwrite --platform=linux --arch=ia32 --icon=assets/img/icon.png --prune=true --out=release-builds --electron-version=4.0.0",
"package-x64": "electron-packager . --overwrite --platform=linux --arch=x64 --icon=assets/img/icon.png --prune=true --out=release-builds --electron-version=4.0.0",
"package-mac-x64": "electron-packager . --overwrite --platform=mas --arch=x64 --icon=assets/img/icons/icon256x256.icns --prune=true --out=release-builds --electron-version=4.0.0",
"package-win-x86": "electron-packager . --overwrite --platform=win32 --arch=x86 --icon=assets/img/icon.png --prune=true --out=release-builds --electron-version=4.0.0",
"package-win-x64": "electron-packager . --overwrite --platform=win32 --arch=x64 --icon=assets/img/icon.png --prune=true --out=release-builds --electron-version=4.0.0",
"installer-x86": "electron-installer-debian --src release-builds/Buka-linux-ia32/ --arch i386 --dest dest/installers/ --icon assets/img/icon.png",
"installer-x64": "electron-installer-debian --src release-builds/Buka-linux-x64/ --arch amd64 --dest dest/installers/ --icon assets/img/icon.png",
"installer-win-x86": "electron-installer-windows --src release-builds/Buka-win32-ia32/ --arch i386 --dest dest/installers/ --icon assets/img/icon.png",
Expand Down Expand Up @@ -61,7 +61,7 @@
"babel-cli": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"electron": "^1.6.6",
"electron": "^4.0.0",
"electron-connect": "^0.6.3",
"node-watch": "^0.5.7"
}
Expand Down
2 changes: 1 addition & 1 deletion pdfviewer/web/viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@
<script src="viewer.js"></script>

<script>

document.PDFViewerApplication = PDFViewerApplication
</script>

</html>
Expand Down
62 changes: 49 additions & 13 deletions src/store/modules/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,55 @@ const actions = {
* @param {string} bookPath
*/
openBook({ rootState }, bookPath) {
rootState.app.openedBookPath = '../pdfviewer/web/viewer.html?file=' + bookPath
rootState.app.toggleBooksContent = false

// The address of the external links clicked in the book is given to the input named <externalLink>.
try {
document.getElementById('book-viewer-iframe').onload = () => {
let externalLink = document.getElementById('book-viewer-iframe').contentDocument.getElementById('externalLink')
// Where the input named <externalLink> is listened to and opened on the browser when the value changes.
if (externalLink)
externalLink.onchange = () => shell.openExternal(externalLink.value)
let Datastore = require('nedb')
let db = new Datastore({ filename: 'locations.json', autoload: true })

db.find({ path: bookPath }, function (err, docs) {
let currentPage = 1

if (docs.length === 0) {
// Page was not found. Initialize book in db to page 1
db.insert({ path: bookPath, page: 1 })
} else if (err) {
// Error
console.log(err)
} else {
// Page number was found. Set initial page.
currentPage = docs[0].page
}
}
catch (err) { }

rootState.app.openedBookPath = '../pdfviewer/web/viewer.html' + '?file=' + bookPath
rootState.app.toggleBooksContent = false

// The address of the external links clicked in the book is given to the input named <externalLink>.
try {
document.getElementById('book-viewer-iframe').onload = () => {
let viewerDocument = document.getElementById('book-viewer-iframe').contentDocument

let externalLink = viewerDocument.getElementById('externalLink')

// Where the input named <externalLink> is listened to and opened on the browser when the value changes.
if (externalLink) {
externalLink.onchange = () => shell.openExternal(externalLink.value)
}

let app = viewerDocument.PDFViewerApplication

if (app) {
const updatePageIfNecessary = () => {
if (app.page != currentPage) {
currentPage = app.page
db.update({ path: bookPath }, { path: bookPath, page: currentPage })
}
}

app.page = currentPage
setInterval(updatePageIfNecessary, 100)
}
}
}
catch (err) { }
})
},
/**
* The book selected from the book content removes.
Expand All @@ -29,7 +65,7 @@ const actions = {
*/
removeBook({ commit }, args) {
// remove the book image.
fs.unlink(args.bookImagePath)
fs.unlinkSync(args.bookImagePath)

let bookCount = 0
bookListDb.find({}, (err, lists) => {
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/book_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const actions = {
bookListDb.findOne({ _id: args.listId }, (err, selectedList) => {
selectedList.books.forEach(book => {
// remove book image
fs.unlink(book.bookImagePath)
fs.unlinkSync(book.bookImagePath)

// does the book author have another book?
// if there is no other book, the author is deleted.
Expand Down
Loading