Skip to content

Commit

Permalink
New: Option to set maximum size of temporary files, preserving them w…
Browse files Browse the repository at this point in the history
…hen closing the app
  • Loading branch information
ollm committed Dec 11, 2023
1 parent 0f81947 commit a727249
Show file tree
Hide file tree
Showing 24 changed files with 315 additions and 39 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## v1.0.1 (dd-mm-yyyy)
## v1.1.0 (dd-mm-yyyy)

##### 🚀 New Features

- Option to set maximum size of temporary files, preserving them when closing the app

##### 🐛 Bug Fixes

- Error on detect file type from binary
- Error on detect file type from binary [`0f81947`](https://github.com/ollm/OpenComic/commit/0f819470d42ce996cd4f1f0a31665a605d2bc39a)

## [v1.0.0](https://github.com/ollm/OpenComic/releases/tag/v1.0.0) (09-12-2023)

Expand Down
14 changes: 9 additions & 5 deletions languages/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,19 @@
"storage": {
"main": "Emmagatzematge",
"cache": "Memòria cau",
"cacheDescription": "Les miniatures i l'índex dels fitxers comprimits s'emmagatzemen aquí, no es recomana netejar-la tret que sigui molt gran o hi hagi algun error relacionat amb ella",
"cacheDescription": "Les miniatures i l'índex dels arxius comprimits s'emmagatzemen aquí, no es recomana netejar-la tret que sigui molt gran o hi hagi algun error relacionat amb ella",
"cacheMaxSize": "Tamany màxim de la memòria cau",
"cacheMaxSizeDescription": "S'eliminaran fitxers de la memòria cau quan superi aquesta mida, prioritzant els fitxers més antics sense ús",
"cacheMaxSizeDescription": "S'eliminaran arxius de la memòria cau quan superi aquesta mida, prioritzant els arxius més antics sense ús",
"cacheMaxOld": "Temps màxim de la memòria cau",
"cacheMaxOldDescription": "S'eliminaran fitxers de la memòria cau quan portin més d'aquest temps sense fer-se servir",
"cacheMaxOldDescription": "S'eliminaran arxius de la memòria cau quan portin més d'aquest temps sense fer-se servir",
"clearCache": "Netejar memòria cau",
"temporaryFiles": "Arxius temporals",
"temporaryFilesDescription": "Aquí es descomprimeixen els fitxers comprimits a mesura que es van necessitant, això s'elimina automàticament en tancar OpenComic",
"removeTemporaryFiles": "Eliminar fitxers temporals"
"temporaryFilesDescription": "Aquí es descomprimeixen els arxius comprimits a mesura que es van necessitant, això s'elimina parcialment en tancar OpenComic",
"removeTemporaryFiles": "Eliminar arxius temporals",
"temporaryFilesMaxSize": "Tamany màxim dels arxius temporals",
"temporaryFilesMaxSizeDescription": "S'eliminaran arxius temporals quan superin aquesta mida, prioritzant els arxius més antics sense ús",
"temporaryFilesMaxOld": "Temps màxim dels arxius temporals",
"temporaryFilesMaxOldDescription": "S'eliminaran arxius temporals quan portin més d'aquest temps sense fer-se servir"
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "",
"temporaryFiles": "",
"temporaryFilesDescription": "",
"removeTemporaryFiles": ""
"removeTemporaryFiles": "",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "",
"temporaryFiles": "",
"temporaryFilesDescription": "",
"removeTemporaryFiles": ""
"removeTemporaryFiles": "",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
8 changes: 6 additions & 2 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,12 @@
"cacheMaxOldDescription": "Files will be removed from the cache when they have not been used for more than this time",
"clearCache": "Clear cache",
"temporaryFiles": "Temporary files",
"temporaryFilesDescription": "Here the compressed files are decompressed as they are needed, this is automatically removed when closing OpenComic",
"removeTemporaryFiles": "Remove temporary files"
"temporaryFilesDescription": "Here the compressed files are decompressed as they are needed, this is partially removed when closing OpenComic",
"removeTemporaryFiles": "Remove temporary files",
"temporaryFilesMaxSize": "Maximum temporary files",
"temporaryFilesMaxSizeDescription": "Temporary files will be removed when they exceed this size, prioritizing older unused files",
"temporaryFilesMaxOld": "Maximum temporary files time",
"temporaryFilesMaxOldDescription": "Temporary files will be removed when they have not been used for more than this time"
}
},
"menu": {
Expand Down
8 changes: 6 additions & 2 deletions languages/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,12 @@
"cacheMaxOldDescription": "Se eliminarán archivos de la caché cuando lleven más de este tiempo sin usarse",
"clearCache": "Limpiar caché",
"temporaryFiles": "Archivos temporales",
"temporaryFilesDescription": "Aquí se descomprimen los archivos comprimidos a medida que se van necesitando, esto se elimina automáticamente al cerrar OpenComic",
"removeTemporaryFiles": "Eliminar archivos temporales"
"temporaryFilesDescription": "Aquí se descomprimen los archivos comprimidos a medida que se van necesitando, esto se elimina parcialmente al cerrar OpenComic",
"removeTemporaryFiles": "Eliminar archivos temporales",
"temporaryFilesMaxSize": "Tamaño máximo de los archivos temporales",
"temporaryFilesMaxSizeDescription": "Se eliminarán archivos temporales cuando superen este tamaño, priorizando los archivos más antiguos sin uso",
"temporaryFilesMaxOld": "Tiempo máximo de los archivos temporales",
"temporaryFilesMaxOldDescription": "Se eliminarán archivos temporales cuando lleven más de este tiempo sin usarse"
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "",
"temporaryFiles": "",
"temporaryFilesDescription": "",
"removeTemporaryFiles": ""
"removeTemporaryFiles": "",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "",
"temporaryFiles": "",
"temporaryFilesDescription": "",
"removeTemporaryFiles": ""
"removeTemporaryFiles": "",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "",
"temporaryFiles": "",
"temporaryFilesDescription": "",
"removeTemporaryFiles": ""
"removeTemporaryFiles": "",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "",
"temporaryFiles": "",
"temporaryFilesDescription": "",
"removeTemporaryFiles": ""
"removeTemporaryFiles": "",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "",
"temporaryFiles": "",
"temporaryFilesDescription": "",
"removeTemporaryFiles": ""
"removeTemporaryFiles": "",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "",
"temporaryFiles": "",
"temporaryFilesDescription": "",
"removeTemporaryFiles": ""
"removeTemporaryFiles": "",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "ล้างแคช",
"temporaryFiles": "ไฟล์ชั่วคราว",
"temporaryFilesDescription": "ที่ที่ไฟล์บีบอัดจำเป็นต้นใช้ในการคลายไฟล์ โดยจะมีการนำไฟล์ออกโดยอัตโนมัติเมื่อปิด OpenComic",
"removeTemporaryFiles": "นำไฟล์ชั่วคราวออก"
"removeTemporaryFiles": "นำไฟล์ชั่วคราวออก",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "",
"temporaryFiles": "",
"temporaryFilesDescription": "",
"removeTemporaryFiles": ""
"removeTemporaryFiles": "",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/zh-hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "清除缓存",
"temporaryFiles": "临时文件",
"temporaryFilesDescription": "在这里,压缩文件根据需要进行解压缩,这在关闭 OpenComic 时会自动删除",
"removeTemporaryFiles": "删除临时文件"
"removeTemporaryFiles": "删除临时文件",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
6 changes: 5 additions & 1 deletion languages/zh-hant.json
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,11 @@
"clearCache": "",
"temporaryFiles": "",
"temporaryFilesDescription": "",
"removeTemporaryFiles": ""
"removeTemporaryFiles": "",
"temporaryFilesMaxSize": "",
"temporaryFilesMaxSizeDescription": "",
"temporaryFilesMaxOld": "",
"temporaryFilesMaxOldDescription": ""
}
},
"menu": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "opencomic",
"productName": "OpenComic",
"version": "1.0.1",
"version": "1.1.0",
"main": "scripts/main.js",
"type": "commonjs",
"keywords": [
Expand Down
6 changes: 6 additions & 0 deletions scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ function stripTagsWithDOM(string)
return doc.body.textContent || '';
}

function time()
{
return Math.floor(Date.now() / 1000);
}

function sleep(ms)
{
return new Promise(function(resolve){
Expand Down Expand Up @@ -231,6 +236,7 @@ module.exports = {
extract: extract,
capitalize: capitalize,
stripTagsWithDOM: stripTagsWithDOM,
time: time,
sleep: sleep,
setImmediate: setImmediate,
};
8 changes: 5 additions & 3 deletions scripts/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ function returnThumbnailsImages(images, callback, file = false)
let toGenerateThumbnails = [];
let toGenerateThumbnailsData = {};

let time = app.time();

for(let i = 0, len = images.length; i < len; i++)
{
let image = images[i];
Expand All @@ -145,7 +147,7 @@ function returnThumbnailsImages(images, callback, file = false)
}
else
{
data[sha].lastAccess = time();
data[sha].lastAccess = time;

if(imgCache.size != size)
{
Expand Down Expand Up @@ -240,7 +242,7 @@ function purge()
{
if(!data) data = storage.get('cache') || {};

let _time = time();
let time = app.time();

let cacheMaxSize = config.cacheMaxSize * 1000 * 1000;
let cacheMaxOld = config.cacheMaxOld * 60 * 60 * 24;
Expand All @@ -250,7 +252,7 @@ function purge()
// Remove not usage files
for(let sha in data)
{
if(_time - data[sha].lastAccess > cacheMaxOld)
if(time - data[sha].lastAccess > cacheMaxOld)
{
deleteInCacheSha(sha);
}
Expand Down
41 changes: 39 additions & 2 deletions scripts/file-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,9 @@ var file = function(path) {
{
let file = files[i];

if(fs.existsSync(realPath(file.path, -1, this.config.prefixes)))
let _path = realPath(file.path, -1, this.config.prefixes);

if(fs.existsSync(_path))
{
if(callbackWhenFileAvailable) callbackWhenFileAvailable(file);
}
Expand All @@ -592,6 +594,9 @@ var file = function(path) {

filesToDecompressNum++;
}

if(_path !== file.path) // If it is different it is because it is not a compressed file
this.setTmpUsage(_path);
}

if(filesToDecompress)
Expand All @@ -613,9 +618,41 @@ var file = function(path) {
}
}

this.saveTmpUsage();

return filesToDecompressNum;
}

this.tmpUsage = [];

this.setTmpUsage = function(path) {

this.tmpUsage.push(path);

}

this.saveTmpUsage = function() {

let len = this.tmpUsage.length;

if(len === 0) return;

let time = app.time();
let tmpUsage = storage.get('tmpUsage');

for(let i = 0; i < len; i++)
{
let path = this.tmpUsage[i];

if(!tmpUsage[path]) tmpUsage[path] = {};
tmpUsage[path].lastAccess = time;
}

storage.setThrottle('tmpUsage', tmpUsage);
this.tmpUsage = [];

}

this.macosScopedResources = [];

this.macosStartAccessingSecurityScopedResource = function(path) {
Expand Down Expand Up @@ -1804,7 +1841,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
}
catch(error)
{
return this.readIfTypeFromBinaryIsDifferent(error);
return this.extractIfTypeFromBinaryIsDifferent(error);
}
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function createWindow() {
{
appClosing = true;

win.webContents.executeJavaScript('var saved = reading.saveReadingProgress(); settings.removeTemporaryFiles(true); cache.purge(); ebook.closeAllRenders(); saved;', false).then(function(value) {
win.webContents.executeJavaScript('var saved = reading.saveReadingProgress(); settings.purgeTemporaryFiles(); cache.purge(); ebook.closeAllRenders(); saved;', false).then(function(value) {

if(!value)
app.quit();
Expand Down
Loading

0 comments on commit a727249

Please sign in to comment.