Skip to content

Commit f774ed4

Browse files
committed
New: Local Artwork Assets
1 parent 91933a9 commit f774ed4

File tree

8 files changed

+174
-22
lines changed

8 files changed

+174
-22
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1818
- Updated electron to v25.5.0 [`41214a5`](https://github.com/ollm/OpenComic/commit/41214a50bc9b0bce56f12b302d47f6d44f12fd81)
1919
- Update theme to Material 3 [`0f537fb`](https://github.com/ollm/OpenComic/commit/0f537fb37d9108986f1cdac41cc56e6c51d51428)
2020
- Settings page to set some default values [`12907bc`](https://github.com/ollm/OpenComic/commit/12907bcb84dccc5c8f0a65c78c65915f55e8cb0f)
21+
- Drag and Drop support [`91933a9`](https://github.com/ollm/OpenComic/commit/91933a998885a2579592566d7773549085495e4e)
2122

2223
### 🐛 Bug Fixes
2324

scripts/app.js

+6
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,14 @@ function empty(mixedVar)
7979
return false
8080
}
8181

82+
function extname(path)
83+
{
84+
return p.extname(path).replace(/^.*\./, '').toLowerCase();
85+
}
86+
8287
module.exports = {
8388
event: event,
8489
eventOff: eventOff,
8590
empty: empty,
91+
extname: extname,
8692
};

scripts/dom.js

+79-2
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ function addImageToDom(querySelector, path, animation = true)
434434
else
435435
$('.fi-sha-'+querySelector+', .sha-'+querySelector+' .item-image').css({'background-image': 'url('+path+')'}).addClass('a');
436436

437+
$('.pi-sha-'+querySelector).css({'background-image': 'url('+path+')'}).addClass('a');
437438
$('.ri-sha-'+querySelector).attr('src', path);
438439
$('.continue-reading-sha-'+querySelector).css({'background-image': 'url('+path+')'}).addClass('a');
439440
}
@@ -446,6 +447,7 @@ function addImageToDom(querySelector, path, animation = true)
446447
else
447448
$('.fi-sha-'+querySelector+', .sha-'+querySelector+' .item-image').css({'transition': '0s', 'background-image': 'url('+path+')'});
448449

450+
$('.pi-sha-'+querySelector).css({'background-image': 'url('+path+')'});
449451
$('.ri-sha-'+querySelector).attr('src', path);
450452
$('.continue-reading-sha-'+querySelector).css({'transition': '0s', 'background-image': 'url('+path+')'});
451453
}
@@ -504,12 +506,20 @@ async function loadFilesIndexPage(file, animation, path, keepScroll, mainPath)
504506
}
505507
else if(file.folder || file.compressed)
506508
{
507-
let images = await getFolderThumbnails(filePath);
509+
let poster = await getFolderPoster(filePath);
510+
511+
let images = [];
512+
513+
if(!poster)
514+
{
515+
images = await getFolderThumbnails(filePath);
516+
}
508517

509518
pathFiles.push({
510519
name: fileName,
511520
path: filePath,
512521
mainPath: mainPath,
522+
poster: poster,
513523
images: images,
514524
folder: true,
515525
});
@@ -655,8 +665,16 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
655665

656666
for(let key in comics)
657667
{
658-
var images = await getFolderThumbnails(comics[key].path);
668+
let poster = await getFolderPoster(comics[key].path);
669+
670+
let images = [];
671+
672+
if(!poster)
673+
{
674+
images = await getFolderThumbnails(comics[key].path);
675+
}
659676

677+
comics[key].poster = poster;
660678
comics[key].images = images;
661679
comics[key].mainPath = config.showFullPathLibrary ? p.parse(comics[key].path).root : comics[key].path;
662680
}
@@ -891,6 +909,65 @@ async function getFolderThumbnails(path)
891909
return images;
892910
}
893911

912+
async function getFolderPoster(path)
913+
{
914+
let dirname = p.dirname(path);
915+
let basename = p.basename(path);
916+
let name = p.parse(basename).name;
917+
918+
// console.log(path);
919+
920+
try
921+
{
922+
let file = fileManager.file(dirname);
923+
file.updateConfig({cacheOnly: true, fastRead: true, specialFiles: true, sha: false});
924+
let files = await file.read();
925+
926+
let regex = new RegExp('^'+pregQuote(name)+'\.[a-z0-9]+');
927+
let poster = false;
928+
929+
for(let i = 0, len = files.length; i < len; i++)
930+
{
931+
let file = files[i];
932+
933+
if(!file.folder && !file.compressed && regex.test(file.name))
934+
{
935+
file.sha = sha1(file.path);
936+
poster = file;
937+
938+
break;
939+
}
940+
}
941+
942+
if(poster)
943+
{
944+
let thumbnail = cache.returnThumbnailsImages({path: poster.path, sha: poster.sha}, function(data){
945+
946+
addImageToDom(data.sha, data.path);
947+
948+
}, file);
949+
950+
console.log(thumbnail);
951+
952+
return thumbnail;
953+
}
954+
}
955+
catch(error)
956+
{
957+
if(error.message && error.message === 'notCacheOnly')
958+
{
959+
// Nothing to do
960+
}
961+
else
962+
{
963+
console.error(error);
964+
dom.compressedError(error);
965+
}
966+
}
967+
968+
return false;
969+
}
970+
894971
var indexPathControlA = [], indexPathA = false, indexMainPathA = false;
895972

896973
function indexPathControlGoBack()

scripts/file-manager.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ var file = function(path) {
8080
this.files = files;
8181
}
8282

83-
return this.config.filtered ? filtered(files) : files;
83+
return this.config.filtered ? filtered(files, this.config.specialFiles) : files;
8484
}
8585

8686
this.readDir = function(path = false, _realPath = false) {
@@ -98,12 +98,12 @@ var file = function(path) {
9898
let filePath = p.join(path, _files[i]);
9999
let retrunPath = filePath;
100100

101-
if(inArray(mime.getType(filePath), compatibleMime))
102-
files.push({name: _files[i], path: retrunPath, folder: false, compressed: false});
103-
else if(fs.statSync(filePath).isDirectory())
101+
if(!this.config.fastRead && fs.statSync(filePath).isDirectory())
104102
files.push({name: _files[i], path: retrunPath, folder: true, compressed: false});
105103
else if(inArray(fileExtension(filePath), compressedExtensions.all))
106104
files.push({name: _files[i], path: retrunPath, folder: false, compressed: true});
105+
else
106+
files.push({name: _files[i], path: retrunPath, folder: false, compressed: false});
107107
}
108108
}
109109

@@ -1739,7 +1739,7 @@ function pathType(path)
17391739
return false;
17401740
}
17411741

1742-
function filtered(files)
1742+
function filtered(files, specialFiles = false)
17431743
{
17441744
let filtered = [];
17451745

@@ -1751,7 +1751,7 @@ function filtered(files)
17511751

17521752
if(file.folder || file.compressed)
17531753
filtered.push(file);
1754-
else if(inArray(mime.getType(file.path), compatibleMime))
1754+
else if(inArray(mime.getType(file.path), compatibleMime) || (specialFiles && inArray(app.extname(file.path), compatibleSpecialExtensions)))
17551755
filtered.push(file);
17561756
}
17571757
}

scripts/opencomic.js

+4
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ var compatibleExtensions = [
195195
/*compressed*/'zip', 'cbz', 'rar', 'cbr', '7z', 'cb7', 'tar', 'cbt', 'pdf',
196196
];
197197

198+
var compatibleSpecialExtensions = [
199+
'tbn',
200+
];
201+
198202
//console.time('Require time 2');
199203

200204
const app = require(p.join(appDir, 'scripts/app.js')),

templates/index.content.right.module.html

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@
1111
<div class="{{#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}}"{{#if @root.comicsIndex}} oncontextmenu="dom.comicContextMenu('{{chain 'escapeBackSlash' 'escapeQuotesSimples' mainPath}}')"{{/if}}>
1212
{{#if folder}}
1313
<div class="v-folder item-image">
14-
{{#each images}}
15-
<div class="fi-sha-{{sha}} folder-images">
16-
<img src="{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}">
17-
</div>
18-
{{/each}}
14+
{{#if poster}}
15+
<div class="pi-sha-{{poster.sha}} folder-poster" style="background-image: url({{poster.path}})"></div>
16+
{{else}}
17+
{{#each images}}
18+
<div class="fi-sha-{{sha}} folder-images">
19+
<img src="{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}">
20+
</div>
21+
{{/each}}
22+
{{/if}}
1923
</div>
2024
{{else}}
2125
<div class="v-img">

themes/material-design/actions.css

+23-9
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@
415415
overflow: hidden;
416416
white-space: nowrap;
417417
word-wrap: normal;
418+
position: relative;
418419
}
419420

420421
.menu-simple-element i
@@ -458,17 +459,30 @@
458459

459460
.menu-simple-element.s
460461
{
461-
background-color: rgba(0, 0, 0, 0.07);
462+
background-color: var(--md-sys-color-secondary-container);
462463
}
463464

464-
.menu-simple:hover .menu-simple-element.s
465+
.menu-simple-element:before
465466
{
466-
background-color: rgba(0, 0, 0, 0);
467+
content: '';
468+
position: absolute;
469+
bottom: 0;
470+
left: 0;
471+
width: 100%;
472+
height: 100%;
473+
background-color: transparent;
474+
transition: 0.2s;
475+
z-index: 0;
467476
}
468477

469-
.menu-simple-element:hover
478+
.menu-simple-element:hover:before
470479
{
471-
background-color: rgba(0, 0, 0, 0.07) !important;
480+
background-color: var(--md-sys-color-on-surface-variant-2);
481+
}
482+
483+
.menu-simple-element:active:before
484+
{
485+
background-color: var(--md-sys-color-on-surface-variant-4);
472486
}
473487

474488
.menu-simple-element-image
@@ -534,15 +548,15 @@
534548
height: 32px;
535549
padding: 0px 24px;
536550
line-height: 32px;
537-
transition: 0.2s;
551+
transition: background-color 0.2s;
538552
}
539553

540554
.menu-simple-text, .menu-simple-button
541555
{
542556
height: 52px;
543557
padding: 0px 24px;
544558
line-height: 52px;
545-
transition: 0.2s;
559+
transition: background-color 0.2s;
546560
}
547561

548562
.menu-simple-text .switch
@@ -1043,15 +1057,15 @@
10431057
{
10441058
min-height: 64px;
10451059
padding: 0px 24px 15px 24px;
1046-
transition: 0.2s;
1060+
transition: background-color 0.2s;
10471061
box-sizing: border-box;
10481062
}
10491063

10501064
.simple-slider-text
10511065
{
10521066
min-height: 32px;
10531067
line-height: 32px;
1054-
transition: 0.2s;
1068+
transition: background-color 0.2s;
10551069
margin-bottom: 15px;
10561070
}
10571071

themes/material-design/theme.css

+46
Original file line numberDiff line numberDiff line change
@@ -1326,6 +1326,28 @@ body .preload
13261326
animation-fill-mode: forwards;
13271327
}
13281328

1329+
.content-view-module .folder-poster
1330+
{
1331+
height: calc(100% - 8px);
1332+
width: calc(100% - 8px);
1333+
position: absolute;
1334+
top: 4px;
1335+
left: 4px;
1336+
background-position: center;
1337+
border-radius: 10px;
1338+
background-repeat: no-repeat;
1339+
background-size: cover;
1340+
/*background-size: contain;
1341+
background-color: var(--md-sys-color-background);*/
1342+
}
1343+
1344+
.content-view-module .folder-poster.a
1345+
{
1346+
animation-name: show-in;
1347+
animation-duration: 0.2s;
1348+
animation-fill-mode: forwards;
1349+
}
1350+
13291351
/* Continue reading */
13301352

13311353
.continue-reading
@@ -1343,6 +1365,30 @@ body .preload
13431365
transform: scale(1.005);
13441366
}
13451367

1368+
.continue-reading:before
1369+
{
1370+
content: '';
1371+
position: absolute;
1372+
bottom: 0;
1373+
left: 0;
1374+
width: 100%;
1375+
height: 100%;
1376+
background-color: transparent;
1377+
transition: 0.2s;
1378+
z-index: 1;
1379+
border-radius: 10px;
1380+
}
1381+
1382+
.continue-reading:hover:before
1383+
{
1384+
background-color: var(--md-sys-color-on-surface-variant-2);
1385+
}
1386+
1387+
.continue-reading:active:before
1388+
{
1389+
background-color: var(--md-sys-color-on-surface-variant-4);
1390+
}
1391+
13461392
.continue-reading:after
13471393
{
13481394
content: '';

0 commit comments

Comments
 (0)