Skip to content

Commit 02b67c6

Browse files
committed
New: Optimized sidebar thumbnails
1 parent ba8641f commit 02b67c6

9 files changed

Lines changed: 256 additions & 26 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1111
- Allow disabling `Do not enlarge more than its original size` in Webtoon mode [`7519ac5`](https://github.com/ollm/OpenComic/commit/7519ac5cd0ac4407a4d0edec7e7a3e2a76832f84)
1212
- Improved rotation and support for rotating in PDF [`cb90771`](https://github.com/ollm/OpenComic/commit/cb907714ca7d713bcbf3471564e48a3e67c8ca40)
1313
- PDFs are rendered to a blob image instead of a canvas [`554c1ef`](https://github.com/ollm/OpenComic/commit/554c1ef88adf358acae14f9bf28f0e1f4f626d8f)
14+
- Optimized sidebar thumbnails
1415

1516
##### 🐛 Bug Fixes
1617

@@ -20,7 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2021
- Correct support Komga OPDS server [`0ae69bf`](https://github.com/ollm/OpenComic/commit/0ae69bf29612ef667cf944bf07ab8e7e488fd60c)
2122
- Some mime types are not correct detected [`baa8397`](https://github.com/ollm/OpenComic/commit/baa8397da5f33b5129607bbcc368c4eb782bc4e9)
2223
- Update electron to fix white lines in Webtoon mode [`2b98eb3`](https://github.com/ollm/OpenComic/commit/2b98eb3af7c1651149063e6176a5ae7e6b3d1c81)
23-
- Navigation back not working with shortcuts and gamepad
24+
- Navigation back not working with shortcuts and gamepad [`ba8641f`](https://github.com/ollm/OpenComic/commit/ba8641f96ed3c8bdef8e35ce98af55b7e6d10bc8)
2425

2526
## [v1.5.0](https://github.com/ollm/OpenComic/releases/tag/v1.5.0) (19-06-2025)
2627

‎scripts/cache.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ function returnThumbnailsImages(images, callback, file = false)
227227

228228
if(toGenerateThumbnails.length > 0 && file)
229229
{
230-
threads.job('cacheMakeAvailable', {useThreads: 0.01, delay: 50}, function() {
230+
threads.job('cacheMakeAvailable', {useThreads: 0.01, delay: 50}, async function() {
231231

232-
file.makeAvailable(toGenerateThumbnails, function(image) {
232+
await file.makeAvailable(toGenerateThumbnails, function(image) {
233233

234234
const data = toGenerateThumbnailsData[image.path];
235235
const size = data.type ? sizes[data.type][data.forceSize] : sizes.image[data.forceSize];
@@ -238,6 +238,8 @@ function returnThumbnailsImages(images, callback, file = false)
238238

239239
}, false, true);
240240

241+
file.afterDestroy();
242+
241243
});
242244
}
243245

‎scripts/dom.js‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,12 +2654,6 @@ async function openComic(animation = true, path = true, mainPath = true, end = f
26542654
images.push(file);
26552655
}
26562656

2657-
let thumbnails = cache.returnThumbnailsImages(images, function(data) {
2658-
2659-
addImageToDom(data.sha, data.path);
2660-
2661-
}, file);
2662-
26632657
for(let i = 0; i < len; i++)
26642658
{
26652659
let file = files[i];
@@ -2684,15 +2678,12 @@ async function openComic(animation = true, path = true, mainPath = true, end = f
26842678
}
26852679
else
26862680
{
2687-
let thumbnail = thumbnails[file.sha] || {};
2688-
26892681
comics.push({
26902682
sha: file.sha,
26912683
name: file.name.replace(/\.[^\.]*$/, ''),
26922684
image: fileManager.realPath(file.path),
26932685
path: file.path,
26942686
mainPath: mainPath,
2695-
thumbnail: (thumbnail.cache) ? thumbnail.path : '',
26962687
size: file.size || false,
26972688
canvas: isCanvas,
26982689
ebook: isEbook,

‎scripts/file-manager.js‎

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var file = function(path, _config = false) {
1818
filtered: true,
1919
sha: true,
2020
only: false,
21+
log: true,
2122
};
2223

2324
if(_config) this.config = {...this.config, ..._config};
@@ -180,7 +181,7 @@ var file = function(path, _config = false) {
180181
this.compressedOpened[path] = {
181182
lastUsage: now,
182183
mtimeMainCompressed: mtime,
183-
compressed: fileManager.fileCompressed(path, _realPath, this.config.forceType, this.config.prefixes),
184+
compressed: fileManager.fileCompressed(path, _realPath, this.config.forceType, this.config.prefixes, {log: this.config.log}),
184185
};
185186
}
186187
else
@@ -895,8 +896,12 @@ var file = function(path, _config = false) {
895896
}
896897
}
897898

899+
this.destroyed = false;
900+
898901
this.destroy = function() {
899902

903+
this.destroyed = true;
904+
900905
for(let path in this.compressedOpened)
901906
{
902907
this.compressedOpened[path].compressed.destroy();
@@ -912,10 +917,17 @@ var file = function(path, _config = false) {
912917
this.macosScopedResources = [];
913918

914919
};
920+
921+
this.afterDestroy = function() {
922+
923+
if(this.destroyed)
924+
this.destroy();
925+
926+
}
915927
}
916928

917929
// Compressed files
918-
var fileCompressed = function(path, _realPath = false, forceType = false, prefixes = false) {
930+
var fileCompressed = function(path, _realPath = false, forceType = false, prefixes = false, _config = false) {
919931

920932
this.path = path;
921933
this.realPath = _realPath || realPath(path, -1);
@@ -962,8 +974,11 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
962974
width: window.devicePixelRatio * 300, // Vector width
963975
height: false, // Vector height
964976
force: false, // Forces the extraction even if the file exists
977+
log: true,
965978
};
966979

980+
if(_config) this.config = this._config = {...this.config, ..._config};
981+
967982
this._features = {
968983
'7z': { // 7z incldues multiple formats, like zip, rar, tar, etc.
969984
read: true,
@@ -996,6 +1011,27 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
9961011

9971012
this.features = false;
9981013

1014+
this.log = function(message) {
1015+
1016+
if(this.config.log)
1017+
console.log(message);
1018+
1019+
}
1020+
1021+
this.time = function(key, message) {
1022+
1023+
if(this.config.log)
1024+
console.time(key, message);
1025+
1026+
}
1027+
1028+
this.timeEnd = function(key, message) {
1029+
1030+
if(this.config.log)
1031+
console.timeEnd(key, message);
1032+
1033+
}
1034+
9991035
this.updateConfigOnly = function(_only) {
10001036

10011037
if(!_only)
@@ -1091,7 +1127,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
10911127
this.setTmpUsage();
10921128

10931129
const message = 'readCompressed | '+this.features.ext+(this.features.fileExt && this.features.ext !== this.features.fileExt ? ' ('+this.features.fileExt+')' : '')+' | '+this.path;
1094-
console.time(message);
1130+
this.time(message);
10951131

10961132
let files = false;
10971133

@@ -1102,7 +1138,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
11021138
else if(this.features.epub)
11031139
files = await this.readEpub();
11041140

1105-
console.timeEnd(message);
1141+
this.timeEnd(message);
11061142

11071143
return files;
11081144
}
@@ -1347,7 +1383,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
13471383

13481384
await threads.job('extractCurrent--'+this.sha, {useThreads: 0.01}, async function() {
13491385

1350-
console.time(message);
1386+
self.time(message);
13511387

13521388
if(self.features['7z'])
13531389
files = await self.extract7z();
@@ -1360,7 +1396,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
13601396

13611397
});
13621398

1363-
console.timeEnd(message);
1399+
this.timeEnd(message);
13641400

13651401
return files;
13661402
}
@@ -2209,7 +2245,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
22092245

22102246
if((status && (status.widthRendered !== this.config.width)) || this.config.force)
22112247
{
2212-
console.log('renderBlobPdf');
2248+
this.log('renderBlobPdf');
22132249

22142250
// Render page
22152251
let page = await pdf.getPage(status.page);
@@ -2384,7 +2420,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
23842420

23852421
this.ebookPagesEpub = async function(config = {}) {
23862422

2387-
console.time('ebookPagesEpub: '+this.path);
2423+
this.time('ebookPagesEpub: '+this.path);
23882424

23892425
let epub = await this.openEpub();
23902426
let _this = this;
@@ -2409,7 +2445,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
24092445

24102446
this.setProgress(1);
24112447

2412-
console.timeEnd('ebookPagesEpub: '+this.path);
2448+
this.timeEnd('ebookPagesEpub: '+this.path);
24132449

24142450
return pages;
24152451

@@ -3435,8 +3471,8 @@ module.exports = {
34353471
file: function(path, _config = false) {
34363472
return new file(path, _config);
34373473
},
3438-
fileCompressed: function(path, realPath = false, forceType = false, prefixes = false){ // This consider moving it to a separate file
3439-
return new fileCompressed(path, realPath, forceType, prefixes);
3474+
fileCompressed: function(path, realPath = false, forceType = false, prefixes = false, _config = false){ // This consider moving it to a separate file
3475+
return new fileCompressed(path, realPath, forceType, prefixes, _config);
34403476
},
34413477
removeTmpVector: removeTmpVector,
34423478
removePathPart: removePathPart,

‎scripts/gamepad.js‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,9 @@ var gamepadResizeST = false;
944944

945945
window.addEventListener('resize', function(){
946946

947+
if(!windowHasLoaded)
948+
return;
949+
947950
gamepadResizeST = setTimeout(function(){
948951

949952
updateBrowsableItems(currentKey);

‎scripts/reading.js‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const render = require(p.join(appDir, 'scripts/reading/render.js')),
33
music = require(p.join(appDir, 'scripts/reading/music.js')),
44
contextMenu = require(p.join(appDir, 'scripts/reading/context-menu.js')),
55
pageTransitions = require(p.join(appDir, 'scripts/reading/page-transitions.js')),
6-
readingEbook = require(p.join(appDir, 'scripts/reading/ebook.js'));
6+
readingEbook = require(p.join(appDir, 'scripts/reading/ebook.js')),
7+
sidebar = require(p.join(appDir, 'scripts/reading/sidebar.js'));
78

89
var images = {}, imagesData = {}, imagesDataClip = {}, imagesPath = {}, imagesNum = 0, contentNum = 0, imagesNumLoad = 0, currentIndex = 1, imagesPosition = {}, imagesFullPosition = {}, prevImagesFullPosition = {}, foldersPosition = {}, indexNum = 0, imagesDistribution = [], currentPageXY = {x: 0, y: 0}, currentMousePosition = {pageX: 0, pageY: 0};
910

@@ -981,6 +982,8 @@ function goToImageCL(index, animation = true, fromScroll = false, fromPageRange
981982
else
982983
leftScroll.scrollTop = 0;
983984
}
985+
986+
sidebar.disableEvent(animationDurationMS + 50);
984987
}
985988

986989
if(!fromPageRange)
@@ -992,6 +995,8 @@ function goToImageCL(index, animation = true, fromScroll = false, fromPageRange
992995
const readingLeft = contentLeft.querySelector('.reading-left-images');
993996
if(readingLeft) readingLeft.style.opacity = 1;
994997

998+
sidebar.goToImage(index);
999+
9951000
// Change header buttons
9961001
if(!fromPageRange && (!readingViewIs('scroll') || !fromScroll))
9971002
changeHeaderButtons();
@@ -5602,6 +5607,8 @@ async function read(path, index = 1, end = false, isCanvas = false, isEbook = fa
56025607
imagesData[index] = {width: width, height: height, aspectRatio: (width / height), rotated: rotated, name: image.name};
56035608
}
56045609

5610+
sidebar.sizes(imagesData, currentComics);
5611+
56055612
render.setImagesData(imagesData);
56065613
filters.setImagesPath(imagesPath, readingCurrentPath);
56075614

@@ -5655,6 +5662,8 @@ async function read(path, index = 1, end = false, isCanvas = false, isEbook = fa
56555662
}
56565663
}
56575664

5665+
sidebar.sizes(imagesData, currentComics);
5666+
56585667
render.setImagesData(imagesData);
56595668
filters.setImagesPath(imagesPath, readingCurrentPath);
56605669

@@ -5809,4 +5818,5 @@ module.exports = {
58095818
contextMenu: contextMenu,
58105819
pageTransitions: pageTransitions,
58115820
render: render,
5821+
sidebar: sidebar,
58125822
};

0 commit comments

Comments
 (0)