diff --git a/CHANGELOG.md b/CHANGELOG.md index 5278d268a..78055c550 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Ignore single folders in browsing [`7507563`](https://github.com/ollm/OpenComic/commit/75075631fcad5fb269427c178e9bac86bc352971) - Search and filter in library/browsing [`8393903`](https://github.com/ollm/OpenComic/commit/8393903117981bea2b8a79e2e50b77d02334aa05) - Tracking at the end of the chapter/volume setting option [`39f1954`](https://github.com/ollm/OpenComic/commit/39f19546b2fd363d321f9c423e706c3dc773aa4f) +- View size and remove cache and temporary files from settings ##### 🐛 Bug Fixes @@ -29,6 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Ignore first gamepad and keyboard event in browsing [`9347fbe`](https://github.com/ollm/OpenComic/commit/9347fbe628143e688f956ed0950510a2265c02e2) - Blurry image when zooming [`0732f3f`](https://github.com/ollm/OpenComic/commit/0732f3f76923f2a50541139e58fb8343e7c20083) - Progress was not saved in some cases [`964bb64`](https://github.com/ollm/OpenComic/commit/964bb64ee765d3830615e78413bf520b17549b0c) +- Error on opening file in OpenComic [`cb56ccf`](https://github.com/ollm/OpenComic/commit/cb56ccfd032ebfdd60be19a4a9fed82f6b60d0d5) ## [v1.0.0-beta.2](https://github.com/ollm/OpenComic/releases/tag/v1.0.0-beta.2) (03-09-2023) diff --git a/languages/ca.json b/languages/ca.json index 39dd12d9d..a01de3907 100644 --- a/languages/ca.json +++ b/languages/ca.json @@ -175,6 +175,15 @@ "main": "Carpetes mestres", "folder": "Carpeta", "noFolders": "Sense carpetes" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/languages/cs.json b/languages/cs.json index fc41475d2..0edf7e0f1 100644 --- a/languages/cs.json +++ b/languages/cs.json @@ -175,6 +175,15 @@ "main": "", "folder": "", "noFolders": "" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/languages/de.json b/languages/de.json index dd9e3384c..daa26f41a 100644 --- a/languages/de.json +++ b/languages/de.json @@ -175,6 +175,15 @@ "main": "", "folder": "", "noFolders": "" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/languages/en.json b/languages/en.json index 56b897a86..56c68d3e3 100644 --- a/languages/en.json +++ b/languages/en.json @@ -175,6 +175,15 @@ "main": "Master folders", "folder": "Folder", "noFolders": "No folders" + }, + "storage": { + "main": "Storage", + "cache": "Cache", + "cacheDescription": "The thumbnails and index of the compressed files are stored here, it is not recommended to clean it unless it is very large or there is an error related to it", + "clearCache": "Clear cache", + "temporaryFiles": "Temporary files", + "temporaryFilesDescription": "Here the compressed files are decompressed as they are needed, this is automatically deleted when closing OpenComic", + "removeTemporaryFiles": "Remove temporary files" } }, "menu": { diff --git a/languages/es.json b/languages/es.json index 72de88641..3c155f886 100644 --- a/languages/es.json +++ b/languages/es.json @@ -175,6 +175,15 @@ "main": "Carpetas maestras", "folder": "Carpeta", "noFolders": "Sin carpetas" + }, + "storage": { + "main": "Almacenamiento", + "cache": "CachĂ©", + "cacheDescription": "Las miniaturas y el Ă­ndice de los archivos comprimidos se almacenan aquĂ­, no se recomienda limpiarla a no ser que sea muy grande o haya algĂșn error relacionado con ella", + "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" } }, "menu": { diff --git a/languages/fr.json b/languages/fr.json index 470dc2ae4..565038fe0 100644 --- a/languages/fr.json +++ b/languages/fr.json @@ -175,6 +175,15 @@ "main": "", "folder": "", "noFolders": "" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/languages/hu.json b/languages/hu.json index 297c3b653..707de1bab 100644 --- a/languages/hu.json +++ b/languages/hu.json @@ -175,6 +175,15 @@ "main": "", "folder": "", "noFolders": "" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/languages/it.json b/languages/it.json index 01a9c0fb0..c985a71d2 100644 --- a/languages/it.json +++ b/languages/it.json @@ -175,6 +175,15 @@ "main": "", "folder": "", "noFolders": "" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/languages/ja.json b/languages/ja.json index fa4992e2f..a6e058baa 100644 --- a/languages/ja.json +++ b/languages/ja.json @@ -175,6 +175,15 @@ "main": "", "folder": "", "noFolders": "" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/languages/pt-br.json b/languages/pt-br.json index 450b01518..348ec5706 100644 --- a/languages/pt-br.json +++ b/languages/pt-br.json @@ -175,6 +175,15 @@ "main": "", "folder": "", "noFolders": "" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/languages/ru.json b/languages/ru.json index c1c3a2228..1fbae34fe 100644 --- a/languages/ru.json +++ b/languages/ru.json @@ -175,6 +175,15 @@ "main": "", "folder": "", "noFolders": "" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/languages/vi.json b/languages/vi.json index 307ab887b..78cfd5840 100644 --- a/languages/vi.json +++ b/languages/vi.json @@ -175,6 +175,15 @@ "main": "", "folder": "", "noFolders": "" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/languages/zh-hans.json b/languages/zh-hans.json index 32bdf8b49..0535b878c 100644 --- a/languages/zh-hans.json +++ b/languages/zh-hans.json @@ -175,6 +175,15 @@ "main": "", "folder": "", "noFolders": "" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/languages/zh-hant.json b/languages/zh-hant.json index 7abbf589c..e01251d40 100644 --- a/languages/zh-hant.json +++ b/languages/zh-hant.json @@ -175,6 +175,15 @@ "main": "", "folder": "", "noFolders": "" + }, + "storage": { + "main": "", + "cache": "", + "cacheDescription": "", + "clearCache": "", + "temporaryFiles": "", + "temporaryFilesDescription": "", + "removeTemporaryFiles": "" } }, "menu": { diff --git a/scripts/file-manager.js b/scripts/file-manager.js index 90e4f9693..0feafb46b 100644 --- a/scripts/file-manager.js +++ b/scripts/file-manager.js @@ -30,10 +30,10 @@ var file = function(path) { if(fs.existsSync(path)) { - if(fs.statSync(path).isDirectory()) - this.isFolder = true; - else if(inArray(fileExtension(path), compressedExtensions.all)) + if(inArray(fileExtension(path), compressedExtensions.all)) this.isCompressed = true; + else if(fs.statSync(path).isDirectory()) + this.isFolder = true; } return {folder: this.isFolder, compressed: this.isCompressed}; @@ -59,10 +59,10 @@ var file = function(path) { } else { - if(fs.statSync(_realPath).isDirectory()) - files = await this.readDir(path, _realPath); - else if(inArray(fileExtension(path), compressedExtensions.all)) + if(inArray(fileExtension(path), compressedExtensions.all)) files = await this.readCompressed(path, _realPath); + else if(fs.statSync(_realPath).isDirectory()) + files = await this.readDir(path, _realPath); } if(this.config.sort) @@ -90,7 +90,7 @@ var file = function(path) { let _this = this; - return fs.promises.readdir(_realPath).then(function(_files){ + return fs.promises.readdir(_realPath, {withFileTypes: !_this.config.fastRead}).then(function(_files){ let files = []; @@ -98,15 +98,17 @@ var file = function(path) { { for(let i = 0, len = _files.length; i < len; i++) { - let filePath = p.join(path, _files[i]); + let name = _this.config.fastRead ? _files[i] : _files[i].name; + + let filePath = p.join(path, name); let retrunPath = filePath; - if(!_this.config.fastRead && fs.statSync(filePath).isDirectory()) - files.push({name: _files[i], path: retrunPath, folder: true, compressed: false}); + if(!_this.config.fastRead && _files[i].isDirectory()) + files.push({name: name, path: retrunPath, folder: true, compressed: false}); else if(inArray(fileExtension(filePath), compressedExtensions.all)) - files.push({name: _files[i], path: retrunPath, folder: false, compressed: true}); + files.push({name: name, path: retrunPath, folder: false, compressed: true}); else - files.push({name: _files[i], path: retrunPath, folder: false, compressed: false}); + files.push({name: name, path: retrunPath, folder: false, compressed: false}); } } @@ -1882,10 +1884,10 @@ function pathType(path) { if(inArray(mime.getType(path), compatibleMime)) return {folder: false, compressed: false}; - else if(fs.statSync(path).isDirectory()) - return {folder: true, compressed: false}; else if(inArray(fileExtension(path), compressedExtensions.all)) return {folder: false, compressed: true}; + else if(fs.statSync(path).isDirectory()) + return {folder: true, compressed: false}; else return false; } @@ -1937,6 +1939,25 @@ function sort(files) } } +async function dirSize(dir) +{ + let files = await fs.promises.readdir(dir, {withFileTypes: true}); + let size = 0; + + for(let i = 0, len = files.length; i < len; i++) + { + let file = files[i]; + let path = p.join(dir, file.name); + + if(file.isDirectory()) + size += await dirSize(path); + else if(file.isFile()) + size += (await fs.promises.stat(path)).size; + } + + return size; +} + var prevDevicePixelRatio = window.devicePixelRatio; window.addEventListener('resize', function() { @@ -1965,4 +1986,5 @@ module.exports = { firstCompressedFile: firstCompressedFile, lastCompressedFile: lastCompressedFile, containsCompressed: containsCompressed, + dirSize: dirSize, } diff --git a/scripts/main.js b/scripts/main.js index 881ba8f8e..f5d1aebac 100644 --- a/scripts/main.js +++ b/scripts/main.js @@ -79,7 +79,7 @@ function createWindow() { { appClosing = true; - win.webContents.executeJavaScript('var saved = reading.saveReadingProgress(); removeTemporaryFiles(); saved;', false).then(function(value) { + win.webContents.executeJavaScript('var saved = reading.saveReadingProgress(); settings.removeTemporaryFiles(true); saved;', false).then(function(value) { if(!value) win.close(); diff --git a/scripts/opencomic.js b/scripts/opencomic.js index 00213b2d4..5c1efdf09 100644 --- a/scripts/opencomic.js +++ b/scripts/opencomic.js @@ -631,18 +631,6 @@ function showAboutWindow() }); } -function removeTemporaryFiles() -{ - try - { - fse.emptyDirSync(tempFolder); - } - catch(error) - { - console.error(error); - } -} - function escapeBackSlash(string) { return string.replace(/\\+/g, '\\\\'); diff --git a/scripts/settings.js b/scripts/settings.js index 6c6bd6e97..19237c6ce 100644 --- a/scripts/settings.js +++ b/scripts/settings.js @@ -1,12 +1,64 @@ function start() { - events.events(); - generateShortcutsTable(); updateMasterFolders(); + + getStorageSize(); + + events.events(); +} + +async function getStorageSize() +{ + // Cache size + let cacheSize = await fileManager.dirSize(cache.folder); + + cacheSize = cacheSize / 1000 / 1000; + + if(cacheSize > 1000) + cacheSize = app.round(cacheSize / 1000, 1)+'GB'; + else + cacheSize = app.round(cacheSize, 1)+'MB'; + + dom.queryAll('.cacheSize').html(' ('+cacheSize+')'); + + // Temp size + let tmpSize = await fileManager.dirSize(tempFolder); + + tmpSize = tmpSize / 1000 / 1000; + + if(tmpSize > 1000) + tmpSize = app.round(tmpSize / 1000, 1)+'GB'; + else + tmpSize = app.round(tmpSize, 1)+'MB'; + + dom.queryAll('.temporaryFilesSize').html(' ('+tmpSize+')'); +} + +async function clearCache() +{ + await fse.emptyDir(cache.folder); + + getStorageSize(); } +function removeTemporaryFiles(onClose = false) +{ + try + { + fse.emptyDirSync(tempFolder); + } + catch(error) + { + console.error(error); + } + + if(!onClose) + getStorageSize(); +} + + function removeMasterFolder(key) { let masterFolders = storage.get('masterFolders'); @@ -296,4 +348,6 @@ module.exports = { resoreShortcuts: resoreShortcuts, removeMasterFolder: removeMasterFolder, addMasterFolder: addMasterFolder, + clearCache: clearCache, + removeTemporaryFiles: removeTemporaryFiles, }; \ No newline at end of file diff --git a/templates/settings.content.right.html b/templates/settings.content.right.html index c9b23b188..f2dde13a0 100644 --- a/templates/settings.content.right.html +++ b/templates/settings.content.right.html @@ -126,6 +126,32 @@

{{language.settings.releases.main}}

+ + +

{{language.settings.storage.main}}

+ + + + + +
diff --git a/themes/material-design/actions.css b/themes/material-design/actions.css index f63259a0f..c9216c3e6 100644 --- a/themes/material-design/actions.css +++ b/themes/material-design/actions.css @@ -721,13 +721,35 @@ .menu-simple-text, .menu-simple-button { - height: 52px; + min-height: 52px; padding: 0px 24px; line-height: 52px; transition: background-color 0.2s, opacity 0.2s; position: relative; } +.menu-simple-supporting-text +{ + display: flex; + justify-content: space-between; + align-items: center; +} + +.menu-simple-supporting-text > span +{ + line-height: 44px; + max-width: calc(100% - 450px); +} + +.menu-simple-supporting-text > span > span +{ + color: var(--md-sys-color-on-surface-variant); + color: color-mix(in srgb, var(--md-sys-color-on-surface-variant), transparent 20%); + margin-top: -12px; + display: block; + padding-bottom: 12px; +} + .menu-grey { color: color-mix(in srgb, var(--md-sys-color-on-surface), transparent 50%);