Skip to content

Commit 6a20160

Browse files
committed
New: Option to open folder/file directly in first image or in continue reading
1 parent a5cf998 commit 6a20160

27 files changed

+216
-42
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
##### 🚀 New Features
1010

1111
- Preliminary support for the `EPUB` format (Alpha) [`24b6494`](https://github.com/ollm/OpenComic/commit/24b6494c00f35dcb5fcea4f2e4cb713a8a130cd9)
12-
- Option to use the first image in the folder/file as a poster
12+
- Option to use the first image in the folder/file as a poster [`a5cf998`](https://github.com/ollm/OpenComic/commit/a5cf998786b17e451ce7d1a8fa24ac287779de44)
13+
- Option to open folder/file directly in first image or in continue reading
1314

1415
##### 🐛 Bug Fixes
1516

languages/ca.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "Navegació (Carpetes)",
181181
"files": "Navegació (Fitxers)",
182182
"ignoreSingleFoldersLibrary": "Ignorar carpetes individuals (S'obren automàticament)",
183+
"whenOpenFolderFirstImageOrContinueReading": "Obrir directament a la primera imatge o en continuar llegint en lloc de la llista de fitxers",
183184
"whenOpenFolderContinueReading": "Obrir directament en continuar llegint en lloc de la llista de fitxers",
184185
"useTheFirstImageAsPoster": "Utilitzar la primera imatge com a pòster (Només si no n'hi ha cap actualment)",
185186
"showFullPathLibrary": "Mostrar la ruta completa a l'obrir els còmics de la biblioteca",

languages/cs.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "",

languages/de.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "",

languages/en.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "Navigation (Folders)",
181181
"files": "Navigation (Files)",
182182
"ignoreSingleFoldersLibrary": "Ignore single folders (Open automatically)",
183+
"whenOpenFolderFirstImageOrContinueReading": "Open directly in first image or in continue reading instead of the file list",
183184
"whenOpenFolderContinueReading": "Open directly in continue reading instead of the file list",
184185
"useTheFirstImageAsPoster": "Use the first image as a poster (Only if there is none currently)",
185186
"showFullPathLibrary": "Show full path when opening library comics",

languages/es.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "Navegación (Carpetas)",
181181
"files": "Navegación (Archivos)",
182182
"ignoreSingleFoldersLibrary": "Ignorar carpetas individuales (Se abren automáticamente)",
183+
"whenOpenFolderFirstImageOrContinueReading": "Abrir directamente en la primera imagen o en continuar leyendo en lugar de la lista de archivos",
183184
"whenOpenFolderContinueReading": "Abrir directamente en continuar leyendo en lugar de la lista de archivos",
184185
"useTheFirstImageAsPoster": "Utilizar la primera imagen como póster (Solo si no hay ninguno actualmente)",
185186
"showFullPathLibrary": "Mostrar la ruta completa al abrir los comics de la biblioteca",

languages/fr.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "",

languages/hu.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "",

languages/it.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "",

languages/ja.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "",

languages/pt-br.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "",

languages/ru.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "",

languages/th.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "ละเว้นโฟลเดอร์เดี่ยว (เปิดอัตโนมัติ)",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "เปิดไปอ่านต่อโดยตรงแทนที่จะเป็นรายการไฟล์",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "แสดงที่ตั้งแบบเต็มเมื่อเปิดห้องสมุดคอมมิกส์",

languages/vi.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "",

languages/zh-hans.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "忽略单个文件夹(自动打开)",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "直接在继续阅读中打开而不是文件列表",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "打开库时显示漫画完整路径",

languages/zh-hant.json

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@
180180
"folders": "",
181181
"files": "",
182182
"ignoreSingleFoldersLibrary": "",
183+
"whenOpenFolderFirstImageOrContinueReading": "",
183184
"whenOpenFolderContinueReading": "",
184185
"useTheFirstImageAsPoster": "",
185186
"showFullPathLibrary": "",

scripts/dom.js

+87-23
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ function addImageToDom(querySelector, path, animation = true)
127127

128128
if(animation)
129129
{
130-
src.addClass('a');
130+
src.addClass('a', 'border');
131131
cr.addClass('a');
132132
}
133133
else
134134
{
135+
src.addClass('border');
135136
src.filter('.folder-poster-img').addClass('has-poster');
136137
}
137138
}
@@ -264,22 +265,22 @@ async function loadFilesIndexPage(file, animation, path, keepScroll, mainPath)
264265
handlebarsContext.comicsReadingProgress = false;
265266
}
266267

267-
if(keepScroll > 1)
268+
/*if(keepScroll > 1)
268269
template.contentRight().children().html(template.load('index.content.right.'+config.view+'.html')).scrollTop(keepScroll);
269270
else
270-
template.contentRight().children().html(template.load('index.content.right.'+config.view+'.html'));
271+
template.contentRight().children().html(template.load('index.content.right.'+config.view+'.html'));*/
271272

272273
//template.loadContentRight('index.content.right.'+config.view+'.html', animation, keepScroll);
273274
events.events();
274275

275-
return {files: pathFiles, readingProgress: readingProgress[mainPath] || {}};
276+
return {files: pathFiles, readingProgress: readingProgress[mainPath] || {}, html: template.load('index.content.right.'+config.view+'.html')};
276277

277278
}).catch(function(error){
278279

279280
console.error(error);
280281
dom.compressedError(error);
281282

282-
return {files: [], readingProgress: {}};
283+
return {files: [], readingProgress: {}, html: ''};
283284

284285
});
285286

@@ -469,7 +470,7 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
469470
if(fromDeepLoad && Date.now() - fromDeepLoadNow < 300)
470471
{
471472
template._barHeader().firstElementChild.innerHTML = template.load('index.header.html');
472-
template._contentRight().firstElementChild.innerHTML = template.load('index.content.right.loading.html');
473+
// template._contentRight().firstElementChild.innerHTML = template.load('index.content.right.loading.html');
473474
}
474475
else
475476
{
@@ -492,23 +493,64 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
492493
cache.stopQueue();
493494
queue.stop('folderThumbnails');
494495

496+
// Get comic reading progress image
497+
let readingProgress = storage.get('readingProgress');
498+
readingProgress = readingProgress[mainPath] || {};
499+
500+
let containsCompressed = fileManager.containsCompressed(path);
501+
502+
let openContinueReading = false;
503+
let openFirstImage = ((!containsCompressed && config.whenOpenFolderFirstImageOrContinueReading) || (containsCompressed && config.whenOpenFileFirstImageOrContinueReading)) ? true : false;
504+
505+
if((config.whenOpenFolderContinueReading || config.whenOpenFileContinueReading || config.whenOpenFolderFirstImageOrContinueReading || config.whenOpenFileFirstImageOrContinueReading) && !fromGoBack && !disableIgnoreSingleFolders && readingProgress && readingProgress.lastReading > 0)
506+
{
507+
let isParentPath = fileManager.isParentPath(path, readingProgress.path);
508+
509+
if((!containsCompressed && (config.whenOpenFolderContinueReading || config.whenOpenFolderFirstImageOrContinueReading)) && isParentPath)
510+
openContinueReading = true;
511+
else if((containsCompressed && (config.whenOpenFileContinueReading || config.whenOpenFileFirstImageOrContinueReading)) && isParentPath)
512+
openContinueReading = true;
513+
}
514+
495515
let file = fileManager.file(path);
496-
let indexData = await loadFilesIndexPage(file, animation, path, keepScroll, mainPath);
497-
file.destroy();
498516

499-
if(config.whenOpenFolderContinueReading && !fromGoBack && !disableIgnoreSingleFolders && indexData.readingProgress && indexData.readingProgress.lastReading > 0)
517+
if(openContinueReading)
500518
{
501519
fromDeepLoadNow = Date.now();
502520
indexPathControlA.pop();
503521

504-
if(indexData.readingProgress.ebook)
505-
reading.setNextOpenChapterProgress(indexData.readingProgress.chapterIndex, indexData.readingProgress.chapterProgress);
522+
if(readingProgress.ebook)
523+
reading.setNextOpenChapterProgress(readingProgress.chapterIndex, readingProgress.chapterProgress);
506524

507-
dom.openComic(true, indexData.readingProgress.path, indexData.readingProgress.mainPath, false, false, false, true);
525+
console.log(readingProgress);
526+
527+
dom.openComic(true, readingProgress.path, mainPath, false, false, false, true);
528+
529+
file.destroy();
508530

509531
return;
510532
}
511-
else if(config.ignoreSingleFoldersLibrary && !fromGoBack && !disableIgnoreSingleFolders && indexData.files.length == 1 && (indexData.files[0].folder || indexData.files[0].compressed))
533+
else if(openFirstImage)
534+
{
535+
let first = await file.images(1);
536+
537+
if(first)
538+
{
539+
fromDeepLoadNow = Date.now();
540+
indexPathControlA.pop();
541+
542+
dom.openComic(true, first.path, mainPath, false, false, false, true);
543+
544+
file.destroy();
545+
546+
return;
547+
}
548+
}
549+
550+
let indexData = await loadFilesIndexPage(file, animation, path, keepScroll, mainPath);
551+
file.destroy();
552+
553+
if(config.ignoreSingleFoldersLibrary && !fromGoBack && !disableIgnoreSingleFolders && indexData.files.length == 1 && (indexData.files[0].folder || indexData.files[0].compressed))
512554
{
513555
fromDeepLoadNow = Date.now();
514556
indexPathControlA.pop();
@@ -518,6 +560,11 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
518560
return;
519561
}
520562

563+
let contentRightScroll = template.contentRight().children().html(indexData.html);
564+
565+
if(keepScroll > 1)
566+
contentRightScroll.scrollTop(keepScroll);
567+
521568
cache.resumeQueue();
522569
queue.resume('folderThumbnails');
523570
}
@@ -1375,14 +1422,13 @@ async function openComic(animation = true, path = true, mainPath = true, end = f
13751422

13761423
if(fromDeepLoad && Date.now() - fromDeepLoadNow < 300)
13771424
{
1378-
template._contentLeft().firstElementChild.innerHTML = template.load('reading.content.left.html');
1379-
template._contentRight().firstElementChild.innerHTML = template.load('reading.content.right.html');
13801425
template._barHeader().firstElementChild.innerHTML = template.load('reading.header.html');
13811426
}
13821427
else
13831428
{
1384-
template.loadContentLeft('reading.content.left.html', true);
1385-
template.loadContentRight('reading.content.right.html', true);
1429+
if(!template._contentRight().querySelector('.loading'))
1430+
template.loadContentRight('reading.content.right.html', true);
1431+
13861432
template.loadHeader('reading.header.html', true);
13871433
}
13881434

@@ -1408,7 +1454,7 @@ async function openComic(animation = true, path = true, mainPath = true, end = f
14081454
{
14091455
await file.makeAvailable([{path: compressedFile}]);
14101456
isEbook = true;
1411-
files = [];
1457+
// files = [];
14121458
}
14131459
else
14141460
{
@@ -1500,34 +1546,52 @@ async function openComic(animation = true, path = true, mainPath = true, end = f
15001546
indexStart = comics[i].index;
15011547
}
15021548

1549+
if(isEbook)
1550+
comics = [];
1551+
15031552
handlebarsContext.comics = comics;
15041553
handlebarsContext.previousComic = skipPreviousComic;
15051554
handlebarsContext.nextComic = skipNextComic;
15061555
reading.setCurrentComics(comics);
15071556

1557+
handlebarsContext.loading = true;
1558+
15081559
if(Date.now() - now < 300)
15091560
{
1510-
template._contentLeft().firstElementChild.innerHTML = template.load('reading.content.left.html');
1511-
template._contentRight().firstElementChild.innerHTML = template.load('reading.content.right.html');
1561+
if(template._contentRight().querySelector('.loading'))
1562+
{
1563+
handlebarsContext.loading = false;
1564+
template._contentRight().firstElementChild.insertAdjacentHTML('beforeend', template.load('reading.content.right.html'));
1565+
}
1566+
else
1567+
{
1568+
template._contentRight().firstElementChild.innerHTML = template.load('reading.content.right.html');
1569+
}
15121570
}
15131571
else
15141572
{
1515-
template.loadContentLeft('reading.content.left.html', true);
15161573
template.loadContentRight('reading.content.right.html', true);
15171574
}
15181575

1576+
template.loadContentLeft('reading.content.left.html', true);
1577+
15191578
if(template.globalElement('.reading-elements-menus').length == 0) template.loadGlobalElement('reading.elements.menus.html', 'menus');
15201579

15211580
floatingActionButton(false);
15221581

15231582
events.events();
15241583

1584+
reading.onLoad(function(){
1585+
1586+
cache.resumeQueue();
1587+
1588+
});
1589+
15251590
reading.read(path, indexStart, end, isCanvas, isEbook, imagePath);
15261591
reading.hideContent(electronRemote.getCurrentWindow().isFullScreen(), true);
15271592

15281593
generateAppMenu();
1529-
1530-
cache.resumeQueue();
1594+
15311595
shortcuts.register('reading');
15321596
gamepad.updateBrowsableItems('reading-'+sha1(path));
15331597
}

scripts/file-manager.js

+9
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,14 @@ function containsCompressed(path, index = 0)
21372137
return false;
21382138
}
21392139

2140+
function isParentPath(parentPath, fullPath)
2141+
{
2142+
if(new RegExp('^\s*'+pregQuote(parentPath)).test(fullPath))
2143+
return true;
2144+
2145+
return false;
2146+
}
2147+
21402148
function removePathPart(path, partToRemove)
21412149
{
21422150
path = path.replace(new RegExp('^\s*'+pregQuote(partToRemove)), '');
@@ -2271,6 +2279,7 @@ module.exports = {
22712279
firstCompressedFile: firstCompressedFile,
22722280
lastCompressedFile: lastCompressedFile,
22732281
containsCompressed: containsCompressed,
2282+
isParentPath: isParentPath,
22742283
dirSize: dirSize,
22752284
dirSizeSync: dirSizeSync,
22762285
}

0 commit comments

Comments
 (0)