فهرست منبع

Добавил ленивую обработку книги после загрузки

Book Pauk 6 سال پیش
والد
کامیت
61d1c47655

+ 11 - 0
client/components/Reader/SettingsPage/SettingsPage.vue

@@ -187,6 +187,17 @@
                                     <el-checkbox v-model="allowUrlParamBookPos">Добавлять параметр "__p"</el-checkbox>
                                     <el-checkbox v-model="allowUrlParamBookPos">Добавлять параметр "__p"</el-checkbox>
                                 </el-tooltip>
                                 </el-tooltip>
                             </el-form-item>
                             </el-form-item>
+                            <el-form-item label="Парсинг">
+                                <el-tooltip :open-delay="500" effect="light">
+                                    <template slot="content">
+                                        Включение этой опции позволяет делать предварительную<br>
+                                        обработку текста в ленивом режиме сразу после загрузки<br>
+                                        книги. Это может ускорить отзывчивость читалки, но<br>
+                                        нагружает процессор каждый раз при открытии книги.
+                                    </template>
+                                    <el-checkbox v-model="lazyParseEnabled">Предварительная обработка текста</el-checkbox>
+                                </el-tooltip>
+                            </el-form-item>
 
 
                         </el-form>
                         </el-form>
                         
                         

+ 42 - 4
client/components/Reader/TextPage/TextPage.vue

@@ -308,10 +308,15 @@ class TextPage extends Vue {
 
 
         if (this.lastBook) {
         if (this.lastBook) {
             (async() => {
             (async() => {
+                //подождем ленивый парсинг
+                this.stopLazyParse = true;
+                while (this.doingLazyParse) await sleep(10);
+
                 const isParsed = await bookManager.hasBookParsed(this.lastBook);
                 const isParsed = await bookManager.hasBookParsed(this.lastBook);
                 if (!isParsed) {
                 if (!isParsed) {
                     return;
                     return;
                 }
                 }
+
                 this.book = await bookManager.getBook(this.lastBook);
                 this.book = await bookManager.getBook(this.lastBook);
                 this.meta = bookManager.metaOnly(this.book);
                 this.meta = bookManager.metaOnly(this.book);
                 this.fb2 = this.meta.fb2;
                 this.fb2 = this.meta.fb2;
@@ -332,6 +337,8 @@ class TextPage extends Vue {
 
 
                 this.calcPropsAndLoadFonts();
                 this.calcPropsAndLoadFonts();
                 this.refreshTime();
                 this.refreshTime();
+                if (this.lazyParseEnabled)
+                    this.lazyParsePara();
             })();
             })();
         }
         }
     }
     }
@@ -460,7 +467,7 @@ class TextPage extends Vue {
                 lineText += part.text;
                 lineText += part.text;
                 center = center || part.style.center;
                 center = center || part.style.center;
                 if (part.style.center)
                 if (part.style.center)
-                    centerStyle = part.style.center;
+                    centerStyle = part.style;
             }
             }
 
 
             let filled = false;
             let filled = false;
@@ -491,7 +498,7 @@ class TextPage extends Vue {
             // просто выводим текст
             // просто выводим текст
             if (!filled) {
             if (!filled) {
                 let x = indent;
                 let x = indent;
-                x = (center ? this.indent + (this.w - this.measureText(lineText, centerStyle))/2 : x);
+                x = (center ? this.indentLR + (this.w - this.measureText(lineText, centerStyle))/2 : x);
                 for (const part of line.parts) {
                 for (const part of line.parts) {
                     let text = part.text;
                     let text = part.text;
                     const font = this.fontByStyle(part.style);
                     const font = this.fontByStyle(part.style);
@@ -506,7 +513,7 @@ class TextPage extends Vue {
         return out;
         return out;
     }
     }
 
 
-    drawStatusBar() {
+    drawStatusBar(message) {
         if (this.w < minLayoutWidth) {
         if (this.w < minLayoutWidth) {
             this.statusBar = null;
             this.statusBar = null;
             return;
             return;
@@ -519,7 +526,8 @@ class TextPage extends Vue {
                 i--;
                 i--;
             i = (i > lines.length - 1 ? lines.length - 1 : i);
             i = (i > lines.length - 1 ? lines.length - 1 : i);
             if (i >= 0) {
             if (i >= 0) {
-                let message = this.statusBarMessage;
+                if (!message)
+                    message = this.statusBarMessage;
                 if (!message)
                 if (!message)
                     message = this.title;
                     message = this.title;
                 this.statusBar = this.drawHelper.drawStatusBar(this.statusBarTop, this.statusBarHeight, 
                 this.statusBar = this.drawHelper.drawStatusBar(this.statusBarTop, this.statusBarHeight, 
@@ -542,6 +550,36 @@ class TextPage extends Vue {
         this.drawStatusBar();
         this.drawStatusBar();
     }
     }
 
 
+    async lazyParsePara() {
+        if (!this.parsed || this.doingLazyParse)
+            return;
+        this.doingLazyParse = true;
+        let j = 0;
+        let k = 0;
+        let prevPerc = 0;
+        this.stopLazyParse = false;
+        for (let i = 0; i < this.parsed.para.length; i++) {
+            j++;
+            if (j > 1) {
+                await sleep(1);
+                j = 0;
+            }
+            if (this.stopLazyParse)
+                break;
+            this.parsed.parsePara(i);
+            k++;
+            if (k > 100) {
+                let perc = Math.round(i/this.parsed.para.length*100);
+                if (perc != prevPerc)
+                    this.drawStatusBar(`Обработка текста ${perc}%`);
+                prevPerc = perc;
+                k = 0;
+            }
+        }
+        this.drawStatusBar();
+        this.doingLazyParse = false;
+    }
+
     async refreshTime() {
     async refreshTime() {
         if (!this.timeRefreshing) {
         if (!this.timeRefreshing) {
             this.timeRefreshing = true;
             this.timeRefreshing = true;

+ 1 - 0
client/store/modules/reader.js

@@ -46,6 +46,7 @@ const settingDefaults = {
         pageChangeTransitionSpeed: 50, //0-100%
         pageChangeTransitionSpeed: 50, //0-100%
 
 
         allowUrlParamBookPos: false,
         allowUrlParamBookPos: false,
+        lazyParseEnabled: false,
         fontShifts: {},
         fontShifts: {},
 };
 };