Skip to content

Commit 86f094b

Browse files
committed
New: Save and show also the current folder progress apart from the main folder
1 parent 84c838a commit 86f094b

File tree

6 files changed

+141
-74
lines changed

6 files changed

+141
-74
lines changed

CHANGELOG.md

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

1111
- Delete bookmarks from the bookmark list [`3792f7d`](https://github.com/ollm/OpenComic/commit/3792f7db319cf885f398836aefe983e56fe5ef2a)
12+
- Save and show also the current folder progress apart from the main folder
1213

1314
##### 🐛 Bug Fixes
1415

@@ -18,7 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1819
- Some errors on go back before comic load [`99fb29d`](https://github.com/ollm/OpenComic/commit/99fb29dab7b07a94883199665167a1301774f4e8)
1920
- Blank page keep white color in dark theme [`8d1a5b7`](https://github.com/ollm/OpenComic/commit/8d1a5b741855fd0bae6a7efd9579c7ddecbfd3d1)
2021
- Open with OpenComic not working in macOS and some fixes in Windows and Linux [`ea90063`](https://github.com/ollm/OpenComic/commit/ea9006309eee995c92571e0bc4c919d50de8e55b)
21-
- Error opening an epub when OpenComic is closed
22+
- Error opening an epub when OpenComic is closed [`84c838a`](https://github.com/ollm/OpenComic/commit/84c838a17a32b3f50e9b25bf016ea810c91d95e6)
2223

2324
## [v1.0.0-beta.5](https://github.com/ollm/OpenComic/releases/tag/v1.0.0-beta.5) (24-11-2023)
2425

scripts/dom.js

+83-39
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ async function loadFilesIndexPage(file, animation, path, keepScroll, mainPath)
154154
let thumbnails = [];
155155

156156
// Get comic reading progress image
157-
let readingProgress = storage.get('readingProgress');
157+
let _readingProgress = storage.get('readingProgress');
158+
159+
let readingProgress = _readingProgress[mainPath] || false;
160+
let readingProgressCurrentPath = (mainPath != path) ? (_readingProgress[path] || false) : false;
158161

159162
if(files)
160163
{
@@ -170,14 +173,24 @@ async function loadFilesIndexPage(file, animation, path, keepScroll, mainPath)
170173
}
171174
}
172175

173-
if(readingProgress[mainPath] && readingProgress[mainPath].lastReading > 0)
176+
if(readingProgress)
177+
{
178+
let path = readingProgress.path;
179+
let sha = sha1(path);
180+
181+
images.push({path: path, sha: sha});
182+
183+
readingProgress.sha = sha;
184+
}
185+
186+
if(readingProgressCurrentPath)
174187
{
175-
let path = readingProgress[mainPath].path;
188+
let path = readingProgressCurrentPath.path;
176189
let sha = sha1(path);
177190

178191
images.push({path: path, sha: sha});
179192

180-
readingProgress[mainPath].sha = sha;
193+
readingProgressCurrentPath.sha = sha;
181194
}
182195

183196
thumbnails = cache.returnThumbnailsImages(images, function(data){
@@ -228,59 +241,81 @@ async function loadFilesIndexPage(file, animation, path, keepScroll, mainPath)
228241
}
229242
else
230243
{
231-
if(readingProgress[mainPath] && readingProgress[mainPath].lastReading > 0)
244+
let images = [];
245+
246+
if(readingProgress)
232247
{
233-
let path = readingProgress[mainPath].path;
248+
let path = readingProgress.path;
234249
let sha = sha1(path);
235250

236-
let thumbnail = cache.returnThumbnailsImages({path: path, sha: sha}, function(data){
251+
images.push({path: path, sha: sha});
237252

238-
addImageToDom(data.sha, data.path);
253+
readingProgress.sha = sha;
254+
}
239255

240-
}, file);
256+
if(readingProgressCurrentPath)
257+
{
258+
let path = readingProgressCurrentPath.path;
259+
let sha = sha1(path);
241260

242-
readingProgress[mainPath].sha = sha;
243-
thumbnails[sha] = thumbnail;
261+
images.push({path: path, sha: sha});
262+
263+
readingProgressCurrentPath.sha = sha;
244264
}
265+
266+
thumbnails = cache.returnThumbnailsImages(images, function(data){
267+
268+
addImageToDom(data.sha, data.path);
269+
270+
}, file);
245271
}
246272

247273
handlebarsContext.comics = pathFiles;
248274

249275
// Comic reading progress
250-
if(readingProgress[mainPath] && readingProgress[mainPath].lastReading > 0)
276+
if(readingProgress)
251277
{
252-
let path = readingProgress[mainPath].path;
253-
let sha = readingProgress[mainPath].sha;
254-
278+
let sha = readingProgress.sha;
255279
let thumbnail = thumbnails[sha];
256280

257-
readingProgress[mainPath].sha = sha;
258-
readingProgress[mainPath].thumbnail = (thumbnail.cache) ? thumbnail.path : '';
259-
readingProgress[mainPath].mainPath = mainPath;
260-
readingProgress[mainPath].pathText = returnTextPath(readingProgress[mainPath].path, mainPath, true);
261-
handlebarsContext.comicsReadingProgress = readingProgress[mainPath];
281+
readingProgress.sha = sha;
282+
readingProgress.thumbnail = (thumbnail.cache) ? thumbnail.path : '';
283+
readingProgress.mainPath = mainPath;
284+
readingProgress.pathText = returnTextPath(readingProgress.path, mainPath, true, !readingProgress.ebook);
285+
handlebarsContext.comicsReadingProgress = readingProgress;
262286
}
263287
else
264288
{
265289
handlebarsContext.comicsReadingProgress = false;
266290
}
267291

268-
/*if(keepScroll > 1)
269-
template.contentRight().children().html(template.load('index.content.right.'+config.view+'.html')).scrollTop(keepScroll);
292+
// Current folder reading progress
293+
if(readingProgressCurrentPath)
294+
{
295+
let sha = readingProgressCurrentPath.sha;
296+
let thumbnail = thumbnails[sha];
297+
298+
readingProgressCurrentPath.sha = sha;
299+
readingProgressCurrentPath.thumbnail = (thumbnail.cache) ? thumbnail.path : '';
300+
readingProgressCurrentPath.mainPath = mainPath;
301+
readingProgressCurrentPath.pathText = returnTextPath(readingProgressCurrentPath.path, path, true, !readingProgressCurrentPath.ebook);
302+
handlebarsContext.comicsReadingProgressCurrentPath = readingProgressCurrentPath;
303+
}
270304
else
271-
template.contentRight().children().html(template.load('index.content.right.'+config.view+'.html'));*/
305+
{
306+
handlebarsContext.comicsReadingProgressCurrentPath = false;
307+
}
272308

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

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

278313
}).catch(function(error){
279314

280315
console.error(error);
281316
dom.compressedError(error);
282317

283-
return {files: [], readingProgress: {}, html: ''};
318+
return {files: [], readingProgress: {}, readingProgressCurrentPath: {}, html: ''};
284319

285320
});
286321

@@ -495,22 +530,29 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
495530
queue.stop('folderThumbnails');
496531

497532
// Get comic reading progress image
498-
let readingProgress = storage.get('readingProgress');
499-
readingProgress = readingProgress[mainPath] || {};
533+
let _readingProgress = storage.get('readingProgress');
534+
let readingProgress = _readingProgress[mainPath] || false;
535+
let readingProgressCurrentPath = (mainPath != path) ? (_readingProgress[path] || false) : false;
500536

501537
let isCompressed = fileManager.isCompressed(path);
502538

503539
let openContinueReading = false;
504540
let openFirstImage = ((!isCompressed && config.whenOpenFolderFirstImageOrContinueReading) || (isCompressed && config.whenOpenFileFirstImageOrContinueReading)) ? true : false;
505541

506-
if((config.whenOpenFolderContinueReading || config.whenOpenFileContinueReading || config.whenOpenFolderFirstImageOrContinueReading || config.whenOpenFileFirstImageOrContinueReading) && !fromGoBack && !notAutomaticBrowsing && readingProgress && readingProgress.lastReading > 0)
542+
if((config.whenOpenFolderContinueReading || config.whenOpenFileContinueReading || config.whenOpenFolderFirstImageOrContinueReading || config.whenOpenFileFirstImageOrContinueReading) && !fromGoBack && !notAutomaticBrowsing && readingProgress)
507543
{
508544
let isParentPath = fileManager.isParentPath(path, readingProgress.path);
509545

510-
if((!isCompressed && (config.whenOpenFolderContinueReading || config.whenOpenFolderFirstImageOrContinueReading)) && isParentPath)
511-
openContinueReading = true;
512-
else if((isCompressed && (config.whenOpenFileContinueReading || config.whenOpenFileFirstImageOrContinueReading)) && isParentPath)
513-
openContinueReading = true;
546+
if(isParentPath || readingProgressCurrentPath)
547+
{
548+
if(!isParentPath && readingProgressCurrentPath)
549+
readingProgress = readingProgressCurrentPath;
550+
551+
if((!isCompressed && (config.whenOpenFolderContinueReading || config.whenOpenFolderFirstImageOrContinueReading)))
552+
openContinueReading = true;
553+
else if((isCompressed && (config.whenOpenFileContinueReading || config.whenOpenFileFirstImageOrContinueReading)))
554+
openContinueReading = true;
555+
}
514556
}
515557

516558
let file = fileManager.file(path);
@@ -600,17 +642,19 @@ function addSepToEnd(path)
600642
return path;
601643
}
602644

603-
function returnTextPath(path, mainPath, image = false)
645+
function returnTextPath(path, mainPath, image = false, extension = true)
604646
{
605647
mainPathR = addSepToEnd(p.dirname(mainPath));
606648

607-
var files = path.replace(new RegExp('^\s*'+pregQuote(mainPathR)), '').split(p.sep);
649+
let files = path.replace(new RegExp('^\s*'+pregQuote(mainPathR)), '').split(p.sep);
650+
path = [];
608651

609-
var path = [];
610-
611-
for(let index in files)
652+
for(let i = 0, len = files.length; i < len; i++)
612653
{
613-
path.push(translatePageName(image ? htmlEntities(files[index]) : files[index]));
654+
if(!extension && i == len - 1)
655+
files[i] = p.parse(files[i]).name;
656+
657+
path.push(translatePageName(image ? htmlEntities(files[i]) : files[i]));
614658
}
615659

616660
return path.join(image ? '<i class="material-icon navegation">chevron_right</i>' : ' / ');

scripts/reading.js

+8-22
Original file line numberDiff line numberDiff line change
@@ -2926,16 +2926,14 @@ function setFromSkip()
29262926
}
29272927

29282928
//Save current reading progress
2929-
function saveReadingProgress(path = false)
2929+
function saveReadingProgress(path = false, mainPath = false)
29302930
{
29312931
if(!onReading)
29322932
return;
29332933

29342934
if(!saveReadingProgressA)
29352935
return;
29362936

2937-
let mainPath = dom.indexMainPathA();
2938-
29392937
if(!path)
29402938
{
29412939
let imageIndex = false;
@@ -2958,17 +2956,14 @@ function saveReadingProgress(path = false)
29582956
path = p.normalize(images[imageIndex].path);
29592957
}
29602958

2961-
/*let comic = false, comicIndex = 0, comics = storage.get('comics');
2962-
2963-
for(let i in comics)
2959+
if(mainPath === false)
29642960
{
2965-
if(comics[i].path == mainPath)
2966-
{
2967-
comic = comics[i];
2968-
comicIndex = i;
2969-
break;
2970-
}
2971-
}*/
2961+
mainPath = dom.indexMainPathA();
2962+
2963+
// Save also the current folder progress
2964+
if(mainPath !== p.dirname(path))
2965+
saveReadingProgress(path, p.dirname(path));
2966+
}
29722967

29732968
let progress = 0;
29742969
let chapterIndex = 0;
@@ -2996,15 +2991,6 @@ function saveReadingProgress(path = false)
29962991

29972992
dom.indexPathControlUpdateLastComic(path);
29982993

2999-
/*if(comic && path)
3000-
{
3001-
comic.readingProgress.path = path.replace(/\?page=[0-9]+$/, '');
3002-
comic.readingProgress.lastReading = +new Date();
3003-
comic.readingProgress.progress = 0;
3004-
3005-
storage.updateVar('comics', comicIndex, comic);
3006-
}*/
3007-
30082994
return true;
30092995
}
30102996

templates/index.content.right.list.html

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
{{#if comicsReadingProgress}}
2-
<div class="continue-reading gamepad-item body-medium" onclick="{{#if comicsReadingProgress.ebook}}reading.setNextOpenChapterProgress({{comicsReadingProgress.chapterIndex}}, {{comicsReadingProgress.chapterProgress}});{{/if}}dom.openComic(true, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.path}}', '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.mainPath}}');">
3-
<div>
4-
<div class="continue-reading-sha-{{comicsReadingProgress.sha}}" style="background-image: url({{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.thumbnail}});"></div>
5-
<span>{{language.comics.continueReading}}:&nbsp&nbsp&nbsp{{{comicsReadingProgress.pathText}}}</span>
1+
<div class="continue-reading-list{{#if comicsReadingProgress}}{{#if comicsReadingProgressCurrentPath}} continue-reading-list-double{{/if}}{{/if}}">
2+
{{#if comicsReadingProgress}}
3+
<div class="continue-reading gamepad-item body-medium" onclick="{{#if comicsReadingProgress.ebook}}reading.setNextOpenChapterProgress({{comicsReadingProgress.chapterIndex}}, {{comicsReadingProgress.chapterProgress}});{{/if}}dom.openComic(true, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.path}}', '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.mainPath}}');">
4+
<div>
5+
<div class="continue-reading-sha-{{comicsReadingProgress.sha}}" style="background-image: url({{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.thumbnail}});"></div>
6+
<span>{{language.comics.continueReading}}:&nbsp&nbsp&nbsp{{{comicsReadingProgress.pathText}}}</span>
7+
</div>
68
</div>
9+
{{/if}}
10+
{{#if comicsReadingProgressCurrentPath}}
11+
<div class="continue-reading gamepad-item body-medium" onclick="{{#if comicsReadingProgressCurrentPath.ebook}}reading.setNextOpenChapterProgress({{comicsReadingProgressCurrentPath.chapterIndex}}, {{comicsReadingProgressCurrentPath.chapterProgress}});{{/if}}dom.openComic(true, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgressCurrentPath.path}}', '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgressCurrentPath.mainPath}}');">
12+
<div>
13+
<div class="continue-reading-sha-{{comicsReadingProgressCurrentPath.sha}}" style="background-image: url({{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgressCurrentPath.thumbnail}});"></div>
14+
<span>{{language.comics.continueReading}}:&nbsp&nbsp&nbsp{{{comicsReadingProgressCurrentPath.pathText}}}</span>
15+
</div>
16+
</div>
17+
{{/if}}
718
</div>
8-
{{/if}}
919
<div class="content-view-list">
1020
{{#each comics}}
1121
<div class="medium-list body-medium{{#unless folder}} sha-{{sha}}{{/unless}} gamepad-item{{#if @first}} gamepad-to-highlight{{/if}}" onclick="{{#if folder}}dom.loadIndexPage(true, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}', false, false, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' mainPath}}');{{else}}dom.openComic(true, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}', '{{chain 'escapeBackSlash' 'escapeQuotesSimples' mainPath}}');{{/if}}{{onclick}}" oncontextmenu="dom.comicContextMenu('{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}', {{#if @root.comicsIndex}}{{#unless fromMasterFolder}}true{{else}}false{{/unless}}{{else}}false{{/if}}, {{#if folder}}true{{else}}false{{/if}}, fromGamepad)">

templates/index.content.right.module.html

+16-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1-
{{#if comicsReadingProgress}}
2-
<div class="continue-reading gamepad-item body-medium" onclick="{{#if comicsReadingProgress.ebook}}reading.setNextOpenChapterProgress({{comicsReadingProgress.chapterIndex}}, {{comicsReadingProgress.chapterProgress}});{{/if}}dom.openComic(true, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.path}}', '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.mainPath}}');">
3-
<div>
4-
<div class="continue-reading-sha-{{comicsReadingProgress.sha}}" style="background-image: url({{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.thumbnail}});"></div>
5-
<span>{{language.comics.continueReading}}:&nbsp&nbsp&nbsp{{{comicsReadingProgress.pathText}}}</span>
1+
<div class="continue-reading-list{{#if comicsReadingProgress}}{{#if comicsReadingProgressCurrentPath}} continue-reading-list-double{{/if}}{{/if}}">
2+
{{#if comicsReadingProgress}}
3+
<div class="continue-reading gamepad-item body-medium" onclick="{{#if comicsReadingProgress.ebook}}reading.setNextOpenChapterProgress({{comicsReadingProgress.chapterIndex}}, {{comicsReadingProgress.chapterProgress}});{{/if}}dom.openComic(true, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.path}}', '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.mainPath}}');">
4+
<div>
5+
<div class="continue-reading-sha-{{comicsReadingProgress.sha}}" style="background-image: url({{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgress.thumbnail}});"></div>
6+
<span>{{language.comics.continueReading}}:&nbsp&nbsp&nbsp{{{comicsReadingProgress.pathText}}}</span>
7+
</div>
8+
</div>
9+
{{/if}}
10+
{{#if comicsReadingProgressCurrentPath}}
11+
<div class="continue-reading gamepad-item body-medium" onclick="{{#if comicsReadingProgressCurrentPath.ebook}}reading.setNextOpenChapterProgress({{comicsReadingProgressCurrentPath.chapterIndex}}, {{comicsReadingProgressCurrentPath.chapterProgress}});{{/if}}dom.openComic(true, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgressCurrentPath.path}}', '{{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgressCurrentPath.mainPath}}');">
12+
<div>
13+
<div class="continue-reading-sha-{{comicsReadingProgressCurrentPath.sha}}" style="background-image: url({{chain 'escapeBackSlash' 'escapeQuotesSimples' comicsReadingProgressCurrentPath.thumbnail}});"></div>
14+
<span>{{language.comics.continueReading}}:&nbsp&nbsp&nbsp{{{comicsReadingProgressCurrentPath.pathText}}}</span>
15+
</div>
616
</div>
17+
{{/if}}
718
</div>
8-
{{/if}}
919
<div class="content-view-module">
1020
{{#each comics}}
1121
<div class="sha-{{sha}} gamepad-item{{#if @first}} gamepad-to-highlight{{/if}}" onclick="{{#if folder}}dom.loadIndexPage(true, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}', false, false, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' mainPath}}');{{else}}dom.openComic(true, '{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}', '{{chain 'escapeBackSlash' 'escapeQuotesSimples' mainPath}}');{{/if}}{{onclick}}" oncontextmenu="dom.comicContextMenu('{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}', {{#if @root.comicsIndex}}{{#unless fromMasterFolder}}true{{else}}false{{/unless}}{{else}}false{{/if}}, {{#if folder}}true{{else}}false{{/if}}, fromGamepad)">

themes/material-design/theme.css

+16
Original file line numberDiff line numberDiff line change
@@ -1581,6 +1581,22 @@ cb
15811581
transition: transform 0.2s;
15821582
}
15831583

1584+
.continue-reading-list-double
1585+
{
1586+
display: flex;
1587+
flex-wrap: wrap;
1588+
}
1589+
1590+
.continue-reading-list-double .continue-reading:nth-of-type(2n + 1)
1591+
{
1592+
margin-right: 0px;
1593+
}
1594+
1595+
.continue-reading-list-double .continue-reading
1596+
{
1597+
width: calc(50% - 18px);
1598+
}
1599+
15841600
.continue-reading.gamepad-highlight
15851601
{
15861602
transform: scale(1.005);

0 commit comments

Comments
 (0)