From e855b5cd26be4bee9b440166cb1ab742b364ae3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Wed, 6 Jan 2021 17:58:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=A4=9A=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/css/app.css | 2 +- src/css/app.scss | 48 +++++++++++++++++------------- src/index.html | 18 +++++++++--- src/js/app.js | 32 +++++++++++++++----- src/main.js | 2 +- src/tools/init.js | 6 ++-- src/tools/socket.js | 71 ++++++++++++++++++++++++++++----------------- 7 files changed, 116 insertions(+), 63 deletions(-) diff --git a/src/css/app.css b/src/css/app.css index 63c1f66..17edc4e 100644 --- a/src/css/app.css +++ b/src/css/app.css @@ -1 +1 @@ -html{font-size:12.8px;width:100%;height:100vh}body{overflow:hidden;display:flex;flex-direction:column;width:100%;height:100%;line-height:1.25;font-size:14px;color:var(--color-dark-1);background:rgba(255,255,255,0.3)}.app-drag{-webkit-app-region:drag;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.app-nodrag{-webkit-app-region:no-drag}.app{position:relative;display:flex;height:100%}.app .category{width:200px;height:100%;background:#fff}.app .category .item{display:flex;justify-content:space-between;align-items:center;height:54px;padding:8px;border-bottom:1px solid var(--color-plain-1);background:#fff;transition:background 0.2s ease-in-out, color 0.2s ease-in-out;cursor:pointer}.app .category .item strong{max-width:150px}.app .category .item .num{display:flex;justify-content:center;align-items:center;min-width:16px;height:16px;padding:2px;line-height:1;border-radius:50%;font-size:12px;background:var(--color-grey-1);color:#fff}.app .category .item:last-child{border-bottom:0}.app .category .item:hover{color:var(--color-blue-1);background:var(--color-plain-1)}.app .category .item.active{color:var(--color-plain-1);background:var(--color-blue-1)}.app .category .item.active .num{background:#fff;color:var(--color-blue-1)}.app .detail{position:relative;flex:1;height:100%;border-left:1px solid var(--color-plain-2);background:rgba(255,255,255,0.5)}.app .detail .title{display:flex;justify-content:space-between;align-items:center;width:100%;height:35px;padding:0 16px;font-size:16px;font-weight:bold}.app .detail .title span{display:inline-flex}.app .detail .title wc-button{margin:0 6px}.app .detail .card{width:96%;padding:12px 12px 16px;margin:12px 2% 24px;border:0;background:#fff;box-shadow:0 0 8px rgba(0,0,0,0.075)}.app .detail .card legend{-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:#64b5f6}.app.loading::after{display:flex;justify-content:center;align-items:center;position:absolute;left:0;top:0;z-index:999;width:100%;height:100%;content:'🌑';background:rgba(255,255,255,0.01);-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px);color:var(--color-orange-1);font-size:50px;-webkit-animation:loading 1s infinite;animation:loading 1s infinite}.app .drag-mask{display:flex;align-items:center;position:fixed;left:0;top:0;z-index:9999;width:100%;height:100%;background:linear-gradient(to right, transparent, transparent 200px, #fff3e3 200px)}.app .drag-mask::after{font-size:46px;text-indent:300px;content:'Drop epub file here...';color:var(--color-grey-1)}@-webkit-keyframes loading{1%,100%{content:'🌑'}12.5%{content:'🌒'}25%{content:'🌓'}37.5%{content:'🌔'}50%{content:'🌕'}62.5%{content:'🌖'}75%{content:'🌗'}87.5%{content:'🌘'}}@keyframes loading{1%,100%{content:'🌑'}12.5%{content:'🌒'}25%{content:'🌓'}37.5%{content:'🌔'}50%{content:'🌕'}62.5%{content:'🌖'}75%{content:'🌗'}87.5%{content:'🌘'}} +html{font-size:12.8px;width:100%;height:100vh}body{overflow:hidden;display:flex;flex-direction:column;width:100%;height:100%;line-height:1.25;font-size:14px;color:var(--color-dark-1);background:rgba(255,255,255,0.3)}.app-drag{-webkit-app-region:drag;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.app-nodrag{-webkit-app-region:no-drag}.app{position:relative;display:flex;height:100%}.app .category{width:200px;height:100%;background:#fff}.app .category .item{display:flex;justify-content:space-between;align-items:center;height:54px;padding:8px;border-bottom:1px solid var(--color-plain-1);background:#fff;transition:background 0.2s ease-in-out, color 0.2s ease-in-out;cursor:pointer}.app .category .item strong{max-width:150px}.app .category .item .num{display:flex;justify-content:center;align-items:center;min-width:16px;height:16px;padding:2px;line-height:1;border-radius:50%;font-size:12px;background:var(--color-grey-1);color:#fff}.app .category .item:last-child{border-bottom:0}.app .category .item:hover{color:var(--color-blue-1);background:var(--color-plain-1)}.app .category .item.active{color:var(--color-plain-1);background:var(--color-blue-1)}.app .category .item.active .num{background:#fff;color:var(--color-blue-1)}.app .detail{position:relative;flex:1;height:100%;border-left:1px solid var(--color-plain-2);background:rgba(255,255,255,0.5)}.app .detail .title{display:flex;justify-content:space-between;align-items:center;width:100%;height:35px;padding:0 16px;font-size:16px;font-weight:bold}.app .detail .title span{display:inline-flex}.app .detail .title wc-button{margin:0 6px}.app .detail .card{width:96%;padding:12px 12px 16px;margin:12px 2% 24px;border:0;background:#fff;box-shadow:0 0 8px rgba(0,0,0,0.075)}.app .detail .card legend{-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:#64b5f6}.app .drag-mask{display:flex;align-items:center;position:fixed;left:0;top:0;z-index:9999;width:100%;height:100%;background:linear-gradient(to right, transparent, transparent 200px, #fff3e3 200px)}.app .drag-mask::after{font-size:46px;text-indent:300px;content:'Drop epub file here...';color:var(--color-grey-1)}.app .book-loading{display:flex;align-items:center;justify-content:center;position:fixed;left:0;top:0;z-index:9999;width:100%;height:100%;font-size:20px;background:rgba(255,255,255,0.01);-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px)}.app .book-loading .loading{display:flex;flex-direction:column;align-items:center;justify-content:center}.app .book-loading .loading::before{content:'🌑';font-size:36px;-webkit-animation:loading 1s infinite;animation:loading 1s infinite}@-webkit-keyframes loading{1%,100%{content:'🌑'}12.5%{content:'🌒'}25%{content:'🌓'}37.5%{content:'🌔'}50%{content:'🌕'}62.5%{content:'🌖'}75%{content:'🌗'}87.5%{content:'🌘'}}@keyframes loading{1%,100%{content:'🌑'}12.5%{content:'🌒'}25%{content:'🌓'}37.5%{content:'🌔'}50%{content:'🌕'}62.5%{content:'🌖'}75%{content:'🌗'}87.5%{content:'🌘'}} diff --git a/src/css/app.scss b/src/css/app.scss index 97d434e..2e9e38e 100644 --- a/src/css/app.scss +++ b/src/css/app.scss @@ -131,26 +131,6 @@ body { } } - &.loading { - &::after { - display: flex; - justify-content: center; - align-items: center; - position: absolute; - left: 0; - top: 0; - z-index: 999; - width: 100%; - height: 100%; - content: '🌑'; - background: rgba(255, 255, 255, 0.01); - backdrop-filter: blur(2px); - color: var(--color-orange-1); - font-size: 50px; - animation: loading 1s infinite; - } - } - .drag-mask { display: flex; align-items: center; @@ -174,6 +154,34 @@ body { color: var(--color-grey-1); } } + + .book-loading { + display: flex; + align-items: center; + justify-content: center; + position: fixed; + left: 0; + top: 0; + z-index: 9999; + width: 100%; + height: 100%; + font-size: 20px; + background: rgba(255, 255, 255, 0.01); + backdrop-filter: blur(2px); + + .loading { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + + &::before { + content: '🌑'; + font-size: 36px; + animation: loading 1s infinite; + } + } + } } @keyframes loading { diff --git a/src/index.html b/src/index.html index 3391aa5..6fac36e 100644 --- a/src/index.html +++ b/src/index.html @@ -11,13 +11,13 @@ -
+
+ :class="{active: curr === it.name}" + :for="it in cates"> @@ -27,7 +27,10 @@
- + + + {{it.title}} +
@@ -35,6 +38,13 @@
+
+
+ å…ą {{load.num}} 朎äđĶ + å―“å‰æ­ĢåœĻč§Ģ析įŽŽ {{load.curr}} 朎 +
+
+
diff --git a/src/js/app.js b/src/js/app.js index e2e7370..4c15159 100644 --- a/src/js/app.js +++ b/src/js/app.js @@ -29,14 +29,14 @@ Anot({ $id: 'app', state: { input: '', - curr: 1, - list: [{ id: 1, name: 'éŧ˜čŪĪ分įąŧ', num: 12 }], - $dict: {}, + curr: 'éŧ˜čŪĪ分įąŧ', + cates: [{ name: 'éŧ˜čŪĪ分įąŧ', num: 12 }], + books: [], loading: false, isDragIn: false, - preferences: { - tab: 1, - notify: Anot.ls('notify') === '1' + load: { + num: 0, + curr: 0 } }, @@ -65,11 +65,27 @@ Anot({ .filter(it => it.type === 'application/epub+zip') .map(it => { let { name, path } = it + name = name.replace(/\.epub$/, '') return { name, path } }) - let res = app.dispatch('parse-book', files) - console.log(res) + this.load.num = files.length + this.load.curr = 0 + this.loading = true + + console.time(1) + while (this.load.curr < this.load.num) { + this.load.curr++ + let book = files.pop() + let res = app.dispatch('parse-book', { book, cate: this.burr }) + console.log(res) + if (res) { + this.books.push(res) + } + } + console.timeEnd(1) + + this.loading = false }) }, methods: {} diff --git a/src/main.js b/src/main.js index 01fe230..5fb2ee4 100644 --- a/src/main.js +++ b/src/main.js @@ -44,7 +44,7 @@ protocol.registerSchemesAsPrivileged([ /* ----------------------------------------------------- */ -app.dock.hide() +// app.dock.hide() // 初始化嚔į”Ļ app.once('ready', () => { diff --git a/src/tools/init.js b/src/tools/init.js index e5dbcc4..c235dce 100644 --- a/src/tools/init.js +++ b/src/tools/init.js @@ -23,10 +23,10 @@ PATH_SET = null /* ********** äŋŪåĪįŽŊåĒƒå˜é‡ end *********** */ -const INIT_FILE = path.join(HOME, 'app.cache') +const DB_FILE = path.join(HOME, 'app.cache') const CACHE_DIR = path.join(HOME, 'book_cache') -if (!fs.exists(INIT_FILE)) { - fs.echo('[]', INIT_FILE) +if (!fs.exists(DB_FILE)) { + fs.echo('{}', DB_FILE) fs.mkdir(CACHE_DIR) } diff --git a/src/tools/socket.js b/src/tools/socket.js index 5977164..6cd0b8f 100644 --- a/src/tools/socket.js +++ b/src/tools/socket.js @@ -10,6 +10,7 @@ const path = require('path') const Epub = require('epub') const HOME = path.resolve(app.getPath('userData')) +const DB_FILE = path.join(HOME, 'app.cache') const CACHE_DIR = path.join(HOME, 'book_cache') function fetch(url) { @@ -45,29 +46,36 @@ module.exports = function(app) { break case 'parse-book': - let books = conn.data - let eb = new Epub(books[0].path) - - function saveImage(id, name) { - return new Promise(done => { - eb.getImage(id, (err, buf) => { - fs.echo(buf, path.resolve(CACHE_DIR, name)) - done() - }) - }) - } - - function saveHtml(id, name) { - return new Promise(done => { - eb.getChapter(id, (err, txt) => { - txt = (txt + '').replace(/<([\w\-]+)[^>]*?>/g, '<$1>') - fs.echo(txt, path.resolve(CACHE_DIR, name)) - done() - }) - }) - } + let { book, cate } = conn.data + let eb = new Epub(book.path) + let cache = JSON.parse(fs.cat(DB_FILE)) eb.on('end', async _ => { + let { title, cover } = eb.metadata + let dir = path.join(CACHE_DIR, title) + + function saveImage(id, name) { + return new Promise(done => { + eb.getImage(id, (err, buf) => { + fs.echo(buf, path.join(dir, name)) + done() + }) + }) + } + + function saveHtml(id, name) { + return new Promise(done => { + eb.getChapter(id, (err, txt) => { + // txt = (txt + '').replace( + // /<(?!img|image)([\w\-]+)[^>]*>/g, + // '<$1>' + // ) + fs.echo(txt, path.join(dir, name.replace('.xhtml', '.html'))) + done() + }) + }) + } + loop: for (let k in eb.manifest) { let it = eb.manifest[k] @@ -77,10 +85,7 @@ module.exports = function(app) { break case 'application/x-dtbncx+xml': - fs.echo( - JSON.stringify(eb.toc), - path.resolve(CACHE_DIR, it.href) - ) + fs.echo(JSON.stringify(eb.toc), path.join(dir, 'toc.json')) break case 'application/xhtml+xml': @@ -90,11 +95,25 @@ module.exports = function(app) { default: if (it['media-type'].startsWith('image')) { saveImage(it.id, it.href) + if (it.href.includes(cover)) { + cover = it.href + } } break } } - ev.returnValue = [eb.manifest, eb.flow] + + let info = { title, cover } + if (cache[cate]) { + if (!cache[cate].some(it => it.title === title)) { + cache[cate].push(info) + } else { + info = null + } + } else { + cache[cate] = [info] + } + ev.returnValue = info }) eb.parse()