Работа над BookUpdateChecker

This commit is contained in:
Book Pauk
2022-07-27 15:40:46 +07:00
parent a1fcb7597b
commit 7f17e7daed
6 changed files with 109 additions and 31 deletions

View File

@@ -310,6 +310,7 @@ class Reader {
dualPageMode = false; dualPageMode = false;
bucEnabled = false; bucEnabled = false;
bucSetOnNew = false;
created() { created() {
this.rstore = rstore; this.rstore = rstore;
@@ -359,8 +360,14 @@ class Reader {
} }
}, 200); }, 200);
this.debouncedRecentBooksPageUpdate = _.debounce(async() => {
if (this.recentBooksActive) {
await this.$refs.recentBooksPage.updateTableData();
}
}, 100);
this.recentItemKeys = []; this.recentItemKeys = [];
this.saveRecentChanges = _.debounce(async() => { this.debouncedSaveRecent = _.debounce(async() => {
let timer = setTimeout(() => { let timer = setTimeout(() => {
if (!this.offlineModeActive) if (!this.offlineModeActive)
this.$root.notify.error('Таймаут соединения'); this.$root.notify.error('Таймаут соединения');
@@ -435,7 +442,7 @@ class Reader {
//вечный цикл, запрашиваем периодически обновления //вечный цикл, запрашиваем периодически обновления
while (1) {// eslint-disable-line no-constant-condition while (1) {// eslint-disable-line no-constant-condition
await this.checkBuc(); await this.checkBuc();
await utils.sleep(70*60*1000); //каждые 70 минут await utils.sleep(/*70*60*1000*/10*1000); //каждые 70 минут
} }
//дальше хода нет //дальше хода нет
})(); })();
@@ -460,6 +467,7 @@ class Reader {
this.dualPageMode = settings.dualPageMode; this.dualPageMode = settings.dualPageMode;
this.userWallpapers = settings.userWallpapers; this.userWallpapers = settings.userWallpapers;
this.bucEnabled = settings.bucEnabled; this.bucEnabled = settings.bucEnabled;
this.bucSetOnNew = settings.bucSetOnNew;
this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys); this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
this.$root.readerActionByKeyEvent = (event) => { this.$root.readerActionByKeyEvent = (event) => {
@@ -595,7 +603,6 @@ class Reader {
await bookManager.recentSetItem(book); await bookManager.recentSetItem(book);
} }
} }
console.log('checkBuc finished', arr);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
@@ -731,14 +738,12 @@ console.log('checkBuc finished', arr);
} }
if (eventName == 'recent-changed') { if (eventName == 'recent-changed') {
if (this.recentBooksActive) { this.debouncedRecentBooksPageUpdate();
await this.$refs.recentBooksPage.updateTableData();
}
//сохранение в serverStorage //сохранение в serverStorage
if (value && this.recentItemKeys.indexOf(value) < 0) { if (value && this.recentItemKeys.indexOf(value) < 0) {
this.recentItemKeys.push(value); this.recentItemKeys.push(value);
this.saveRecentChanges(); this.debouncedSaveRecent();
} }
} }
} }
@@ -1307,9 +1312,13 @@ console.log('checkBuc finished', arr);
delete wasOpened.loadTime; delete wasOpened.loadTime;
// добавляем в историю // добавляем в историю
await bookManager.setRecentBook(Object.assign(wasOpened, addedBook)); const recentBook = await bookManager.setRecentBook(Object.assign(wasOpened, addedBook));
if (this.bucSetOnNew) {
await bookManager.setCheckBuc(recentBook, true);
}
this.mostRecentBook(); this.mostRecentBook();
this.addAction(wasOpened.bookPos); this.addAction(recentBook.bookPos);
this.updateRoute(true); this.updateRoute(true);
this.loaderActive = false; this.loaderActive = false;

View File

@@ -105,9 +105,13 @@
</div> </div>
<div class="row-part column justify-center items-stretch" style="width: 80px"> <div class="row-part column justify-center items-stretch" style="width: 80px">
<div class="col row justify-center items-center clickable" style="padding: 0 2px 0 2px" @click="loadBook(item)"> <div class="col row justify-center items-center clickable" style="padding: 0 2px 0 2px" @click="loadBook(item, bothBucEnabled && item.needBookUpdate)">
<div v-show="isLoadedCover(item.coverPageUrl)" style="height: 80px" v-html="getCoverHtml(item.coverPageUrl)" /> <div v-show="isLoadedCover(item.coverPageUrl)" style="height: 80px" v-html="getCoverHtml(item.coverPageUrl)" />
<q-icon v-show="!isLoadedCover(item.coverPageUrl)" name="la la-book" size="40px" style="color: #dddddd" /> <q-icon v-show="!isLoadedCover(item.coverPageUrl)" name="la la-book" size="40px" style="color: #dddddd" />
<div v-show="bothBucEnabled && item.needBookUpdate" style="position: absolute; z-index: 10;">
<q-icon name="la la-sync" size="60px" style="color: blue" />
</div>
</div> </div>
<div v-show="!showSameBook && item.group && item.group.length > 0" class="row justify-center" style="font-size: 70%"> <div v-show="!showSameBook && item.group && item.group.length > 0" class="row justify-center" style="font-size: 70%">
@@ -127,7 +131,7 @@
{{ item.desc.title }} {{ item.desc.title }}
</div> </div>
<div v-show="bothBucEnabled && item.needBookUpdate" style="font-size: 75%; color: blue"> <div v-show="bothBucEnabled && item.needBookUpdate" style="font-size: 75%; color: blue">
Старый размер: {{ item.bucSize }}, новый: {{ item.downloadSize }} Размер: {{ item.downloadSize }} &rarr; {{ item.bucSize }}, +{{ item.bucSize - item.downloadSize }}
</div> </div>
</div> </div>
@@ -172,7 +176,7 @@
class="col column justify-center" class="col column justify-center"
style="font-size: 75%; padding-left: 6px; border: 1px solid #cccccc; border-left: 0;" style="font-size: 75%; padding-left: 6px; border: 1px solid #cccccc; border-left: 0;"
> >
<div style="margin: 20px 0 0 5px"> <div style="margin: 25px 0 0 5px">
<a v-show="isUrl(item.url)" :href="item.url" target="_blank">Оригинал</a><br><br> <a v-show="isUrl(item.url)" :href="item.url" target="_blank">Оригинал</a><br><br>
<a :href="item.path" @click.prevent="downloadBook(item.path, item.fullTitle)">Скачать FB2</a> <a :href="item.path" @click.prevent="downloadBook(item.path, item.fullTitle)">Скачать FB2</a>
</div> </div>
@@ -206,7 +210,7 @@
<q-checkbox <q-checkbox
v-model="item.checkBuc" v-model="item.checkBuc"
size="xs" size="xs"
style="position: relative; top: -5px; left: -5px;" style="position: relative; top: -3px; left: -3px;"
@update:model-value="checkBucChange(item)" @update:model-value="checkBucChange(item)"
> >
<q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%"> <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
@@ -350,7 +354,7 @@ class RecentBooksPage {
let title = bt.bookTitle; let title = bt.bookTitle;
title = (title ? `"${title}"`: ''); title = (title ? `"${title}"`: '');
const author = (bt.author ? bt.author : (bt.bookTitle ? bt.bookTitle : (book.uploadFileName ? book.uploadFileName : book.url))); const author = (bt.author ? bt.author : (bt.bookTitle ? bt.bookTitle : (book.uploadFileName ? book.uploadFileName : book.url))) || '';
result.push({ result.push({
key: book.key, key: book.key,
@@ -397,12 +401,14 @@ class RecentBooksPage {
//фильтрация //фильтрация
const search = this.search; const search = this.search;
if (search) { if (search) {
const lowerSearch = search.toLowerCase();
result = result.filter(item => { result = result.filter(item => {
return !search || return !search ||
item.touchTime.includes(search) || item.touchTime.includes(search) ||
item.loadTime.includes(search) || item.loadTime.includes(search) ||
item.desc.title.toLowerCase().includes(search.toLowerCase()) || item.desc.title.toLowerCase().includes(lowerSearch) ||
item.desc.author.toLowerCase().includes(search.toLowerCase()) item.desc.author.toLowerCase().includes(lowerSearch)
}); });
} }
@@ -451,6 +457,9 @@ class RecentBooksPage {
if (book.active) if (book.active)
parents[book.sameBookKey].activeParent = true; parents[book.sameBookKey].activeParent = true;
book.showCheckBuc = false;
book.needBookUpdate = false;
groups[book.sameBookKey].push(book); groups[book.sameBookKey].push(book);
} }
} else { } else {
@@ -546,14 +555,14 @@ class RecentBooksPage {
this.$root.notify.info('Восстановлено из архива'); this.$root.notify.info('Восстановлено из архива');
} }
async loadBook(item) { async loadBook(item, force = false) {
//чтобы не обновлять лишний раз updateTableData //чтобы не обновлять лишний раз updateTableData
this.inited = false; this.inited = false;
if (item.deleted) if (item.deleted)
await this.handleRestore(item.key); await this.handleRestore(item.key);
this.$emit('load-book', {url: item.url, path: item.path}); this.$emit('load-book', {url: item.url, path: item.path, force});
this.close(); this.close();
} }
@@ -753,8 +762,7 @@ class RecentBooksPage {
async checkBucChange(item) { async checkBucChange(item) {
const book = await bookManager.getRecentBook(item); const book = await bookManager.getRecentBook(item);
if (book) { if (book) {
book.checkBuc = item.checkBuc; await bookManager.setCheckBuc(book, item.checkBuc);
await bookManager.recentSetItem(book);
} }
} }
} }

View File

@@ -41,17 +41,6 @@
</q-checkbox> </q-checkbox>
</div> </div>
<div class="item row">
<div class="label-6">Уведомление</div>
<q-checkbox size="xs" v-model="showNeedUpdateNotify">
Показывать уведомление о новой версии
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
Напоминать о необходимости обновления страницы<br>
при появлении новой версии читалки
</q-tooltip>
</q-checkbox>
</div>
<!--div class="item row"> <!--div class="item row">
<div class="label-6">Уведомление</div> <div class="label-6">Уведомление</div>
<q-checkbox size="xs" v-model="showDonationDialog2020"> <q-checkbox size="xs" v-model="showDonationDialog2020">

View File

@@ -30,6 +30,7 @@
<q-tab class="tab" name="keys" icon="la la-gamepad" label="Управление" /> <q-tab class="tab" name="keys" icon="la la-gamepad" label="Управление" />
<q-tab class="tab" name="pagemove" icon="la la-school" label="Листание" /> <q-tab class="tab" name="pagemove" icon="la la-school" label="Листание" />
<q-tab class="tab" name="convert" icon="la la-magic" label="Конвертир." /> <q-tab class="tab" name="convert" icon="la la-magic" label="Конвертир." />
<q-tab class="tab" name="update" icon="la la-sync" label="Обновление" />
<q-tab class="tab" name="others" icon="la la-list-ul" label="Прочее" /> <q-tab class="tab" name="others" icon="la la-list-ul" label="Прочее" />
<q-tab class="tab" name="reset" icon="la la-broom" label="Сброс" /> <q-tab class="tab" name="reset" icon="la la-broom" label="Сброс" />
<div v-show="tabsScrollable" class="q-pt-lg" /> <div v-show="tabsScrollable" class="q-pt-lg" />
@@ -99,6 +100,10 @@
<div v-if="selectedTab == 'convert'" class="fit tab-panel"> <div v-if="selectedTab == 'convert'" class="fit tab-panel">
@@include('./ConvertTab.inc'); @@include('./ConvertTab.inc');
</div> </div>
<!-- Обновление ------------------------------------------------------------------>
<div v-if="selectedTab == 'update'" class="fit tab-panel">
@@include('./UpdateTab.inc');
</div>
<!-- Прочее ----------------------------------------------------------------------> <!-- Прочее ---------------------------------------------------------------------->
<div v-if="selectedTab == 'others'" class="fit tab-panel"> <div v-if="selectedTab == 'others'" class="fit tab-panel">
@@include('./OthersTab.inc'); @@include('./OthersTab.inc');

View File

@@ -0,0 +1,45 @@
<!---------------------------------------------->
<div class="part-header">Обновление читалки</div>
<div class="item row">
<div class="label-6"></div>
<q-checkbox size="xs" v-model="showNeedUpdateNotify">
Проверять наличие новой версии
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
Напоминать о необходимости обновления страницы<br>
при появлении новой версии читалки
</q-tooltip>
</q-checkbox>
</div>
<!---------------------------------------------->
<div class="part-header">Обновление книг</div>
<div class="item row">
<div class="label-6"></div>
<q-checkbox size="xs" v-model="bucEnabled">
Проверять обновления книг
</q-checkbox>
</div>
<div class="item row">
<div class="label-6"></div>
<q-checkbox size="xs" v-model="bucSetOnNew">
Автопроверка для вновь загружаемых
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
Автоматически устанавливать флаг проверки<br>
обновлений для всех вновь загружаемых книг
</q-tooltip>
</q-checkbox>
</div>
<div v-show="bucEnabled" class="item row">
<div class="label-6">Разница размеров</div>
<div class="col row">
<NumInput class="col-left" v-model="bucSizeDiff" />
<q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
Уведомлять о наличии обновления книги в списке загруженных<br>
при указанной разнице в размерах старого и нового файлов
</q-tooltip>
</div>
</div>

View File

@@ -487,6 +487,28 @@ class BookManager {
await this.recentSetItem(item); await this.recentSetItem(item);
} }
async setCheckBuc(value, checkBuc = true) {
const item = this.recent[value.key];
const updateItems = [];
if (item) {
if (item.sameBookKey !== undefined) {
const sorted = this.getSortedRecent();
for (const book of sorted) {
if (book.sameBookKey === item.sameBookKey)
updateItems.push(book);
}
} else {
updateItems.push(item);
}
}
for (const book of updateItems) {
book.checkBuc = checkBuc;
await this.recentSetItem(book);
}
}
async cleanRecentBooks() { async cleanRecentBooks() {
const sorted = this.getSortedRecent(); const sorted = this.getSortedRecent();