Skip to content

Commit 9edd70e

Browse files
committed
New: Master folder support from settings
1 parent 04b1caa commit 9edd70e

13 files changed

+266
-26
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1515
- Improve the detection of the type of compressed files if the file extension is not correct [`b39605c`](https://github.com/ollm/OpenComic/commit/b39605c5d5ab72742cf32f14a23004976cccec7c)
1616
- Option to start OpenComic in startup (Windows and macOS only) [`7b9b8ec`](https://github.com/ollm/OpenComic/commit/7b9b8ec4457445ad9bb3a761face8403ff507b7f)
1717
- Buttons in library to go next and prev chapter [`c41ecde`](https://github.com/ollm/OpenComic/commit/c41ecde33a3b0b2361b9ccdcbec92d848b48077d)
18-
- Adjust the brightness, saturation, contrast, sepia and colorize black and white images
18+
- Adjust the brightness, saturation, contrast, sepia and colorize black and white images [`04b1caa`](https://github.com/ollm/OpenComic/commit/04b1caa5d28a468df6e94893bd943518da762030)
19+
- Master folder support from settings
1920

2021
##### 🐛 Bug Fixes
2122

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
- 🖼 Support this image formats: `JPG`, `PNG`, `APNG`, `AVIF`, `WEBP`, `GIF`, `SVG`, `BMP`, `ICO`
3232
- 🗄 Support this compressed formats: `PDF`, `RAR`, `ZIP`, `7Z`, `TAR`, `CBR`, `CBZ`, `CB7`, `CBT`
33+
- 📁 Master folder support
3334
- 🇯🇵 Manga read mode
3435
- 🇰🇷 Webtoon read mode
3536
- 📖 Double page view

languages/en.json

+5
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@
130130
},
131131
"settings": {
132132
"general": "General",
133+
"masterFolders": {
134+
"main": "Master folders",
135+
"folder": "Folder",
136+
"noFolders": "No folders"
137+
},
133138
"reading": {
134139
"main": "Reading preferences",
135140
"maxMargin": "Maximum horizontal and vertical margin",

scripts/dom.js

+44-20
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,6 @@ async function loadFilesIndexPage(file, animation, path, keepScroll, mainPath)
246246
handlebarsContext.comics = pathFiles;
247247

248248
// Comic reading progress
249-
let comic = false, _comics = storage.get('comics');
250-
251-
for(let i in _comics)
252-
{
253-
if(_comics[i].path == mainPath)
254-
{
255-
comic = _comics[i];
256-
break;
257-
}
258-
}
259-
260249
let readingProgress = storage.get('readingProgress');
261250

262251
if(readingProgress[mainPath] && readingProgress[mainPath].lastReading > 0)
@@ -366,22 +355,56 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
366355
sortInvert = !sortInvert;
367356
}
368357

369-
var comicsStorage = storage.get('comics');
370-
var comics = [];
358+
let comics = [];
359+
360+
// Get comics in master folders
361+
let masterFolders = storage.get('masterFolders');
362+
let pathInMasterFolder = {};
363+
364+
if(!isEmpty(masterFolders))
365+
{
366+
for(let key in masterFolders)
367+
{
368+
let file = fileManager.file(masterFolders[key]);
369+
let files = await file.readDir();
370+
371+
for(let i = 0, len = files.length; i < len; i++)
372+
{
373+
let folder = files[i];
374+
375+
if((folder.folder || folder.compressed) && !pathInMasterFolder[folder.path])
376+
{
377+
comics.push({
378+
name: folder.name,
379+
path: folder.path,
380+
added: Math.round(fs.statSync(folder.path).mtimeMs / 1000),
381+
folder: true,
382+
compressed: folder.compressed,
383+
fromMasterFolder: true,
384+
});
385+
386+
pathInMasterFolder[folder.path] = true;
387+
}
388+
}
389+
}
390+
}
391+
392+
// Get comics in library
393+
let comicsStorage = storage.get('comics');
371394

372395
if(!isEmpty(comicsStorage))
373396
{
374397
for(let key in comicsStorage)
375398
{
376-
if(fs.existsSync(comicsStorage[key].path))
377-
{
399+
if(!pathInMasterFolder[comicsStorage[key].path] && fs.existsSync(comicsStorage[key].path))
378400
comics.push(comicsStorage[key]);
379-
}
380-
else
381-
{
382-
//console.log(comicsStorage[key]);
383-
}
384401
}
402+
}
403+
404+
if(comics.length > 0)
405+
{
406+
// Comic reading progress
407+
let readingProgress = storage.get('readingProgress');
385408

386409
for(let key in comics)
387410
{
@@ -391,6 +414,7 @@ async function loadIndexPage(animation = true, path = false, content = false, ke
391414
comics[key].poster = images.poster;
392415
comics[key].images = images.images;
393416
comics[key].mainPath = config.showFullPathLibrary ? p.parse(comics[key].path).root : comics[key].path;
417+
comics[key].readingProgress = readingProgress[comics[key].path] || {};
394418
}
395419

396420
comics.sort(function (a, b) {

scripts/settings.js

+64
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,68 @@ function start()
33
events.events();
44

55
generateShortcutsTable();
6+
7+
updateMasterFolders();
8+
}
9+
10+
function removeMasterFolder(key)
11+
{
12+
let masterFolders = storage.get('masterFolders');
13+
14+
if(masterFolders[key])
15+
{
16+
masterFolders.splice(key, 1);
17+
storage.set('masterFolders', masterFolders);
18+
19+
updateMasterFolders();
20+
}
21+
}
22+
23+
function addMasterFolder()
24+
{
25+
let dialog = electronRemote.dialog;
26+
27+
dialog.showOpenDialog({properties: ['openDirectory'], filters: [{name: language.settings.masterFolders.folder}]}).then(async function (files) {
28+
29+
if(files.filePaths && files.filePaths[0])
30+
{
31+
let folder = files.filePaths[0];
32+
let masterFolders = storage.get('masterFolders');
33+
34+
if(!inArray(folder, masterFolders))
35+
{
36+
masterFolders.push(folder);
37+
storage.set('masterFolders', masterFolders);
38+
39+
updateMasterFolders();
40+
}
41+
}
42+
43+
});
44+
}
45+
46+
function updateMasterFolders()
47+
{
48+
let masterFolders = storage.get('masterFolders');
49+
handlebarsContext.masterFolders = masterFolders;
50+
51+
let contentRight = template._contentRight();
52+
53+
let empty = contentRight.querySelector('.settings-master-folders-empty');
54+
let list = contentRight.querySelector('.settings-master-folders-list');
55+
56+
if(masterFolders.length)
57+
{
58+
empty.style.display = 'none';
59+
list.style.display = '';
60+
}
61+
else
62+
{
63+
empty.style.display = '';
64+
list.style.display = 'none';
65+
}
66+
67+
list.innerHTML = template.load('settings.content.right.master.folders.list.html');
668
}
769

870
function generateShortcutsTable(highlightItem = false)
@@ -220,4 +282,6 @@ module.exports = {
220282
changeButton: changeButton,
221283
removeButton: removeButton,
222284
resoreShortcuts: resoreShortcuts,
285+
removeMasterFolder: removeMasterFolder,
286+
addMasterFolder: addMasterFolder,
223287
};

scripts/storage.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var changes = 48; // Update this if readingPagesConfig is updated
1+
var changes = 49; // Update this if readingPagesConfig is updated
22

33
var readingPagesConfig = {
44
readingConfigName: '',
@@ -108,9 +108,9 @@ var storageDefault = {
108108
path: 'Files path',
109109
added: 0,
110110
compressed: false,
111-
bookmark: false,
111+
bookmark: false, // I think this is no longer used now, but I not sure
112112
folder: true,
113-
readingProgress: {
113+
readingProgress: { // I think this is no longer used now, but I not sure
114114
path: 'Path',
115115
lastReading: 0,
116116
progress: 0,
@@ -130,6 +130,9 @@ var storageDefault = {
130130
progress: 0,
131131
},
132132
}],
133+
masterFolders: [
134+
'',
135+
],
133136
bookmarks: {
134137
wildcard: [{
135138
index: 0,

templates/index.content.right.list.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{{/if}}
99
<div class="content-view-list">
1010
{{#each comics}}
11-
<div class="medium-list body-medium{{#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}}" oncontextmenu="dom.comicContextMenu('{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}', {{#if @root.comicsIndex}}true{{else}}false{{/if}}, {{#if folder}}true{{else}}false{{/if}}, fromGamepad)">
11+
<div class="medium-list body-medium{{#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}}" oncontextmenu="dom.comicContextMenu('{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}', {{#if @root.comicsIndex}}{{#unless fromMasterFolder}}true{{else}}false{{/unless}}{{else}}false{{/if}}, {{#if folder}}true{{else}}false{{/if}}, fromGamepad)">
1212
<div class="{{#if folder}}icon-24 material-icon{{else}}medium-list-image{{/if}} item-image"{{#unless folder}} style="background-image: url({{chain 'escapeBackSlash' 'escapeQuotesSimples' thumbnail}});"{{/unless}}>{{#if folder}}folder{{/if}}</div>
1313
<div class="medium-list-text">{{name}}</div>
1414
</div>

templates/index.content.right.module.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{{/if}}
99
<div class="content-view-module">
1010
{{#each comics}}
11-
<div class="sha-{{sha}} 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}}" oncontextmenu="dom.comicContextMenu('{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}', {{#if @root.comicsIndex}}true{{else}}false{{/if}}, {{#if folder}}true{{else}}false{{/if}}, fromGamepad)">
11+
<div class="sha-{{sha}} 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}}" oncontextmenu="dom.comicContextMenu('{{chain 'escapeBackSlash' 'escapeQuotesSimples' path}}', {{#if @root.comicsIndex}}{{#unless fromMasterFolder}}true{{else}}false{{/unless}}{{else}}false{{/if}}, {{#if folder}}true{{else}}false{{/if}}, fromGamepad)">
1212
{{#if folder}}
1313
<div class="v-folder item-image">
1414
{{#if poster}}

templates/settings.content.right.html

+17
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ <h1 class="display-medium">{{language.global.settings}}</h1>
1616
<div class="tabs-content">
1717
<div class="tabs-general active">
1818

19+
<h2 class="headline-small">{{language.settings.masterFolders.main}}</h2>
20+
21+
<div class="settings-master-folders">
22+
23+
<div class="menu-simple-text menu-grey settings-master-folders-empty"{{#if masterFolders}} style="display: none;"{{/if}}>
24+
<span>{{language.settings.masterFolders.noFolders}}</span>
25+
</div>
26+
27+
<div class="settings-master-folders-list"{{#unless masterFolders}} style="display: none;"{{/unless}}>
28+
</div>
29+
30+
<div class="simple-button filled-tonal gamepad-item" onclick="settings.addMasterFolder();">
31+
<div class="touch-effect"><i class="icon-24 material-icon">add</i>{{language.menu.file.addFolder}}</div>
32+
</div>
33+
<cb></cb>
34+
</div>
35+
1936
<h2 class="headline-small">{{language.settings.reading.main}}</h2>
2037

2138
<div class="menu-simple-text gamepad-item">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{{#each masterFolders}}
2+
<div class="chip chip-icon-right label-large" onclick="electron.shell.openPath('{{@this}}');"><div></div>{{@this}}<i class="icon-18 material-icon right gamepad-item" onclick="event.stopPropagation(); settings.removeMasterFolder({{@key}});">close</i></div>
3+
{{/each}}

themes/material-design/actions.css

+84
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,11 @@
728728
position: relative;
729729
}
730730

731+
.menu-grey
732+
{
733+
color: color-mix(in srgb, var(--md-sys-color-on-surface), transparent 50%);
734+
}
735+
731736
.menu-simple-text .switch
732737
{
733738
margin-top: 16px;
@@ -2303,4 +2308,83 @@ table tbody td.lh0
23032308
{
23042309
transform: rotate(180deg);
23052310
color: var(--md-sys-color-primary);
2311+
}
2312+
2313+
/* Chip */
2314+
2315+
.chip
2316+
{
2317+
border-radius: 8px;
2318+
border: 1px solid var(--md-sys-color-outline);
2319+
padding: 5px 12px;
2320+
margin: 0px 8px 8px 0px;
2321+
background-color: var(--md-sys-color-surface-container-low);
2322+
color: var(--md-sys-color-on-surface);
2323+
display: inline-block;
2324+
transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
2325+
box-sizing: border-box;
2326+
overflow: hidden;
2327+
position: relative;
2328+
cursor: pointer;
2329+
}
2330+
2331+
.chip > div
2332+
{
2333+
content: '';
2334+
position: absolute;
2335+
bottom: 0;
2336+
left: 0;
2337+
width: 100%;
2338+
height: 100%;
2339+
border-radius: 4px 4px 0px 0px;
2340+
z-index: 1;
2341+
transition: 0.2s background-color;
2342+
background-color: transparent;
2343+
}
2344+
2345+
.chip > div:hover
2346+
{
2347+
background-color: var(--md-sys-color-on-surface-variant-2);
2348+
}
2349+
2350+
.chip > div:active,
2351+
.chip.gamepad-highlight > div
2352+
{
2353+
background-color: var(--md-sys-color-on-surface-variant-4);
2354+
}
2355+
2356+
.chip.active
2357+
{
2358+
background-color: var(--md-sys-color-primary);
2359+
color: var(--md-sys-color-on-primary);
2360+
}
2361+
2362+
.chip-icon-right
2363+
{
2364+
padding-right: 0px;
2365+
}
2366+
2367+
.chip i
2368+
{
2369+
margin: -2px 5px;
2370+
}
2371+
2372+
.chip i.right
2373+
{
2374+
float: right;
2375+
cursor: pointer;
2376+
height: 24px;
2377+
width: 24px;
2378+
border-radius: 24px;
2379+
line-height: 24px;
2380+
text-align: center;
2381+
transition: 0.2s background-color;
2382+
position: relative;
2383+
z-index: 2;
2384+
}
2385+
2386+
.chip i.right:hover,
2387+
.chip i.gamepad-highlight
2388+
{
2389+
background-color: var(--md-sys-color-on-surface-variant-2);
23062390
}

themes/material-design/settings.css

+22
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,26 @@
4242
{
4343
float: right;
4444
margin: 32px 24px 6px 0px;
45+
}
46+
47+
.settings-master-folders
48+
{
49+
padding: 0px 24px;
50+
}
51+
52+
.settings-master-folders
53+
{
54+
55+
}
56+
57+
.settings-master-folders-empty
58+
{
59+
padding: 0px;
60+
margin-bottom: 10px;
61+
}
62+
63+
.settings-master-folders-list
64+
{
65+
margin: 19px 0px 13px;
66+
display: flex;
4567
}

0 commit comments

Comments
 (0)