Работа над ServerStorage, попутный рефакторинг
This commit is contained in:
@@ -208,11 +208,10 @@ class Reader extends Vue {
|
|||||||
(async() => {
|
(async() => {
|
||||||
await bookManager.init(this.settings);
|
await bookManager.init(this.settings);
|
||||||
bookManager.addEventListener(this.bookManagerEvent);
|
bookManager.addEventListener(this.bookManagerEvent);
|
||||||
await this.$refs.serverStorage.init();
|
|
||||||
|
|
||||||
if (this.$root.rootRoute == '/reader') {
|
if (this.$root.rootRoute == '/reader') {
|
||||||
if (this.routeParamUrl) {
|
if (this.routeParamUrl) {
|
||||||
this.loadBook({url: this.routeParamUrl, bookPos: this.routeParamPos});
|
await this.loadBook({url: this.routeParamUrl, bookPos: this.routeParamPos});
|
||||||
} else {
|
} else {
|
||||||
this.loaderActive = true;
|
this.loaderActive = true;
|
||||||
}
|
}
|
||||||
@@ -290,13 +289,22 @@ class Reader extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bookManagerEvent(eventName) {
|
bookManagerEvent(eventName) {
|
||||||
|
const serverStorage = this.$refs.serverStorage;
|
||||||
|
if (eventName == 'load-meta-finish') {
|
||||||
|
serverStorage.init();
|
||||||
|
}
|
||||||
|
|
||||||
if (eventName == 'recent-changed') {
|
if (eventName == 'recent-changed') {
|
||||||
|
(async() => {
|
||||||
const oldBook = this.mostRecentBookReactive;
|
const oldBook = this.mostRecentBookReactive;
|
||||||
const newBook = bookManager.mostRecentBook();
|
const newBook = bookManager.mostRecentBook();
|
||||||
|
|
||||||
if (oldBook && newBook && oldBook.key != newBook.key) {
|
if (oldBook && newBook && oldBook.key != newBook.key) {
|
||||||
this.loadBook(newBook);
|
await this.loadBook(newBook);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await serverStorage.saveRecent();
|
||||||
|
})();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -649,7 +657,7 @@ class Reader extends Vue {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadBook(opts) {
|
async loadBook(opts) {
|
||||||
if (!opts || !opts.url) {
|
if (!opts || !opts.url) {
|
||||||
this.mostRecentBook();
|
this.mostRecentBook();
|
||||||
return;
|
return;
|
||||||
@@ -668,7 +676,9 @@ class Reader extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.progressActive = true;
|
this.progressActive = true;
|
||||||
this.$nextTick(async() => {
|
|
||||||
|
await this.$nextTick()
|
||||||
|
|
||||||
const progress = this.$refs.page;
|
const progress = this.$refs.page;
|
||||||
|
|
||||||
this.actionList = [];
|
this.actionList = [];
|
||||||
@@ -756,12 +766,13 @@ class Reader extends Vue {
|
|||||||
this.loaderActive = true;
|
this.loaderActive = true;
|
||||||
this.$alert(e.message, 'Ошибка', {type: 'error'});
|
this.$alert(e.message, 'Ошибка', {type: 'error'});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadFile(opts) {
|
async loadFile(opts) {
|
||||||
this.progressActive = true;
|
this.progressActive = true;
|
||||||
this.$nextTick(async() => {
|
|
||||||
|
await this.$nextTick();
|
||||||
|
|
||||||
const progress = this.$refs.page;
|
const progress = this.$refs.page;
|
||||||
try {
|
try {
|
||||||
progress.show();
|
progress.show();
|
||||||
@@ -773,13 +784,12 @@ class Reader extends Vue {
|
|||||||
|
|
||||||
progress.hide(); this.progressActive = false;
|
progress.hide(); this.progressActive = false;
|
||||||
|
|
||||||
this.loadBook({url});
|
await this.loadBook({url});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
progress.hide(); this.progressActive = false;
|
progress.hide(); this.progressActive = false;
|
||||||
this.loaderActive = true;
|
this.loaderActive = true;
|
||||||
this.$alert(e.message, 'Ошибка', {type: 'error'});
|
this.$alert(e.message, 'Ошибка', {type: 'error'});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
blinkCachedLoadMessage() {
|
blinkCachedLoadMessage() {
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ class BookManager {
|
|||||||
}
|
}
|
||||||
await bmCacheStore.setItem('books', this.booksCached);
|
await bmCacheStore.setItem('books', this.booksCached);
|
||||||
await bmCacheStore.setItem('recent', this.recent);
|
await bmCacheStore.setItem('recent', this.recent);
|
||||||
|
this.emit('load-meta-finish');
|
||||||
}
|
}
|
||||||
|
|
||||||
async cleanBooks() {
|
async cleanBooks() {
|
||||||
|
|||||||
Reference in New Issue
Block a user