Skip to content

Commit

Permalink
New: Option to open folder/file directly in first image or in continu…
Browse files Browse the repository at this point in the history
…e reading
  • Loading branch information
ollm committed Nov 22, 2023
1 parent a5cf998 commit 6a20160
Show file tree
Hide file tree
Showing 27 changed files with 216 additions and 42 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
##### 🚀 New Features

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

##### 🐛 Bug Fixes

Expand Down
1 change: 1 addition & 0 deletions languages/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "Navegació (Carpetes)",
"files": "Navegació (Fitxers)",
"ignoreSingleFoldersLibrary": "Ignorar carpetes individuals (S'obren automàticament)",
"whenOpenFolderFirstImageOrContinueReading": "Obrir directament a la primera imatge o en continuar llegint en lloc de la llista de fitxers",
"whenOpenFolderContinueReading": "Obrir directament en continuar llegint en lloc de la llista de fitxers",
"useTheFirstImageAsPoster": "Utilitzar la primera imatge com a pòster (Només si no n'hi ha cap actualment)",
"showFullPathLibrary": "Mostrar la ruta completa a l'obrir els còmics de la biblioteca",
Expand Down
1 change: 1 addition & 0 deletions languages/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "",
Expand Down
1 change: 1 addition & 0 deletions languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "",
Expand Down
1 change: 1 addition & 0 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "Navigation (Folders)",
"files": "Navigation (Files)",
"ignoreSingleFoldersLibrary": "Ignore single folders (Open automatically)",
"whenOpenFolderFirstImageOrContinueReading": "Open directly in first image or in continue reading instead of the file list",
"whenOpenFolderContinueReading": "Open directly in continue reading instead of the file list",
"useTheFirstImageAsPoster": "Use the first image as a poster (Only if there is none currently)",
"showFullPathLibrary": "Show full path when opening library comics",
Expand Down
1 change: 1 addition & 0 deletions languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "Navegación (Carpetas)",
"files": "Navegación (Archivos)",
"ignoreSingleFoldersLibrary": "Ignorar carpetas individuales (Se abren automáticamente)",
"whenOpenFolderFirstImageOrContinueReading": "Abrir directamente en la primera imagen o en continuar leyendo en lugar de la lista de archivos",
"whenOpenFolderContinueReading": "Abrir directamente en continuar leyendo en lugar de la lista de archivos",
"useTheFirstImageAsPoster": "Utilizar la primera imagen como póster (Solo si no hay ninguno actualmente)",
"showFullPathLibrary": "Mostrar la ruta completa al abrir los comics de la biblioteca",
Expand Down
1 change: 1 addition & 0 deletions languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "",
Expand Down
1 change: 1 addition & 0 deletions languages/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "",
Expand Down
1 change: 1 addition & 0 deletions languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "",
Expand Down
1 change: 1 addition & 0 deletions languages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "",
Expand Down
1 change: 1 addition & 0 deletions languages/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "",
Expand Down
1 change: 1 addition & 0 deletions languages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "",
Expand Down
1 change: 1 addition & 0 deletions languages/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "ละเว้นโฟลเดอร์เดี่ยว (เปิดอัตโนมัติ)",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "เปิดไปอ่านต่อโดยตรงแทนที่จะเป็นรายการไฟล์",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "แสดงที่ตั้งแบบเต็มเมื่อเปิดห้องสมุดคอมมิกส์",
Expand Down
1 change: 1 addition & 0 deletions languages/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "",
Expand Down
1 change: 1 addition & 0 deletions languages/zh-hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "忽略单个文件夹(自动打开)",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "直接在继续阅读中打开而不是文件列表",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "打开库时显示漫画完整路径",
Expand Down
1 change: 1 addition & 0 deletions languages/zh-hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
"folders": "",
"files": "",
"ignoreSingleFoldersLibrary": "",
"whenOpenFolderFirstImageOrContinueReading": "",
"whenOpenFolderContinueReading": "",
"useTheFirstImageAsPoster": "",
"showFullPathLibrary": "",
Expand Down
110 changes: 87 additions & 23 deletions scripts/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ function addImageToDom(querySelector, path, animation = true)

if(animation)
{
src.addClass('a');
src.addClass('a', 'border');
cr.addClass('a');
}
else
{
src.addClass('border');
src.filter('.folder-poster-img').addClass('has-poster');
}
}
Expand Down Expand Up @@ -264,22 +265,22 @@ async function loadFilesIndexPage(file, animation, path, keepScroll, mainPath)
handlebarsContext.comicsReadingProgress = false;
}

if(keepScroll > 1)
/*if(keepScroll > 1)
template.contentRight().children().html(template.load('index.content.right.'+config.view+'.html')).scrollTop(keepScroll);
else
template.contentRight().children().html(template.load('index.content.right.'+config.view+'.html'));
template.contentRight().children().html(template.load('index.content.right.'+config.view+'.html'));*/

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

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

}).catch(function(error){

console.error(error);
dom.compressedError(error);

return {files: [], readingProgress: {}};
return {files: [], readingProgress: {}, html: ''};

});

Expand Down Expand Up @@ -469,7 +470,7 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
if(fromDeepLoad && Date.now() - fromDeepLoadNow < 300)
{
template._barHeader().firstElementChild.innerHTML = template.load('index.header.html');
template._contentRight().firstElementChild.innerHTML = template.load('index.content.right.loading.html');
// template._contentRight().firstElementChild.innerHTML = template.load('index.content.right.loading.html');
}
else
{
Expand All @@ -492,23 +493,64 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
cache.stopQueue();
queue.stop('folderThumbnails');

// Get comic reading progress image
let readingProgress = storage.get('readingProgress');
readingProgress = readingProgress[mainPath] || {};

let containsCompressed = fileManager.containsCompressed(path);

let openContinueReading = false;
let openFirstImage = ((!containsCompressed && config.whenOpenFolderFirstImageOrContinueReading) || (containsCompressed && config.whenOpenFileFirstImageOrContinueReading)) ? true : false;

if((config.whenOpenFolderContinueReading || config.whenOpenFileContinueReading || config.whenOpenFolderFirstImageOrContinueReading || config.whenOpenFileFirstImageOrContinueReading) && !fromGoBack && !disableIgnoreSingleFolders && readingProgress && readingProgress.lastReading > 0)
{
let isParentPath = fileManager.isParentPath(path, readingProgress.path);

if((!containsCompressed && (config.whenOpenFolderContinueReading || config.whenOpenFolderFirstImageOrContinueReading)) && isParentPath)
openContinueReading = true;
else if((containsCompressed && (config.whenOpenFileContinueReading || config.whenOpenFileFirstImageOrContinueReading)) && isParentPath)
openContinueReading = true;
}

let file = fileManager.file(path);
let indexData = await loadFilesIndexPage(file, animation, path, keepScroll, mainPath);
file.destroy();

if(config.whenOpenFolderContinueReading && !fromGoBack && !disableIgnoreSingleFolders && indexData.readingProgress && indexData.readingProgress.lastReading > 0)
if(openContinueReading)
{
fromDeepLoadNow = Date.now();
indexPathControlA.pop();

if(indexData.readingProgress.ebook)
reading.setNextOpenChapterProgress(indexData.readingProgress.chapterIndex, indexData.readingProgress.chapterProgress);
if(readingProgress.ebook)
reading.setNextOpenChapterProgress(readingProgress.chapterIndex, readingProgress.chapterProgress);

dom.openComic(true, indexData.readingProgress.path, indexData.readingProgress.mainPath, false, false, false, true);
console.log(readingProgress);

dom.openComic(true, readingProgress.path, mainPath, false, false, false, true);

file.destroy();

return;
}
else if(config.ignoreSingleFoldersLibrary && !fromGoBack && !disableIgnoreSingleFolders && indexData.files.length == 1 && (indexData.files[0].folder || indexData.files[0].compressed))
else if(openFirstImage)
{
let first = await file.images(1);

if(first)
{
fromDeepLoadNow = Date.now();
indexPathControlA.pop();

dom.openComic(true, first.path, mainPath, false, false, false, true);

file.destroy();

return;
}
}

let indexData = await loadFilesIndexPage(file, animation, path, keepScroll, mainPath);
file.destroy();

if(config.ignoreSingleFoldersLibrary && !fromGoBack && !disableIgnoreSingleFolders && indexData.files.length == 1 && (indexData.files[0].folder || indexData.files[0].compressed))
{
fromDeepLoadNow = Date.now();
indexPathControlA.pop();
Expand All @@ -518,6 +560,11 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
return;
}

let contentRightScroll = template.contentRight().children().html(indexData.html);

if(keepScroll > 1)
contentRightScroll.scrollTop(keepScroll);

cache.resumeQueue();
queue.resume('folderThumbnails');
}
Expand Down Expand Up @@ -1375,14 +1422,13 @@ async function openComic(animation = true, path = true, mainPath = true, end = f

if(fromDeepLoad && Date.now() - fromDeepLoadNow < 300)
{
template._contentLeft().firstElementChild.innerHTML = template.load('reading.content.left.html');
template._contentRight().firstElementChild.innerHTML = template.load('reading.content.right.html');
template._barHeader().firstElementChild.innerHTML = template.load('reading.header.html');
}
else
{
template.loadContentLeft('reading.content.left.html', true);
template.loadContentRight('reading.content.right.html', true);
if(!template._contentRight().querySelector('.loading'))
template.loadContentRight('reading.content.right.html', true);

template.loadHeader('reading.header.html', true);
}

Expand All @@ -1408,7 +1454,7 @@ async function openComic(animation = true, path = true, mainPath = true, end = f
{
await file.makeAvailable([{path: compressedFile}]);
isEbook = true;
files = [];
// files = [];
}
else
{
Expand Down Expand Up @@ -1500,34 +1546,52 @@ async function openComic(animation = true, path = true, mainPath = true, end = f
indexStart = comics[i].index;
}

if(isEbook)
comics = [];

handlebarsContext.comics = comics;
handlebarsContext.previousComic = skipPreviousComic;
handlebarsContext.nextComic = skipNextComic;
reading.setCurrentComics(comics);

handlebarsContext.loading = true;

if(Date.now() - now < 300)
{
template._contentLeft().firstElementChild.innerHTML = template.load('reading.content.left.html');
template._contentRight().firstElementChild.innerHTML = template.load('reading.content.right.html');
if(template._contentRight().querySelector('.loading'))
{
handlebarsContext.loading = false;
template._contentRight().firstElementChild.insertAdjacentHTML('beforeend', template.load('reading.content.right.html'));
}
else
{
template._contentRight().firstElementChild.innerHTML = template.load('reading.content.right.html');
}
}
else
{
template.loadContentLeft('reading.content.left.html', true);
template.loadContentRight('reading.content.right.html', true);
}

template.loadContentLeft('reading.content.left.html', true);

if(template.globalElement('.reading-elements-menus').length == 0) template.loadGlobalElement('reading.elements.menus.html', 'menus');

floatingActionButton(false);

events.events();

reading.onLoad(function(){

cache.resumeQueue();

});

reading.read(path, indexStart, end, isCanvas, isEbook, imagePath);
reading.hideContent(electronRemote.getCurrentWindow().isFullScreen(), true);

generateAppMenu();

cache.resumeQueue();

shortcuts.register('reading');
gamepad.updateBrowsableItems('reading-'+sha1(path));
}
Expand Down
9 changes: 9 additions & 0 deletions scripts/file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2137,6 +2137,14 @@ function containsCompressed(path, index = 0)
return false;
}

function isParentPath(parentPath, fullPath)
{
if(new RegExp('^\s*'+pregQuote(parentPath)).test(fullPath))
return true;

return false;
}

function removePathPart(path, partToRemove)
{
path = path.replace(new RegExp('^\s*'+pregQuote(partToRemove)), '');
Expand Down Expand Up @@ -2271,6 +2279,7 @@ module.exports = {
firstCompressedFile: firstCompressedFile,
lastCompressedFile: lastCompressedFile,
containsCompressed: containsCompressed,
isParentPath: isParentPath,
dirSize: dirSize,
dirSizeSync: dirSizeSync,
}

0 comments on commit 6a20160

Please sign in to comment.