Skip to content

Commit e11046b

Browse files
committed
New: Support for image format
1 parent 60d27bb commit e11046b

12 files changed

Lines changed: 438 additions & 124 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
##### 🚀 New Features
1010

11-
- Improve chapter detection in tracking
11+
- Improve chapter detection in tracking [`ad05a23`](https://github.com/ollm/OpenComic/commit/ad05a2364882227688cccfa2fdf58a21f8e9615c)
12+
- Support for `JP2` image format
1213

1314
## [v1.4.1](https://github.com/ollm/OpenComic/releases/tag/v1.4.1) (08-02-2025)
1415

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/cache.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ var imagesWithoutSaving = 0;
3131

3232
function processTheImageQueue()
3333
{
34-
let img = queuedImages[0];
34+
let img = queuedImages.shift();
35+
if(!img) return;
36+
3537
let sha = img.sha;
3638

3739
let realPath = fileManager.realPath(img.file);
@@ -52,8 +54,6 @@ function processTheImageQueue()
5254

5355
img.callback({cache: true, path: escapeBackSlash(addCacheVars(toImage, img.size, img.sha)), sha: sha}, img.vars);
5456

55-
queuedImages.splice(0, 1);
56-
5757
if(queuedImages.length > 0)
5858
{
5959
imagesWithoutSaving++;
@@ -80,8 +80,6 @@ function processTheImageQueue()
8080

8181
img.callback({cache: true, path: escapeBackSlash(realPath), sha: sha}, img.vars);
8282

83-
queuedImages.splice(0, 1);
84-
8583
if(queuedImages.length > 0)
8684
{
8785
imagesWithoutSaving++;
@@ -107,8 +105,13 @@ function processTheImageQueue()
107105
});
108106
}
109107

110-
function addImageToQueue(file, size, sha, callback, vars, type, forceSize)
108+
async function addImageToQueue(file, size, sha, callback, vars, type, forceSize)
111109
{
110+
const extention = fileExtension(file);
111+
112+
if(inArray(extention, imageExtensions.convert)) // Convert unsupported images
113+
await workers.convertImage(file);
114+
112115
queuedImages.push({file: file, size: size, sha: sha, callback: callback, vars: vars, type: type, forceSize: forceSize});
113116

114117
if(!processingTheImageQueue && !stopTheImageQueue)

scripts/dom.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,6 +2452,8 @@ async function openComic(animation = true, path = true, mainPath = true, end = f
24522452
await file.makeAvailable(files, false, true);
24532453
}
24542454

2455+
await fileManager.convertUnsupportedImages(files);
2456+
24552457
if(hasMusic) files.pop(); // Remove now
24562458

24572459
file.destroy();

scripts/dom/poster.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function openDialog(path)
5656
{
5757
let dialog = electronRemote.dialog;
5858

59-
dialog.showOpenDialog({properties: ['openFile'], defaultPath: fileManager.containsCompressed(path) ? p.dirname(path) : path, filters: [{name: language.global.comics, extensions: [...compatibleImageExtensions, ...compatibleSpecialExtensions]}]}).then(function (files) {
59+
dialog.showOpenDialog({properties: ['openFile'], defaultPath: fileManager.containsCompressed(path) ? p.dirname(path) : path, filters: [{name: language.global.comics, extensions: [...compatibleImageExtensionsWithoutConvert, ...compatibleSpecialExtensions]}]}).then(function (files) {
6060

6161
if(files.filePaths && files.filePaths[0])
6262
setNewPoster(files.filePaths[0]);

scripts/file-manager.js

Lines changed: 79 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ var file = function(path, _config = false) {
784784
}
785785

786786
if(_path !== file.path) // If it is different it is because it is not a compressed file
787-
this.setTmpUsage(_path);
787+
fileManager.setTmpUsage(_path);
788788
}
789789

790790
if(filesToDecompress)
@@ -842,41 +842,9 @@ var file = function(path, _config = false) {
842842
}
843843
}
844844

845-
this.saveTmpUsage();
846-
847845
return filesToDecompressNum;
848846
}
849847

850-
this.tmpUsage = [];
851-
852-
this.setTmpUsage = function(path) {
853-
854-
this.tmpUsage.push(path);
855-
856-
}
857-
858-
this.saveTmpUsage = function() {
859-
860-
let len = this.tmpUsage.length;
861-
862-
if(len === 0) return;
863-
864-
let time = app.time();
865-
let tmpUsage = storage.get('tmpUsage');
866-
867-
for(let i = 0; i < len; i++)
868-
{
869-
let path = this.tmpUsage[i];
870-
871-
if(!tmpUsage[path]) tmpUsage[path] = {};
872-
tmpUsage[path].lastAccess = time;
873-
}
874-
875-
storage.setThrottle('tmpUsage', tmpUsage);
876-
this.tmpUsage = [];
877-
878-
}
879-
880848
this.macosScopedResources = [];
881849

882850
this.macosStartAccessingSecurityScopedResource = function(path) {
@@ -1105,15 +1073,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
11051073
this.setTmpUsage = function() {
11061074

11071075
if(this.path !== this.realPath)
1108-
{
1109-
let time = app.time();
1110-
let tmpUsage = storage.get('tmpUsage');
1111-
1112-
if(!tmpUsage[this.realPath]) tmpUsage[this.realPath] = {};
1113-
tmpUsage[this.realPath].lastAccess = time;
1114-
1115-
storage.setThrottle('tmpUsage', tmpUsage);
1116-
}
1076+
fileManager.setTmpUsage(this.realPath);
11171077

11181078
}
11191079

@@ -2893,13 +2853,13 @@ function downloadedCompressedFile(path)
28932853

28942854
function realPath(path, index = 0, prefixes = false)
28952855
{
2896-
let segments = splitPath(path);
2897-
let len = segments.length;
2856+
const segments = splitPath(path);
2857+
const len = segments.length;
2858+
const numSegments = len + index;
28982859

28992860
let virtualPath;
29002861

29012862
let newPath = virtualPath = (len > 0) ? (isEmpty(segments[0]) ? '/' : segments[0]) : '';
2902-
let numSegments = len + index;
29032863

29042864
if(isServer(path))
29052865
{
@@ -2923,31 +2883,94 @@ function realPath(path, index = 0, prefixes = false)
29232883
{
29242884
let extension = fileExtension(newPath);
29252885

2926-
if(extension && inArray(extension, compressedExtensions.all)/* && fs.existsSync(newPath) && !fs.statSync(newPath).isDirectory()*/)
2886+
if(extension)
29272887
{
2928-
let sha = sha1(p.normalize(virtualPath));
2929-
2930-
if(prefixes)
2888+
if(inArray(extension, compressedExtensions.all) /* && fs.existsSync(newPath) && !fs.statSync(newPath).isDirectory()*/)
29312889
{
2932-
for(let ext in prefixes)
2890+
let sha = sha1(p.normalize(virtualPath));
2891+
2892+
if(prefixes)
29332893
{
2934-
if(inArray(extension, compressedExtensions[ext]))
2894+
for(let ext in prefixes)
29352895
{
2936-
sha = prefixes[ext]+'-'+sha;
2896+
if(inArray(extension, compressedExtensions[ext]))
2897+
{
2898+
sha = prefixes[ext]+'-'+sha;
29372899

2938-
break;
2900+
break;
2901+
}
29392902
}
29402903
}
2904+
2905+
newPath = p.join(tempFolder, sha);
29412906
}
2907+
else if(inArray(extension, imageExtensions.convert) && i + 1 === len)
2908+
{
2909+
const sha = sha1(p.dirname(p.normalize(virtualPath)));
29422910

2943-
newPath = p.join(tempFolder, sha);
2911+
let image = p.basename(virtualPath);
2912+
image = image+'.png';
2913+
2914+
newPath = p.join(tempFolder, sha, image);
2915+
}
29442916
}
29452917
}
29462918
}
29472919

29482920
return newPath;
29492921
}
29502922

2923+
async function convertUnsupportedImages(files)
2924+
{
2925+
const promises = [];
2926+
2927+
for(let i = 0, len = files.length; i < len; i++)
2928+
{
2929+
const file = files[i];
2930+
const path = file.path;
2931+
2932+
if(inArray(fileExtension(path), imageExtensions.convert)) // Convert unsupported images
2933+
promises.push(workers.convertImage(path));
2934+
}
2935+
2936+
await Promise.all(promises);
2937+
2938+
return true;
2939+
}
2940+
2941+
var tmpUsageST = false, tmpUsageQueue = [];
2942+
2943+
function setTmpUsage(path)
2944+
{
2945+
tmpUsageQueue.push(path);
2946+
2947+
if(tmpUsageST === false)
2948+
{
2949+
tmpUsageST = setTimeout(function() {
2950+
2951+
tmpUsageST = false;
2952+
2953+
const len = tmpUsageQueue.length;
2954+
if(len === 0) return;
2955+
2956+
const time = app.time();
2957+
const tmpUsage = storage.get('tmpUsage');
2958+
2959+
for(let i = 0; i < len; i++)
2960+
{
2961+
const path = tmpUsageQueue[i];
2962+
2963+
if(!tmpUsage[path]) tmpUsage[path] = {};
2964+
tmpUsage[path].lastAccess = time;
2965+
}
2966+
2967+
storage.setThrottle('tmpUsage', tmpUsage);
2968+
tmpUsageQueue = [];
2969+
2970+
}, 1000);
2971+
}
2972+
}
2973+
29512974
var serverInOfflineMode = false;
29522975

29532976
function setServerInOfflineMode(value = false)
@@ -3372,6 +3395,8 @@ module.exports = {
33723395
isParentPath: isParentPath,
33733396
simpleExists: simpleExists,
33743397
replaceReservedCharacters: replaceReservedCharacters,
3398+
convertUnsupportedImages: convertUnsupportedImages,
3399+
setTmpUsage: setTmpUsage,
33753400
macosSecurityScopedBookmarks: macosSecurityScopedBookmarks,
33763401
macosStartAccessingSecurityScopedResource: macosStartAccessingSecurityScopedResource,
33773402
dirSize: dirSize,

0 commit comments

Comments
 (0)