Skip to content

Commit f1118f6

Browse files
committed
Fixes
1 parent 7a5cd9a commit f1118f6

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

Build/src/book.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export async function openBookFromEntry(entry) {
7373
toggleLibrary(false);
7474
showLoading();
7575
try {
76-
const file = (entry && typeof entry.getFile === 'function') ? await entry.getFile() : entry;
76+
const file = (typeof entry?.getFile === 'function') ? await entry.getFile() : entry;
7777
const arrayBuffer = await file.arrayBuffer();
7878
await loadBook(arrayBuffer);
7979
} catch (err) {
@@ -124,6 +124,8 @@ async function loadBook(bookData, startLocation) {
124124
currentPageInput.value = pageNumber + 1;
125125
}
126126
});
127+
window.removeEventListener('keyup', handleKeyEvents);
128+
window.addEventListener('keyup', handleKeyEvents);
127129
window.addEventListener('keyup', handleKeyEvents);
128130
// Set the book title in header if available
129131
try {

Build/src/indexedDB.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ export async function storeLibraryHandle(handle) {
2929
return new Promise((resolve, reject) => {
3030
const tx = db.transaction("handles", "readwrite");
3131
const store = tx.objectStore("handles");
32-
const req = store.put({ name: "library", handle });
33-
req.onsuccess = () => resolve();
34-
req.onerror = e => reject(e.target.error);
32+
store.put({ name: "library", handle });
33+
tx.oncomplete = () => resolve();
34+
tx.onabort = tx.onerror = e => reject(tx.error || (e && e.target && e.target.error));
3535
});
3636
}
37+
3738
/**
3839
* Retrieve the stored library handle from the "handles" object store.
3940
*

Build/src/library.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,22 @@ export async function openLibrary() {
2323
let dirHandle = await getStoredLibraryHandle();
2424
if (!dirHandle) {
2525
// If no stored handle, prompt user
26+
if (!('showDirectoryPicker' in window)) {
27+
// Fallback: trigger multiple file input flow
28+
document.getElementById('library-input')?.click();
29+
return;
30+
}
2631
dirHandle = await window.showDirectoryPicker();
2732
await storeLibraryHandle(dirHandle);
2833
}
34+
// Permissions for persisted handles can be lost between sessions
35+
if (dirHandle.queryPermission && dirHandle.requestPermission) {
36+
const perm = await dirHandle.queryPermission({ mode: 'read' });
37+
if (perm !== 'granted') {
38+
const res = await dirHandle.requestPermission({ mode: 'read' });
39+
if (res !== 'granted') throw new Error('Read permission was denied for the library directory.');
40+
}
41+
}
2942
const files = [];
3043
for await (const entry of dirHandle.values()) {
3144
if (entry.kind === 'file' && entry.name.endsWith('.epub')) {
@@ -38,6 +51,7 @@ export async function openLibrary() {
3851
showError('Failed to open library: ' + err.message);
3952
}
4053
}
54+
4155
/**
4256
* Handle a file-input change by displaying selected EPUB files in the library and opening the library UI.
4357
* @param {Event} e - Change event from a file input (`<input type="file" multiple>`); selected File objects are read and shown in the library grid.

Build/src/style.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ input[type="number"] {
109109
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
110110
transform: translateX(-100%);
111111
transition: transform 0.3s ease;
112-
z-index: 10;
113112
display: flex;
114113
flex-direction: column;
115114
z-index: 1010;

0 commit comments

Comments
 (0)