@embedpdf-editor/vue3-chapter-viewer 1.0.7-beta.8 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +601 -470
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -419,12 +419,17 @@ const st$1 = class e extends BasePlugin {
|
|
|
419
419
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
420
420
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
421
421
|
const s2 = this.findChapter(e15.chapterId);
|
|
422
|
-
if (s2)
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
422
|
+
if (!s2) continue;
|
|
423
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
424
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
425
|
+
continue;
|
|
427
426
|
}
|
|
427
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
428
|
+
let n9 = false;
|
|
429
|
+
const r2 = () => {
|
|
430
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
431
|
+
};
|
|
432
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
428
433
|
}
|
|
429
434
|
}
|
|
430
435
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -514,21 +519,21 @@ const st$1 = class e extends BasePlugin {
|
|
|
514
519
|
ensureSegmentLoaded(e14, t2) {
|
|
515
520
|
return this.loadSegmentNow(e14, t2);
|
|
516
521
|
}
|
|
517
|
-
loadSegmentNow(e14, t2) {
|
|
522
|
+
loadSegmentNow(e14, t2, s2) {
|
|
518
523
|
this.prepareChapterForSegmentLoad(e14);
|
|
519
|
-
const
|
|
520
|
-
if (!
|
|
521
|
-
const
|
|
522
|
-
if (!
|
|
523
|
-
if (t2 < 0 || t2 >=
|
|
524
|
-
const
|
|
525
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
526
|
-
const
|
|
527
|
-
if (
|
|
528
|
-
const
|
|
529
|
-
this.pendingSegmentLoadPromises.delete(
|
|
524
|
+
const n9 = this.findChapter(e14);
|
|
525
|
+
if (!n9) return Promise.resolve("error");
|
|
526
|
+
const r2 = je$1(n9);
|
|
527
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
528
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
529
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
530
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
531
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
532
|
+
if (o2) return o2;
|
|
533
|
+
const l = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
534
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
530
535
|
});
|
|
531
|
-
return this.pendingSegmentLoadPromises.set(
|
|
536
|
+
return this.pendingSegmentLoadPromises.set(i2, l), l;
|
|
532
537
|
}
|
|
533
538
|
ensureSingleDocumentChapter(e14) {
|
|
534
539
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -602,24 +607,27 @@ const st$1 = class e extends BasePlugin {
|
|
|
602
607
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(t2, s2);
|
|
603
608
|
throw new Error(`Chapter "${t2.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
604
609
|
}
|
|
605
|
-
async startLoadSegment(t2, s2) {
|
|
606
|
-
var
|
|
607
|
-
const
|
|
608
|
-
|
|
610
|
+
async startLoadSegment(t2, s2, n9) {
|
|
611
|
+
var r2;
|
|
612
|
+
const a2 = t2.chapterId, i2 = (null == s2 ? void 0 : s2.index) ?? 0, o2 = (null == s2 ? void 0 : s2.documentId) ?? a2;
|
|
613
|
+
let l = false;
|
|
614
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
609
615
|
try {
|
|
610
|
-
const e14 = t2.encrypted && (null == (
|
|
611
|
-
|
|
616
|
+
const e14 = t2.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, h2 = await this.resolvePdfPayload(t2, i2), d2 = this.documentManager.provides(), c2 = "url" in h2 ? d2.openDocumentUrl({ documentId: o2, url: h2.url, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: h2.buffer, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false });
|
|
617
|
+
l || (l = true, null == n9 || n9());
|
|
618
|
+
const u2 = await new Promise((e15, t3) => {
|
|
619
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
612
620
|
});
|
|
613
621
|
return await new Promise((e15, t3) => {
|
|
614
|
-
|
|
615
|
-
}),
|
|
616
|
-
} catch (
|
|
617
|
-
const t3 = this.chapterStatus.get(
|
|
622
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
623
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
624
|
+
} catch (h2) {
|
|
625
|
+
const t3 = this.chapterStatus.get(a2);
|
|
618
626
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
619
|
-
const t4 =
|
|
620
|
-
this.logger.error(e.id, "LoadChapter", t4,
|
|
627
|
+
const t4 = h2 instanceof Error ? h2.message : `Failed to load chapter "${a2}"`;
|
|
628
|
+
this.logger.error(e.id, "LoadChapter", t4, h2), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", t4);
|
|
621
629
|
}
|
|
622
|
-
return this.chapterStatus.get(
|
|
630
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
623
631
|
}
|
|
624
632
|
}
|
|
625
633
|
waitForTerminalStatus(e14) {
|
|
@@ -1032,12 +1040,17 @@ const xt$1 = class e2 extends BasePlugin {
|
|
|
1032
1040
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
1033
1041
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
1034
1042
|
const s2 = this.findChapter(e15.chapterId);
|
|
1035
|
-
if (s2)
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
1043
|
+
if (!s2) continue;
|
|
1044
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
1045
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
1046
|
+
continue;
|
|
1040
1047
|
}
|
|
1048
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
1049
|
+
let n9 = false;
|
|
1050
|
+
const r2 = () => {
|
|
1051
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
1052
|
+
};
|
|
1053
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
1041
1054
|
}
|
|
1042
1055
|
}
|
|
1043
1056
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -1127,21 +1140,21 @@ const xt$1 = class e2 extends BasePlugin {
|
|
|
1127
1140
|
ensureSegmentLoaded(e14, t2) {
|
|
1128
1141
|
return this.loadSegmentNow(e14, t2);
|
|
1129
1142
|
}
|
|
1130
|
-
loadSegmentNow(e14, t2) {
|
|
1143
|
+
loadSegmentNow(e14, t2, s2) {
|
|
1131
1144
|
this.prepareChapterForSegmentLoad(e14);
|
|
1132
|
-
const
|
|
1133
|
-
if (!
|
|
1134
|
-
const
|
|
1135
|
-
if (!
|
|
1136
|
-
if (t2 < 0 || t2 >=
|
|
1137
|
-
const
|
|
1138
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
1139
|
-
const
|
|
1140
|
-
if (
|
|
1141
|
-
const
|
|
1142
|
-
this.pendingSegmentLoadPromises.delete(
|
|
1145
|
+
const n9 = this.findChapter(e14);
|
|
1146
|
+
if (!n9) return Promise.resolve("error");
|
|
1147
|
+
const r2 = Pt$1(n9);
|
|
1148
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
1149
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
1150
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
1151
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
1152
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
1153
|
+
if (o2) return o2;
|
|
1154
|
+
const l = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
1155
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
1143
1156
|
});
|
|
1144
|
-
return this.pendingSegmentLoadPromises.set(
|
|
1157
|
+
return this.pendingSegmentLoadPromises.set(i2, l), l;
|
|
1145
1158
|
}
|
|
1146
1159
|
ensureSingleDocumentChapter(e14) {
|
|
1147
1160
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -1215,24 +1228,27 @@ const xt$1 = class e2 extends BasePlugin {
|
|
|
1215
1228
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(t2, s2);
|
|
1216
1229
|
throw new Error(`Chapter "${t2.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
1217
1230
|
}
|
|
1218
|
-
async startLoadSegment(t2, s2) {
|
|
1219
|
-
var
|
|
1220
|
-
const
|
|
1221
|
-
|
|
1231
|
+
async startLoadSegment(t2, s2, n9) {
|
|
1232
|
+
var r2;
|
|
1233
|
+
const a2 = t2.chapterId, i2 = (null == s2 ? void 0 : s2.index) ?? 0, o2 = (null == s2 ? void 0 : s2.documentId) ?? a2;
|
|
1234
|
+
let l = false;
|
|
1235
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
1222
1236
|
try {
|
|
1223
|
-
const e14 = t2.encrypted && (null == (
|
|
1224
|
-
|
|
1237
|
+
const e14 = t2.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, h2 = await this.resolvePdfPayload(t2, i2), d2 = this.documentManager.provides(), c2 = "url" in h2 ? d2.openDocumentUrl({ documentId: o2, url: h2.url, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: h2.buffer, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false });
|
|
1238
|
+
l || (l = true, null == n9 || n9());
|
|
1239
|
+
const u2 = await new Promise((e15, t3) => {
|
|
1240
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
1225
1241
|
});
|
|
1226
1242
|
return await new Promise((e15, t3) => {
|
|
1227
|
-
|
|
1228
|
-
}),
|
|
1229
|
-
} catch (
|
|
1230
|
-
const t3 = this.chapterStatus.get(
|
|
1243
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
1244
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
1245
|
+
} catch (h2) {
|
|
1246
|
+
const t3 = this.chapterStatus.get(a2);
|
|
1231
1247
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
1232
|
-
const t4 =
|
|
1233
|
-
this.logger.error(e2.id, "LoadChapter", t4,
|
|
1248
|
+
const t4 = h2 instanceof Error ? h2.message : `Failed to load chapter "${a2}"`;
|
|
1249
|
+
this.logger.error(e2.id, "LoadChapter", t4, h2), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", t4);
|
|
1234
1250
|
}
|
|
1235
|
-
return this.chapterStatus.get(
|
|
1251
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
1236
1252
|
}
|
|
1237
1253
|
}
|
|
1238
1254
|
waitForTerminalStatus(e14) {
|
|
@@ -1835,12 +1851,17 @@ const jt$1 = class e3 extends BasePlugin {
|
|
|
1835
1851
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
1836
1852
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
1837
1853
|
const s2 = this.findChapter(e15.chapterId);
|
|
1838
|
-
if (s2)
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
1854
|
+
if (!s2) continue;
|
|
1855
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
1856
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
1857
|
+
continue;
|
|
1843
1858
|
}
|
|
1859
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
1860
|
+
let n9 = false;
|
|
1861
|
+
const r2 = () => {
|
|
1862
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
1863
|
+
};
|
|
1864
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
1844
1865
|
}
|
|
1845
1866
|
}
|
|
1846
1867
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -1930,21 +1951,21 @@ const jt$1 = class e3 extends BasePlugin {
|
|
|
1930
1951
|
ensureSegmentLoaded(e14, t2) {
|
|
1931
1952
|
return this.loadSegmentNow(e14, t2);
|
|
1932
1953
|
}
|
|
1933
|
-
loadSegmentNow(e14, t2) {
|
|
1954
|
+
loadSegmentNow(e14, t2, s2) {
|
|
1934
1955
|
this.prepareChapterForSegmentLoad(e14);
|
|
1935
|
-
const
|
|
1936
|
-
if (!
|
|
1937
|
-
const
|
|
1938
|
-
if (!
|
|
1939
|
-
if (t2 < 0 || t2 >=
|
|
1940
|
-
const
|
|
1941
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
1942
|
-
const
|
|
1943
|
-
if (
|
|
1944
|
-
const
|
|
1945
|
-
this.pendingSegmentLoadPromises.delete(
|
|
1956
|
+
const n9 = this.findChapter(e14);
|
|
1957
|
+
if (!n9) return Promise.resolve("error");
|
|
1958
|
+
const r2 = zt$1(n9);
|
|
1959
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
1960
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
1961
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
1962
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
1963
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
1964
|
+
if (o2) return o2;
|
|
1965
|
+
const l = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
1966
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
1946
1967
|
});
|
|
1947
|
-
return this.pendingSegmentLoadPromises.set(
|
|
1968
|
+
return this.pendingSegmentLoadPromises.set(i2, l), l;
|
|
1948
1969
|
}
|
|
1949
1970
|
ensureSingleDocumentChapter(e14) {
|
|
1950
1971
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -2018,24 +2039,27 @@ const jt$1 = class e3 extends BasePlugin {
|
|
|
2018
2039
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(t2, s2);
|
|
2019
2040
|
throw new Error(`Chapter "${t2.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
2020
2041
|
}
|
|
2021
|
-
async startLoadSegment(t2, s2) {
|
|
2022
|
-
var
|
|
2023
|
-
const
|
|
2024
|
-
|
|
2042
|
+
async startLoadSegment(t2, s2, n9) {
|
|
2043
|
+
var r2;
|
|
2044
|
+
const a2 = t2.chapterId, i2 = (null == s2 ? void 0 : s2.index) ?? 0, o2 = (null == s2 ? void 0 : s2.documentId) ?? a2;
|
|
2045
|
+
let l = false;
|
|
2046
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
2025
2047
|
try {
|
|
2026
|
-
const e14 = t2.encrypted && (null == (
|
|
2027
|
-
|
|
2048
|
+
const e14 = t2.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, h2 = await this.resolvePdfPayload(t2, i2), d2 = this.documentManager.provides(), c2 = "url" in h2 ? d2.openDocumentUrl({ documentId: o2, url: h2.url, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: h2.buffer, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false });
|
|
2049
|
+
l || (l = true, null == n9 || n9());
|
|
2050
|
+
const u2 = await new Promise((e15, t3) => {
|
|
2051
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
2028
2052
|
});
|
|
2029
2053
|
return await new Promise((e15, t3) => {
|
|
2030
|
-
|
|
2031
|
-
}),
|
|
2032
|
-
} catch (
|
|
2033
|
-
const t3 = this.chapterStatus.get(
|
|
2054
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
2055
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
2056
|
+
} catch (h2) {
|
|
2057
|
+
const t3 = this.chapterStatus.get(a2);
|
|
2034
2058
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
2035
|
-
const t4 =
|
|
2036
|
-
this.logger.error(e3.id, "LoadChapter", t4,
|
|
2059
|
+
const t4 = h2 instanceof Error ? h2.message : `Failed to load chapter "${a2}"`;
|
|
2060
|
+
this.logger.error(e3.id, "LoadChapter", t4, h2), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", t4);
|
|
2037
2061
|
}
|
|
2038
|
-
return this.chapterStatus.get(
|
|
2062
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
2039
2063
|
}
|
|
2040
2064
|
}
|
|
2041
2065
|
waitForTerminalStatus(e14) {
|
|
@@ -2447,12 +2471,17 @@ const ms = class e4 extends BasePlugin {
|
|
|
2447
2471
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
2448
2472
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
2449
2473
|
const s2 = this.findChapter(e15.chapterId);
|
|
2450
|
-
if (s2)
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
2474
|
+
if (!s2) continue;
|
|
2475
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
2476
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
2477
|
+
continue;
|
|
2455
2478
|
}
|
|
2479
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
2480
|
+
let n9 = false;
|
|
2481
|
+
const r2 = () => {
|
|
2482
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
2483
|
+
};
|
|
2484
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
2456
2485
|
}
|
|
2457
2486
|
}
|
|
2458
2487
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -2542,21 +2571,21 @@ const ms = class e4 extends BasePlugin {
|
|
|
2542
2571
|
ensureSegmentLoaded(e14, t2) {
|
|
2543
2572
|
return this.loadSegmentNow(e14, t2);
|
|
2544
2573
|
}
|
|
2545
|
-
loadSegmentNow(e14, t2) {
|
|
2574
|
+
loadSegmentNow(e14, t2, s2) {
|
|
2546
2575
|
this.prepareChapterForSegmentLoad(e14);
|
|
2547
|
-
const
|
|
2548
|
-
if (!
|
|
2549
|
-
const
|
|
2550
|
-
if (!
|
|
2551
|
-
if (t2 < 0 || t2 >=
|
|
2552
|
-
const
|
|
2553
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
2554
|
-
const
|
|
2555
|
-
if (
|
|
2556
|
-
const
|
|
2557
|
-
this.pendingSegmentLoadPromises.delete(
|
|
2576
|
+
const n9 = this.findChapter(e14);
|
|
2577
|
+
if (!n9) return Promise.resolve("error");
|
|
2578
|
+
const r2 = os(n9);
|
|
2579
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
2580
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
2581
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
2582
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
2583
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
2584
|
+
if (o2) return o2;
|
|
2585
|
+
const l = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
2586
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
2558
2587
|
});
|
|
2559
|
-
return this.pendingSegmentLoadPromises.set(
|
|
2588
|
+
return this.pendingSegmentLoadPromises.set(i2, l), l;
|
|
2560
2589
|
}
|
|
2561
2590
|
ensureSingleDocumentChapter(e14) {
|
|
2562
2591
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -2630,24 +2659,27 @@ const ms = class e4 extends BasePlugin {
|
|
|
2630
2659
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(t2, s2);
|
|
2631
2660
|
throw new Error(`Chapter "${t2.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
2632
2661
|
}
|
|
2633
|
-
async startLoadSegment(t2, s2) {
|
|
2634
|
-
var
|
|
2635
|
-
const
|
|
2636
|
-
|
|
2662
|
+
async startLoadSegment(t2, s2, n9) {
|
|
2663
|
+
var r2;
|
|
2664
|
+
const a2 = t2.chapterId, i2 = (null == s2 ? void 0 : s2.index) ?? 0, o2 = (null == s2 ? void 0 : s2.documentId) ?? a2;
|
|
2665
|
+
let l = false;
|
|
2666
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
2637
2667
|
try {
|
|
2638
|
-
const e14 = t2.encrypted && (null == (
|
|
2639
|
-
|
|
2668
|
+
const e14 = t2.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, h2 = await this.resolvePdfPayload(t2, i2), d2 = this.documentManager.provides(), c2 = "url" in h2 ? d2.openDocumentUrl({ documentId: o2, url: h2.url, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: h2.buffer, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false });
|
|
2669
|
+
l || (l = true, null == n9 || n9());
|
|
2670
|
+
const u2 = await new Promise((e15, t3) => {
|
|
2671
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
2640
2672
|
});
|
|
2641
2673
|
return await new Promise((e15, t3) => {
|
|
2642
|
-
|
|
2643
|
-
}),
|
|
2644
|
-
} catch (
|
|
2645
|
-
const t3 = this.chapterStatus.get(
|
|
2674
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
2675
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
2676
|
+
} catch (h2) {
|
|
2677
|
+
const t3 = this.chapterStatus.get(a2);
|
|
2646
2678
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
2647
|
-
const t4 =
|
|
2648
|
-
this.logger.error(e4.id, "LoadChapter", t4,
|
|
2679
|
+
const t4 = h2 instanceof Error ? h2.message : `Failed to load chapter "${a2}"`;
|
|
2680
|
+
this.logger.error(e4.id, "LoadChapter", t4, h2), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", t4);
|
|
2649
2681
|
}
|
|
2650
|
-
return this.chapterStatus.get(
|
|
2682
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
2651
2683
|
}
|
|
2652
2684
|
}
|
|
2653
2685
|
waitForTerminalStatus(e14) {
|
|
@@ -3363,12 +3395,17 @@ const zs$1 = class e6 extends BasePlugin {
|
|
|
3363
3395
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
3364
3396
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
3365
3397
|
const s2 = this.findChapter(e15.chapterId);
|
|
3366
|
-
if (s2)
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
3398
|
+
if (!s2) continue;
|
|
3399
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
3400
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
3401
|
+
continue;
|
|
3371
3402
|
}
|
|
3403
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
3404
|
+
let n9 = false;
|
|
3405
|
+
const r2 = () => {
|
|
3406
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
3407
|
+
};
|
|
3408
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
3372
3409
|
}
|
|
3373
3410
|
}
|
|
3374
3411
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -3458,21 +3495,21 @@ const zs$1 = class e6 extends BasePlugin {
|
|
|
3458
3495
|
ensureSegmentLoaded(e14, t2) {
|
|
3459
3496
|
return this.loadSegmentNow(e14, t2);
|
|
3460
3497
|
}
|
|
3461
|
-
loadSegmentNow(e14, t2) {
|
|
3498
|
+
loadSegmentNow(e14, t2, s2) {
|
|
3462
3499
|
this.prepareChapterForSegmentLoad(e14);
|
|
3463
|
-
const
|
|
3464
|
-
if (!
|
|
3465
|
-
const
|
|
3466
|
-
if (!
|
|
3467
|
-
if (t2 < 0 || t2 >=
|
|
3468
|
-
const
|
|
3469
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
3470
|
-
const
|
|
3471
|
-
if (
|
|
3472
|
-
const
|
|
3473
|
-
this.pendingSegmentLoadPromises.delete(
|
|
3500
|
+
const n9 = this.findChapter(e14);
|
|
3501
|
+
if (!n9) return Promise.resolve("error");
|
|
3502
|
+
const r2 = Es$1(n9);
|
|
3503
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
3504
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
3505
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
3506
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
3507
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
3508
|
+
if (o2) return o2;
|
|
3509
|
+
const l = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
3510
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
3474
3511
|
});
|
|
3475
|
-
return this.pendingSegmentLoadPromises.set(
|
|
3512
|
+
return this.pendingSegmentLoadPromises.set(i2, l), l;
|
|
3476
3513
|
}
|
|
3477
3514
|
ensureSingleDocumentChapter(e14) {
|
|
3478
3515
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -3546,24 +3583,27 @@ const zs$1 = class e6 extends BasePlugin {
|
|
|
3546
3583
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(t2, s2);
|
|
3547
3584
|
throw new Error(`Chapter "${t2.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
3548
3585
|
}
|
|
3549
|
-
async startLoadSegment(t2, s2) {
|
|
3550
|
-
var
|
|
3551
|
-
const
|
|
3552
|
-
|
|
3586
|
+
async startLoadSegment(t2, s2, n9) {
|
|
3587
|
+
var r2;
|
|
3588
|
+
const a2 = t2.chapterId, i2 = (null == s2 ? void 0 : s2.index) ?? 0, o2 = (null == s2 ? void 0 : s2.documentId) ?? a2;
|
|
3589
|
+
let l = false;
|
|
3590
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
3553
3591
|
try {
|
|
3554
|
-
const e14 = t2.encrypted && (null == (
|
|
3555
|
-
|
|
3592
|
+
const e14 = t2.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, h2 = await this.resolvePdfPayload(t2, i2), d2 = this.documentManager.provides(), c2 = "url" in h2 ? d2.openDocumentUrl({ documentId: o2, url: h2.url, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: h2.buffer, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false });
|
|
3593
|
+
l || (l = true, null == n9 || n9());
|
|
3594
|
+
const u2 = await new Promise((e15, t3) => {
|
|
3595
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
3556
3596
|
});
|
|
3557
3597
|
return await new Promise((e15, t3) => {
|
|
3558
|
-
|
|
3559
|
-
}),
|
|
3560
|
-
} catch (
|
|
3561
|
-
const t3 = this.chapterStatus.get(
|
|
3598
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
3599
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
3600
|
+
} catch (h2) {
|
|
3601
|
+
const t3 = this.chapterStatus.get(a2);
|
|
3562
3602
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
3563
|
-
const t4 =
|
|
3564
|
-
this.logger.error(e6.id, "LoadChapter", t4,
|
|
3603
|
+
const t4 = h2 instanceof Error ? h2.message : `Failed to load chapter "${a2}"`;
|
|
3604
|
+
this.logger.error(e6.id, "LoadChapter", t4, h2), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", t4);
|
|
3565
3605
|
}
|
|
3566
|
-
return this.chapterStatus.get(
|
|
3606
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
3567
3607
|
}
|
|
3568
3608
|
}
|
|
3569
3609
|
waitForTerminalStatus(e14) {
|
|
@@ -3975,12 +4015,17 @@ const ln = class e7 extends BasePlugin {
|
|
|
3975
4015
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
3976
4016
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
3977
4017
|
const s2 = this.findChapter(e15.chapterId);
|
|
3978
|
-
if (s2)
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
4018
|
+
if (!s2) continue;
|
|
4019
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
4020
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
4021
|
+
continue;
|
|
3983
4022
|
}
|
|
4023
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
4024
|
+
let n9 = false;
|
|
4025
|
+
const r2 = () => {
|
|
4026
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
4027
|
+
};
|
|
4028
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
3984
4029
|
}
|
|
3985
4030
|
}
|
|
3986
4031
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -4070,21 +4115,21 @@ const ln = class e7 extends BasePlugin {
|
|
|
4070
4115
|
ensureSegmentLoaded(e14, t2) {
|
|
4071
4116
|
return this.loadSegmentNow(e14, t2);
|
|
4072
4117
|
}
|
|
4073
|
-
loadSegmentNow(e14, t2) {
|
|
4118
|
+
loadSegmentNow(e14, t2, s2) {
|
|
4074
4119
|
this.prepareChapterForSegmentLoad(e14);
|
|
4075
|
-
const
|
|
4076
|
-
if (!
|
|
4077
|
-
const
|
|
4078
|
-
if (!
|
|
4079
|
-
if (t2 < 0 || t2 >=
|
|
4080
|
-
const
|
|
4081
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
4082
|
-
const
|
|
4083
|
-
if (
|
|
4084
|
-
const
|
|
4085
|
-
this.pendingSegmentLoadPromises.delete(
|
|
4120
|
+
const n9 = this.findChapter(e14);
|
|
4121
|
+
if (!n9) return Promise.resolve("error");
|
|
4122
|
+
const r2 = Js(n9);
|
|
4123
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
4124
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
4125
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
4126
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
4127
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
4128
|
+
if (o2) return o2;
|
|
4129
|
+
const l = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
4130
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
4086
4131
|
});
|
|
4087
|
-
return this.pendingSegmentLoadPromises.set(
|
|
4132
|
+
return this.pendingSegmentLoadPromises.set(i2, l), l;
|
|
4088
4133
|
}
|
|
4089
4134
|
ensureSingleDocumentChapter(e14) {
|
|
4090
4135
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -4158,24 +4203,27 @@ const ln = class e7 extends BasePlugin {
|
|
|
4158
4203
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(t2, s2);
|
|
4159
4204
|
throw new Error(`Chapter "${t2.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
4160
4205
|
}
|
|
4161
|
-
async startLoadSegment(t2, s2) {
|
|
4162
|
-
var
|
|
4163
|
-
const
|
|
4164
|
-
|
|
4206
|
+
async startLoadSegment(t2, s2, n9) {
|
|
4207
|
+
var r2;
|
|
4208
|
+
const a2 = t2.chapterId, i2 = (null == s2 ? void 0 : s2.index) ?? 0, o2 = (null == s2 ? void 0 : s2.documentId) ?? a2;
|
|
4209
|
+
let l = false;
|
|
4210
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
4165
4211
|
try {
|
|
4166
|
-
const e14 = t2.encrypted && (null == (
|
|
4167
|
-
|
|
4212
|
+
const e14 = t2.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, h2 = await this.resolvePdfPayload(t2, i2), d2 = this.documentManager.provides(), c2 = "url" in h2 ? d2.openDocumentUrl({ documentId: o2, url: h2.url, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: h2.buffer, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false });
|
|
4213
|
+
l || (l = true, null == n9 || n9());
|
|
4214
|
+
const u2 = await new Promise((e15, t3) => {
|
|
4215
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
4168
4216
|
});
|
|
4169
4217
|
return await new Promise((e15, t3) => {
|
|
4170
|
-
|
|
4171
|
-
}),
|
|
4172
|
-
} catch (
|
|
4173
|
-
const t3 = this.chapterStatus.get(
|
|
4218
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
4219
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
4220
|
+
} catch (h2) {
|
|
4221
|
+
const t3 = this.chapterStatus.get(a2);
|
|
4174
4222
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
4175
|
-
const t4 =
|
|
4176
|
-
this.logger.error(e7.id, "LoadChapter", t4,
|
|
4223
|
+
const t4 = h2 instanceof Error ? h2.message : `Failed to load chapter "${a2}"`;
|
|
4224
|
+
this.logger.error(e7.id, "LoadChapter", t4, h2), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", t4);
|
|
4177
4225
|
}
|
|
4178
|
-
return this.chapterStatus.get(
|
|
4226
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
4179
4227
|
}
|
|
4180
4228
|
}
|
|
4181
4229
|
waitForTerminalStatus(e14) {
|
|
@@ -5248,12 +5296,17 @@ const pr = class e9 extends BasePlugin {
|
|
|
5248
5296
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
5249
5297
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
5250
5298
|
const s2 = this.findChapter(e15.chapterId);
|
|
5251
|
-
if (s2)
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
|
|
5255
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
5299
|
+
if (!s2) continue;
|
|
5300
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
5301
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
5302
|
+
continue;
|
|
5256
5303
|
}
|
|
5304
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
5305
|
+
let n9 = false;
|
|
5306
|
+
const r2 = () => {
|
|
5307
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
5308
|
+
};
|
|
5309
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
5257
5310
|
}
|
|
5258
5311
|
}
|
|
5259
5312
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -5343,21 +5396,21 @@ const pr = class e9 extends BasePlugin {
|
|
|
5343
5396
|
ensureSegmentLoaded(e14, t2) {
|
|
5344
5397
|
return this.loadSegmentNow(e14, t2);
|
|
5345
5398
|
}
|
|
5346
|
-
loadSegmentNow(e14, t2) {
|
|
5399
|
+
loadSegmentNow(e14, t2, s2) {
|
|
5347
5400
|
this.prepareChapterForSegmentLoad(e14);
|
|
5348
|
-
const
|
|
5349
|
-
if (!
|
|
5350
|
-
const
|
|
5351
|
-
if (!
|
|
5352
|
-
if (t2 < 0 || t2 >=
|
|
5353
|
-
const
|
|
5354
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
5355
|
-
const
|
|
5356
|
-
if (
|
|
5357
|
-
const
|
|
5358
|
-
this.pendingSegmentLoadPromises.delete(
|
|
5401
|
+
const n9 = this.findChapter(e14);
|
|
5402
|
+
if (!n9) return Promise.resolve("error");
|
|
5403
|
+
const r2 = ar(n9);
|
|
5404
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
5405
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
5406
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
5407
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
5408
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
5409
|
+
if (o2) return o2;
|
|
5410
|
+
const l = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
5411
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
5359
5412
|
});
|
|
5360
|
-
return this.pendingSegmentLoadPromises.set(
|
|
5413
|
+
return this.pendingSegmentLoadPromises.set(i2, l), l;
|
|
5361
5414
|
}
|
|
5362
5415
|
ensureSingleDocumentChapter(e14) {
|
|
5363
5416
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -5431,24 +5484,27 @@ const pr = class e9 extends BasePlugin {
|
|
|
5431
5484
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(t2, s2);
|
|
5432
5485
|
throw new Error(`Chapter "${t2.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
5433
5486
|
}
|
|
5434
|
-
async startLoadSegment(t2, s2) {
|
|
5435
|
-
var
|
|
5436
|
-
const
|
|
5437
|
-
|
|
5487
|
+
async startLoadSegment(t2, s2, n9) {
|
|
5488
|
+
var r2;
|
|
5489
|
+
const a2 = t2.chapterId, i2 = (null == s2 ? void 0 : s2.index) ?? 0, o2 = (null == s2 ? void 0 : s2.documentId) ?? a2;
|
|
5490
|
+
let l = false;
|
|
5491
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
5438
5492
|
try {
|
|
5439
|
-
const e14 = t2.encrypted && (null == (
|
|
5440
|
-
|
|
5493
|
+
const e14 = t2.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, h2 = await this.resolvePdfPayload(t2, i2), d2 = this.documentManager.provides(), c2 = "url" in h2 ? d2.openDocumentUrl({ documentId: o2, url: h2.url, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: h2.buffer, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false });
|
|
5494
|
+
l || (l = true, null == n9 || n9());
|
|
5495
|
+
const u2 = await new Promise((e15, t3) => {
|
|
5496
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
5441
5497
|
});
|
|
5442
5498
|
return await new Promise((e15, t3) => {
|
|
5443
|
-
|
|
5444
|
-
}),
|
|
5445
|
-
} catch (
|
|
5446
|
-
const t3 = this.chapterStatus.get(
|
|
5499
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
5500
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
5501
|
+
} catch (h2) {
|
|
5502
|
+
const t3 = this.chapterStatus.get(a2);
|
|
5447
5503
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
5448
|
-
const t4 =
|
|
5449
|
-
this.logger.error(e9.id, "LoadChapter", t4,
|
|
5504
|
+
const t4 = h2 instanceof Error ? h2.message : `Failed to load chapter "${a2}"`;
|
|
5505
|
+
this.logger.error(e9.id, "LoadChapter", t4, h2), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", t4);
|
|
5450
5506
|
}
|
|
5451
|
-
return this.chapterStatus.get(
|
|
5507
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
5452
5508
|
}
|
|
5453
5509
|
}
|
|
5454
5510
|
waitForTerminalStatus(e14) {
|
|
@@ -6072,12 +6128,17 @@ const Tr = class e10 extends BasePlugin {
|
|
|
6072
6128
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
6073
6129
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
6074
6130
|
const s2 = this.findChapter(e15.chapterId);
|
|
6075
|
-
if (s2)
|
|
6076
|
-
|
|
6077
|
-
|
|
6078
|
-
|
|
6079
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
6131
|
+
if (!s2) continue;
|
|
6132
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
6133
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
6134
|
+
continue;
|
|
6080
6135
|
}
|
|
6136
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
6137
|
+
let n9 = false;
|
|
6138
|
+
const r2 = () => {
|
|
6139
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
6140
|
+
};
|
|
6141
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
6081
6142
|
}
|
|
6082
6143
|
}
|
|
6083
6144
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -6167,21 +6228,21 @@ const Tr = class e10 extends BasePlugin {
|
|
|
6167
6228
|
ensureSegmentLoaded(e14, t2) {
|
|
6168
6229
|
return this.loadSegmentNow(e14, t2);
|
|
6169
6230
|
}
|
|
6170
|
-
loadSegmentNow(e14, t2) {
|
|
6231
|
+
loadSegmentNow(e14, t2, s2) {
|
|
6171
6232
|
this.prepareChapterForSegmentLoad(e14);
|
|
6172
|
-
const
|
|
6173
|
-
if (!
|
|
6174
|
-
const
|
|
6175
|
-
if (!
|
|
6176
|
-
if (t2 < 0 || t2 >=
|
|
6177
|
-
const
|
|
6178
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
6179
|
-
const
|
|
6180
|
-
if (
|
|
6181
|
-
const
|
|
6182
|
-
this.pendingSegmentLoadPromises.delete(
|
|
6233
|
+
const n9 = this.findChapter(e14);
|
|
6234
|
+
if (!n9) return Promise.resolve("error");
|
|
6235
|
+
const r2 = Lr(n9);
|
|
6236
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
6237
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
6238
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
6239
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
6240
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
6241
|
+
if (o2) return o2;
|
|
6242
|
+
const l = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
6243
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
6183
6244
|
});
|
|
6184
|
-
return this.pendingSegmentLoadPromises.set(
|
|
6245
|
+
return this.pendingSegmentLoadPromises.set(i2, l), l;
|
|
6185
6246
|
}
|
|
6186
6247
|
ensureSingleDocumentChapter(e14) {
|
|
6187
6248
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -6255,24 +6316,27 @@ const Tr = class e10 extends BasePlugin {
|
|
|
6255
6316
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(t2, s2);
|
|
6256
6317
|
throw new Error(`Chapter "${t2.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
6257
6318
|
}
|
|
6258
|
-
async startLoadSegment(t2, s2) {
|
|
6259
|
-
var
|
|
6260
|
-
const
|
|
6261
|
-
|
|
6319
|
+
async startLoadSegment(t2, s2, n9) {
|
|
6320
|
+
var r2;
|
|
6321
|
+
const a2 = t2.chapterId, i2 = (null == s2 ? void 0 : s2.index) ?? 0, o2 = (null == s2 ? void 0 : s2.documentId) ?? a2;
|
|
6322
|
+
let l = false;
|
|
6323
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
6262
6324
|
try {
|
|
6263
|
-
const e14 = t2.encrypted && (null == (
|
|
6264
|
-
|
|
6325
|
+
const e14 = t2.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, h2 = await this.resolvePdfPayload(t2, i2), d2 = this.documentManager.provides(), c2 = "url" in h2 ? d2.openDocumentUrl({ documentId: o2, url: h2.url, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: h2.buffer, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false });
|
|
6326
|
+
l || (l = true, null == n9 || n9());
|
|
6327
|
+
const u2 = await new Promise((e15, t3) => {
|
|
6328
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
6265
6329
|
});
|
|
6266
6330
|
return await new Promise((e15, t3) => {
|
|
6267
|
-
|
|
6268
|
-
}),
|
|
6269
|
-
} catch (
|
|
6270
|
-
const t3 = this.chapterStatus.get(
|
|
6331
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
6332
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
6333
|
+
} catch (h2) {
|
|
6334
|
+
const t3 = this.chapterStatus.get(a2);
|
|
6271
6335
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
6272
|
-
const t4 =
|
|
6273
|
-
this.logger.error(e10.id, "LoadChapter", t4,
|
|
6336
|
+
const t4 = h2 instanceof Error ? h2.message : `Failed to load chapter "${a2}"`;
|
|
6337
|
+
this.logger.error(e10.id, "LoadChapter", t4, h2), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", t4);
|
|
6274
6338
|
}
|
|
6275
|
-
return this.chapterStatus.get(
|
|
6339
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
6276
6340
|
}
|
|
6277
6341
|
}
|
|
6278
6342
|
waitForTerminalStatus(e14) {
|
|
@@ -6684,12 +6748,17 @@ const sa = class e11 extends BasePlugin {
|
|
|
6684
6748
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
6685
6749
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
6686
6750
|
const s2 = this.findChapter(e15.chapterId);
|
|
6687
|
-
if (s2)
|
|
6688
|
-
|
|
6689
|
-
|
|
6690
|
-
|
|
6691
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
6751
|
+
if (!s2) continue;
|
|
6752
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
6753
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
6754
|
+
continue;
|
|
6692
6755
|
}
|
|
6756
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
6757
|
+
let n9 = false;
|
|
6758
|
+
const r2 = () => {
|
|
6759
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
6760
|
+
};
|
|
6761
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
6693
6762
|
}
|
|
6694
6763
|
}
|
|
6695
6764
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -6779,21 +6848,21 @@ const sa = class e11 extends BasePlugin {
|
|
|
6779
6848
|
ensureSegmentLoaded(e14, t2) {
|
|
6780
6849
|
return this.loadSegmentNow(e14, t2);
|
|
6781
6850
|
}
|
|
6782
|
-
loadSegmentNow(e14, t2) {
|
|
6851
|
+
loadSegmentNow(e14, t2, s2) {
|
|
6783
6852
|
this.prepareChapterForSegmentLoad(e14);
|
|
6784
|
-
const
|
|
6785
|
-
if (!
|
|
6786
|
-
const
|
|
6787
|
-
if (!
|
|
6788
|
-
if (t2 < 0 || t2 >=
|
|
6789
|
-
const
|
|
6790
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
6791
|
-
const
|
|
6792
|
-
if (
|
|
6793
|
-
const
|
|
6794
|
-
this.pendingSegmentLoadPromises.delete(
|
|
6853
|
+
const n9 = this.findChapter(e14);
|
|
6854
|
+
if (!n9) return Promise.resolve("error");
|
|
6855
|
+
const r2 = jr(n9);
|
|
6856
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
6857
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
6858
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
6859
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
6860
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
6861
|
+
if (o2) return o2;
|
|
6862
|
+
const l = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
6863
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
6795
6864
|
});
|
|
6796
|
-
return this.pendingSegmentLoadPromises.set(
|
|
6865
|
+
return this.pendingSegmentLoadPromises.set(i2, l), l;
|
|
6797
6866
|
}
|
|
6798
6867
|
ensureSingleDocumentChapter(e14) {
|
|
6799
6868
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -6867,24 +6936,27 @@ const sa = class e11 extends BasePlugin {
|
|
|
6867
6936
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(t2, s2);
|
|
6868
6937
|
throw new Error(`Chapter "${t2.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
6869
6938
|
}
|
|
6870
|
-
async startLoadSegment(t2, s2) {
|
|
6871
|
-
var
|
|
6872
|
-
const
|
|
6873
|
-
|
|
6939
|
+
async startLoadSegment(t2, s2, n9) {
|
|
6940
|
+
var r2;
|
|
6941
|
+
const a2 = t2.chapterId, i2 = (null == s2 ? void 0 : s2.index) ?? 0, o2 = (null == s2 ? void 0 : s2.documentId) ?? a2;
|
|
6942
|
+
let l = false;
|
|
6943
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
6874
6944
|
try {
|
|
6875
|
-
const e14 = t2.encrypted && (null == (
|
|
6876
|
-
|
|
6945
|
+
const e14 = t2.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, h2 = await this.resolvePdfPayload(t2, i2), d2 = this.documentManager.provides(), c2 = "url" in h2 ? d2.openDocumentUrl({ documentId: o2, url: h2.url, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: h2.buffer, name: s2 ? `${t2.title} (${s2.index + 1})` : t2.title, password: e14 ?? void 0, autoActivate: false });
|
|
6946
|
+
l || (l = true, null == n9 || n9());
|
|
6947
|
+
const u2 = await new Promise((e15, t3) => {
|
|
6948
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
6877
6949
|
});
|
|
6878
6950
|
return await new Promise((e15, t3) => {
|
|
6879
|
-
|
|
6880
|
-
}),
|
|
6881
|
-
} catch (
|
|
6882
|
-
const t3 = this.chapterStatus.get(
|
|
6951
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
6952
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
6953
|
+
} catch (h2) {
|
|
6954
|
+
const t3 = this.chapterStatus.get(a2);
|
|
6883
6955
|
if ("loaded" !== t3 && "password-required" !== t3) {
|
|
6884
|
-
const t4 =
|
|
6885
|
-
this.logger.error(e11.id, "LoadChapter", t4,
|
|
6956
|
+
const t4 = h2 instanceof Error ? h2.message : `Failed to load chapter "${a2}"`;
|
|
6957
|
+
this.logger.error(e11.id, "LoadChapter", t4, h2), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", t4);
|
|
6886
6958
|
}
|
|
6887
|
-
return this.chapterStatus.get(
|
|
6959
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
6888
6960
|
}
|
|
6889
6961
|
}
|
|
6890
6962
|
waitForTerminalStatus(e14) {
|
|
@@ -8040,12 +8112,17 @@ const B = class n extends BasePlugin {
|
|
|
8040
8112
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
8041
8113
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
8042
8114
|
const s2 = this.findChapter(e15.chapterId);
|
|
8043
|
-
if (s2)
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
8115
|
+
if (!s2) continue;
|
|
8116
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
8117
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
8118
|
+
continue;
|
|
8048
8119
|
}
|
|
8120
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
8121
|
+
let n9 = false;
|
|
8122
|
+
const r2 = () => {
|
|
8123
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
8124
|
+
};
|
|
8125
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
8049
8126
|
}
|
|
8050
8127
|
}
|
|
8051
8128
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -8135,21 +8212,21 @@ const B = class n extends BasePlugin {
|
|
|
8135
8212
|
ensureSegmentLoaded(e14, t2) {
|
|
8136
8213
|
return this.loadSegmentNow(e14, t2);
|
|
8137
8214
|
}
|
|
8138
|
-
loadSegmentNow(e14, t2) {
|
|
8215
|
+
loadSegmentNow(e14, t2, s2) {
|
|
8139
8216
|
this.prepareChapterForSegmentLoad(e14);
|
|
8140
|
-
const
|
|
8141
|
-
if (!
|
|
8142
|
-
const
|
|
8143
|
-
if (!
|
|
8144
|
-
if (t2 < 0 || t2 >=
|
|
8145
|
-
const
|
|
8146
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
8147
|
-
const
|
|
8148
|
-
if (
|
|
8149
|
-
const
|
|
8150
|
-
this.pendingSegmentLoadPromises.delete(
|
|
8217
|
+
const n9 = this.findChapter(e14);
|
|
8218
|
+
if (!n9) return Promise.resolve("error");
|
|
8219
|
+
const r2 = E(n9);
|
|
8220
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
8221
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
8222
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
8223
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
8224
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
8225
|
+
if (o2) return o2;
|
|
8226
|
+
const h2 = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
8227
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
8151
8228
|
});
|
|
8152
|
-
return this.pendingSegmentLoadPromises.set(
|
|
8229
|
+
return this.pendingSegmentLoadPromises.set(i2, h2), h2;
|
|
8153
8230
|
}
|
|
8154
8231
|
ensureSingleDocumentChapter(e14) {
|
|
8155
8232
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -8223,24 +8300,27 @@ const B = class n extends BasePlugin {
|
|
|
8223
8300
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(e14, t2);
|
|
8224
8301
|
throw new Error(`Chapter "${e14.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
8225
8302
|
}
|
|
8226
|
-
async startLoadSegment(e14, t2) {
|
|
8227
|
-
var
|
|
8228
|
-
const
|
|
8229
|
-
|
|
8303
|
+
async startLoadSegment(e14, t2, s2) {
|
|
8304
|
+
var r2;
|
|
8305
|
+
const a2 = e14.chapterId, i2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? a2;
|
|
8306
|
+
let h2 = false;
|
|
8307
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
8230
8308
|
try {
|
|
8231
|
-
const n9 = e14.encrypted && (null == (
|
|
8232
|
-
|
|
8309
|
+
const n9 = e14.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, l = await this.resolvePdfPayload(e14, i2), d2 = this.documentManager.provides(), c2 = "url" in l ? d2.openDocumentUrl({ documentId: o2, url: l.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: l.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false });
|
|
8310
|
+
h2 || (h2 = true, null == s2 || s2());
|
|
8311
|
+
const u2 = await new Promise((e15, t3) => {
|
|
8312
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
8233
8313
|
});
|
|
8234
8314
|
return await new Promise((e15, t3) => {
|
|
8235
|
-
|
|
8236
|
-
}),
|
|
8237
|
-
} catch (
|
|
8238
|
-
const e15 = this.chapterStatus.get(
|
|
8315
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
8316
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
8317
|
+
} catch (l) {
|
|
8318
|
+
const e15 = this.chapterStatus.get(a2);
|
|
8239
8319
|
if ("loaded" !== e15 && "password-required" !== e15) {
|
|
8240
|
-
const e16 =
|
|
8241
|
-
this.logger.error(n.id, "LoadChapter", e16,
|
|
8320
|
+
const e16 = l instanceof Error ? l.message : `Failed to load chapter "${a2}"`;
|
|
8321
|
+
this.logger.error(n.id, "LoadChapter", e16, l), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", e16);
|
|
8242
8322
|
}
|
|
8243
|
-
return this.chapterStatus.get(
|
|
8323
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
8244
8324
|
}
|
|
8245
8325
|
}
|
|
8246
8326
|
waitForTerminalStatus(e14) {
|
|
@@ -8652,12 +8732,17 @@ const ce = class n2 extends BasePlugin {
|
|
|
8652
8732
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
8653
8733
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
8654
8734
|
const s2 = this.findChapter(e15.chapterId);
|
|
8655
|
-
if (s2)
|
|
8656
|
-
|
|
8657
|
-
|
|
8658
|
-
|
|
8659
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
8735
|
+
if (!s2) continue;
|
|
8736
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
8737
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
8738
|
+
continue;
|
|
8660
8739
|
}
|
|
8740
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
8741
|
+
let n9 = false;
|
|
8742
|
+
const r2 = () => {
|
|
8743
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
8744
|
+
};
|
|
8745
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
8661
8746
|
}
|
|
8662
8747
|
}
|
|
8663
8748
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -8747,21 +8832,21 @@ const ce = class n2 extends BasePlugin {
|
|
|
8747
8832
|
ensureSegmentLoaded(e14, t2) {
|
|
8748
8833
|
return this.loadSegmentNow(e14, t2);
|
|
8749
8834
|
}
|
|
8750
|
-
loadSegmentNow(e14, t2) {
|
|
8835
|
+
loadSegmentNow(e14, t2, s2) {
|
|
8751
8836
|
this.prepareChapterForSegmentLoad(e14);
|
|
8752
|
-
const
|
|
8753
|
-
if (!
|
|
8754
|
-
const
|
|
8755
|
-
if (!
|
|
8756
|
-
if (t2 < 0 || t2 >=
|
|
8757
|
-
const
|
|
8758
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
8759
|
-
const
|
|
8760
|
-
if (
|
|
8761
|
-
const
|
|
8762
|
-
this.pendingSegmentLoadPromises.delete(
|
|
8837
|
+
const n9 = this.findChapter(e14);
|
|
8838
|
+
if (!n9) return Promise.resolve("error");
|
|
8839
|
+
const r2 = ne(n9);
|
|
8840
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
8841
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
8842
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
8843
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
8844
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
8845
|
+
if (o2) return o2;
|
|
8846
|
+
const h2 = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
8847
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
8763
8848
|
});
|
|
8764
|
-
return this.pendingSegmentLoadPromises.set(
|
|
8849
|
+
return this.pendingSegmentLoadPromises.set(i2, h2), h2;
|
|
8765
8850
|
}
|
|
8766
8851
|
ensureSingleDocumentChapter(e14) {
|
|
8767
8852
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -8835,24 +8920,27 @@ const ce = class n2 extends BasePlugin {
|
|
|
8835
8920
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(e14, t2);
|
|
8836
8921
|
throw new Error(`Chapter "${e14.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
8837
8922
|
}
|
|
8838
|
-
async startLoadSegment(e14, t2) {
|
|
8839
|
-
var
|
|
8840
|
-
const
|
|
8841
|
-
|
|
8923
|
+
async startLoadSegment(e14, t2, s2) {
|
|
8924
|
+
var r2;
|
|
8925
|
+
const a2 = e14.chapterId, i2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? a2;
|
|
8926
|
+
let h2 = false;
|
|
8927
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
8842
8928
|
try {
|
|
8843
|
-
const n9 = e14.encrypted && (null == (
|
|
8844
|
-
|
|
8929
|
+
const n9 = e14.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, l = await this.resolvePdfPayload(e14, i2), d2 = this.documentManager.provides(), c2 = "url" in l ? d2.openDocumentUrl({ documentId: o2, url: l.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: l.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false });
|
|
8930
|
+
h2 || (h2 = true, null == s2 || s2());
|
|
8931
|
+
const u2 = await new Promise((e15, t3) => {
|
|
8932
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
8845
8933
|
});
|
|
8846
8934
|
return await new Promise((e15, t3) => {
|
|
8847
|
-
|
|
8848
|
-
}),
|
|
8849
|
-
} catch (
|
|
8850
|
-
const e15 = this.chapterStatus.get(
|
|
8935
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
8936
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
8937
|
+
} catch (l) {
|
|
8938
|
+
const e15 = this.chapterStatus.get(a2);
|
|
8851
8939
|
if ("loaded" !== e15 && "password-required" !== e15) {
|
|
8852
|
-
const e16 =
|
|
8853
|
-
this.logger.error(n2.id, "LoadChapter", e16,
|
|
8940
|
+
const e16 = l instanceof Error ? l.message : `Failed to load chapter "${a2}"`;
|
|
8941
|
+
this.logger.error(n2.id, "LoadChapter", e16, l), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", e16);
|
|
8854
8942
|
}
|
|
8855
|
-
return this.chapterStatus.get(
|
|
8943
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
8856
8944
|
}
|
|
8857
8945
|
}
|
|
8858
8946
|
waitForTerminalStatus(e14) {
|
|
@@ -9452,12 +9540,17 @@ const Ee = class n3 extends BasePlugin {
|
|
|
9452
9540
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
9453
9541
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
9454
9542
|
const s2 = this.findChapter(e15.chapterId);
|
|
9455
|
-
if (s2)
|
|
9456
|
-
|
|
9457
|
-
|
|
9458
|
-
|
|
9459
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
9543
|
+
if (!s2) continue;
|
|
9544
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
9545
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
9546
|
+
continue;
|
|
9460
9547
|
}
|
|
9548
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
9549
|
+
let n9 = false;
|
|
9550
|
+
const r2 = () => {
|
|
9551
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
9552
|
+
};
|
|
9553
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
9461
9554
|
}
|
|
9462
9555
|
}
|
|
9463
9556
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -9547,21 +9640,21 @@ const Ee = class n3 extends BasePlugin {
|
|
|
9547
9640
|
ensureSegmentLoaded(e14, t2) {
|
|
9548
9641
|
return this.loadSegmentNow(e14, t2);
|
|
9549
9642
|
}
|
|
9550
|
-
loadSegmentNow(e14, t2) {
|
|
9643
|
+
loadSegmentNow(e14, t2, s2) {
|
|
9551
9644
|
this.prepareChapterForSegmentLoad(e14);
|
|
9552
|
-
const
|
|
9553
|
-
if (!
|
|
9554
|
-
const
|
|
9555
|
-
if (!
|
|
9556
|
-
if (t2 < 0 || t2 >=
|
|
9557
|
-
const
|
|
9558
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
9559
|
-
const
|
|
9560
|
-
if (
|
|
9561
|
-
const
|
|
9562
|
-
this.pendingSegmentLoadPromises.delete(
|
|
9645
|
+
const n9 = this.findChapter(e14);
|
|
9646
|
+
if (!n9) return Promise.resolve("error");
|
|
9647
|
+
const r2 = Me(n9);
|
|
9648
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
9649
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
9650
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
9651
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
9652
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
9653
|
+
if (o2) return o2;
|
|
9654
|
+
const h2 = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
9655
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
9563
9656
|
});
|
|
9564
|
-
return this.pendingSegmentLoadPromises.set(
|
|
9657
|
+
return this.pendingSegmentLoadPromises.set(i2, h2), h2;
|
|
9565
9658
|
}
|
|
9566
9659
|
ensureSingleDocumentChapter(e14) {
|
|
9567
9660
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -9635,24 +9728,27 @@ const Ee = class n3 extends BasePlugin {
|
|
|
9635
9728
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(e14, t2);
|
|
9636
9729
|
throw new Error(`Chapter "${e14.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
9637
9730
|
}
|
|
9638
|
-
async startLoadSegment(e14, t2) {
|
|
9639
|
-
var
|
|
9640
|
-
const
|
|
9641
|
-
|
|
9731
|
+
async startLoadSegment(e14, t2, s2) {
|
|
9732
|
+
var r2;
|
|
9733
|
+
const a2 = e14.chapterId, i2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? a2;
|
|
9734
|
+
let h2 = false;
|
|
9735
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
9642
9736
|
try {
|
|
9643
|
-
const n9 = e14.encrypted && (null == (
|
|
9644
|
-
|
|
9737
|
+
const n9 = e14.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, l = await this.resolvePdfPayload(e14, i2), d2 = this.documentManager.provides(), c2 = "url" in l ? d2.openDocumentUrl({ documentId: o2, url: l.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: l.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false });
|
|
9738
|
+
h2 || (h2 = true, null == s2 || s2());
|
|
9739
|
+
const u2 = await new Promise((e15, t3) => {
|
|
9740
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
9645
9741
|
});
|
|
9646
9742
|
return await new Promise((e15, t3) => {
|
|
9647
|
-
|
|
9648
|
-
}),
|
|
9649
|
-
} catch (
|
|
9650
|
-
const e15 = this.chapterStatus.get(
|
|
9743
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
9744
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
9745
|
+
} catch (l) {
|
|
9746
|
+
const e15 = this.chapterStatus.get(a2);
|
|
9651
9747
|
if ("loaded" !== e15 && "password-required" !== e15) {
|
|
9652
|
-
const e16 =
|
|
9653
|
-
this.logger.error(n3.id, "LoadChapter", e16,
|
|
9748
|
+
const e16 = l instanceof Error ? l.message : `Failed to load chapter "${a2}"`;
|
|
9749
|
+
this.logger.error(n3.id, "LoadChapter", e16, l), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", e16);
|
|
9654
9750
|
}
|
|
9655
|
-
return this.chapterStatus.get(
|
|
9751
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
9656
9752
|
}
|
|
9657
9753
|
}
|
|
9658
9754
|
waitForTerminalStatus(e14) {
|
|
@@ -10064,12 +10160,17 @@ const et2 = class n4 extends BasePlugin {
|
|
|
10064
10160
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
10065
10161
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
10066
10162
|
const s2 = this.findChapter(e15.chapterId);
|
|
10067
|
-
if (s2)
|
|
10068
|
-
|
|
10069
|
-
|
|
10070
|
-
|
|
10071
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
10163
|
+
if (!s2) continue;
|
|
10164
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
10165
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
10166
|
+
continue;
|
|
10072
10167
|
}
|
|
10168
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
10169
|
+
let n9 = false;
|
|
10170
|
+
const r2 = () => {
|
|
10171
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
10172
|
+
};
|
|
10173
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
10073
10174
|
}
|
|
10074
10175
|
}
|
|
10075
10176
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -10159,21 +10260,21 @@ const et2 = class n4 extends BasePlugin {
|
|
|
10159
10260
|
ensureSegmentLoaded(e14, t2) {
|
|
10160
10261
|
return this.loadSegmentNow(e14, t2);
|
|
10161
10262
|
}
|
|
10162
|
-
loadSegmentNow(e14, t2) {
|
|
10263
|
+
loadSegmentNow(e14, t2, s2) {
|
|
10163
10264
|
this.prepareChapterForSegmentLoad(e14);
|
|
10164
|
-
const
|
|
10165
|
-
if (!
|
|
10166
|
-
const
|
|
10167
|
-
if (!
|
|
10168
|
-
if (t2 < 0 || t2 >=
|
|
10169
|
-
const
|
|
10170
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
10171
|
-
const
|
|
10172
|
-
if (
|
|
10173
|
-
const
|
|
10174
|
-
this.pendingSegmentLoadPromises.delete(
|
|
10265
|
+
const n9 = this.findChapter(e14);
|
|
10266
|
+
if (!n9) return Promise.resolve("error");
|
|
10267
|
+
const r2 = Ke(n9);
|
|
10268
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
10269
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
10270
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
10271
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
10272
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
10273
|
+
if (o2) return o2;
|
|
10274
|
+
const h2 = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
10275
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
10175
10276
|
});
|
|
10176
|
-
return this.pendingSegmentLoadPromises.set(
|
|
10277
|
+
return this.pendingSegmentLoadPromises.set(i2, h2), h2;
|
|
10177
10278
|
}
|
|
10178
10279
|
ensureSingleDocumentChapter(e14) {
|
|
10179
10280
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -10247,24 +10348,27 @@ const et2 = class n4 extends BasePlugin {
|
|
|
10247
10348
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(e14, t2);
|
|
10248
10349
|
throw new Error(`Chapter "${e14.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
10249
10350
|
}
|
|
10250
|
-
async startLoadSegment(e14, t2) {
|
|
10251
|
-
var
|
|
10252
|
-
const
|
|
10253
|
-
|
|
10351
|
+
async startLoadSegment(e14, t2, s2) {
|
|
10352
|
+
var r2;
|
|
10353
|
+
const a2 = e14.chapterId, i2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? a2;
|
|
10354
|
+
let h2 = false;
|
|
10355
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
10254
10356
|
try {
|
|
10255
|
-
const n9 = e14.encrypted && (null == (
|
|
10256
|
-
|
|
10357
|
+
const n9 = e14.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, l = await this.resolvePdfPayload(e14, i2), d2 = this.documentManager.provides(), c2 = "url" in l ? d2.openDocumentUrl({ documentId: o2, url: l.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: l.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false });
|
|
10358
|
+
h2 || (h2 = true, null == s2 || s2());
|
|
10359
|
+
const u2 = await new Promise((e15, t3) => {
|
|
10360
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
10257
10361
|
});
|
|
10258
10362
|
return await new Promise((e15, t3) => {
|
|
10259
|
-
|
|
10260
|
-
}),
|
|
10261
|
-
} catch (
|
|
10262
|
-
const e15 = this.chapterStatus.get(
|
|
10363
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
10364
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
10365
|
+
} catch (l) {
|
|
10366
|
+
const e15 = this.chapterStatus.get(a2);
|
|
10263
10367
|
if ("loaded" !== e15 && "password-required" !== e15) {
|
|
10264
|
-
const e16 =
|
|
10265
|
-
this.logger.error(n4.id, "LoadChapter", e16,
|
|
10368
|
+
const e16 = l instanceof Error ? l.message : `Failed to load chapter "${a2}"`;
|
|
10369
|
+
this.logger.error(n4.id, "LoadChapter", e16, l), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", e16);
|
|
10266
10370
|
}
|
|
10267
|
-
return this.chapterStatus.get(
|
|
10371
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
10268
10372
|
}
|
|
10269
10373
|
}
|
|
10270
10374
|
waitForTerminalStatus(e14) {
|
|
@@ -10979,12 +11083,17 @@ const Mt = class n6 extends BasePlugin {
|
|
|
10979
11083
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
10980
11084
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
10981
11085
|
const s2 = this.findChapter(e15.chapterId);
|
|
10982
|
-
if (s2)
|
|
10983
|
-
|
|
10984
|
-
|
|
10985
|
-
|
|
10986
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
11086
|
+
if (!s2) continue;
|
|
11087
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
11088
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
11089
|
+
continue;
|
|
10987
11090
|
}
|
|
11091
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
11092
|
+
let n9 = false;
|
|
11093
|
+
const r2 = () => {
|
|
11094
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
11095
|
+
};
|
|
11096
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
10988
11097
|
}
|
|
10989
11098
|
}
|
|
10990
11099
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -11074,21 +11183,21 @@ const Mt = class n6 extends BasePlugin {
|
|
|
11074
11183
|
ensureSegmentLoaded(e14, t2) {
|
|
11075
11184
|
return this.loadSegmentNow(e14, t2);
|
|
11076
11185
|
}
|
|
11077
|
-
loadSegmentNow(e14, t2) {
|
|
11186
|
+
loadSegmentNow(e14, t2, s2) {
|
|
11078
11187
|
this.prepareChapterForSegmentLoad(e14);
|
|
11079
|
-
const
|
|
11080
|
-
if (!
|
|
11081
|
-
const
|
|
11082
|
-
if (!
|
|
11083
|
-
if (t2 < 0 || t2 >=
|
|
11084
|
-
const
|
|
11085
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
11086
|
-
const
|
|
11087
|
-
if (
|
|
11088
|
-
const
|
|
11089
|
-
this.pendingSegmentLoadPromises.delete(
|
|
11188
|
+
const n9 = this.findChapter(e14);
|
|
11189
|
+
if (!n9) return Promise.resolve("error");
|
|
11190
|
+
const r2 = vt(n9);
|
|
11191
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
11192
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
11193
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
11194
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
11195
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
11196
|
+
if (o2) return o2;
|
|
11197
|
+
const h2 = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
11198
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
11090
11199
|
});
|
|
11091
|
-
return this.pendingSegmentLoadPromises.set(
|
|
11200
|
+
return this.pendingSegmentLoadPromises.set(i2, h2), h2;
|
|
11092
11201
|
}
|
|
11093
11202
|
ensureSingleDocumentChapter(e14) {
|
|
11094
11203
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -11162,24 +11271,27 @@ const Mt = class n6 extends BasePlugin {
|
|
|
11162
11271
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(e14, t2);
|
|
11163
11272
|
throw new Error(`Chapter "${e14.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
11164
11273
|
}
|
|
11165
|
-
async startLoadSegment(e14, t2) {
|
|
11166
|
-
var
|
|
11167
|
-
const
|
|
11168
|
-
|
|
11274
|
+
async startLoadSegment(e14, t2, s2) {
|
|
11275
|
+
var r2;
|
|
11276
|
+
const a2 = e14.chapterId, i2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? a2;
|
|
11277
|
+
let h2 = false;
|
|
11278
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
11169
11279
|
try {
|
|
11170
|
-
const n9 = e14.encrypted && (null == (
|
|
11171
|
-
|
|
11280
|
+
const n9 = e14.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, l = await this.resolvePdfPayload(e14, i2), d2 = this.documentManager.provides(), c2 = "url" in l ? d2.openDocumentUrl({ documentId: o2, url: l.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: l.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false });
|
|
11281
|
+
h2 || (h2 = true, null == s2 || s2());
|
|
11282
|
+
const u2 = await new Promise((e15, t3) => {
|
|
11283
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
11172
11284
|
});
|
|
11173
11285
|
return await new Promise((e15, t3) => {
|
|
11174
|
-
|
|
11175
|
-
}),
|
|
11176
|
-
} catch (
|
|
11177
|
-
const e15 = this.chapterStatus.get(
|
|
11286
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
11287
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
11288
|
+
} catch (l) {
|
|
11289
|
+
const e15 = this.chapterStatus.get(a2);
|
|
11178
11290
|
if ("loaded" !== e15 && "password-required" !== e15) {
|
|
11179
|
-
const e16 =
|
|
11180
|
-
this.logger.error(n6.id, "LoadChapter", e16,
|
|
11291
|
+
const e16 = l instanceof Error ? l.message : `Failed to load chapter "${a2}"`;
|
|
11292
|
+
this.logger.error(n6.id, "LoadChapter", e16, l), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", e16);
|
|
11181
11293
|
}
|
|
11182
|
-
return this.chapterStatus.get(
|
|
11294
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
11183
11295
|
}
|
|
11184
11296
|
}
|
|
11185
11297
|
waitForTerminalStatus(e14) {
|
|
@@ -11591,12 +11703,17 @@ const Kt = class n7 extends BasePlugin {
|
|
|
11591
11703
|
if (this.isSegmentDocumentOpen(e15.chapterId, e15.segmentIndex)) continue;
|
|
11592
11704
|
if (this.isSegmentLoadPending(e15.chapterId, e15.segmentIndex)) continue;
|
|
11593
11705
|
const s2 = this.findChapter(e15.chapterId);
|
|
11594
|
-
if (s2)
|
|
11595
|
-
|
|
11596
|
-
|
|
11597
|
-
|
|
11598
|
-
else if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
11706
|
+
if (!s2) continue;
|
|
11707
|
+
if (!this.ensureVisibleChapterUrls(s2)) {
|
|
11708
|
+
if (this.visibleSegmentBacklog.push(e15), t2++, t2 >= this.visibleSegmentBacklog.length) break;
|
|
11709
|
+
continue;
|
|
11599
11710
|
}
|
|
11711
|
+
t2 = 0, this.prepareChapterForSegmentLoad(e15.chapterId), this.activeVisibleSegmentLoads++;
|
|
11712
|
+
let n9 = false;
|
|
11713
|
+
const r2 = () => {
|
|
11714
|
+
n9 || (n9 = true, this.activeVisibleSegmentLoads--, this.pumpVisibleSegmentBacklog());
|
|
11715
|
+
};
|
|
11716
|
+
this.loadSegmentNow(e15.chapterId, e15.segmentIndex, r2).finally(r2);
|
|
11600
11717
|
}
|
|
11601
11718
|
}
|
|
11602
11719
|
prepareChapterForSegmentLoad(e14) {
|
|
@@ -11686,21 +11803,21 @@ const Kt = class n7 extends BasePlugin {
|
|
|
11686
11803
|
ensureSegmentLoaded(e14, t2) {
|
|
11687
11804
|
return this.loadSegmentNow(e14, t2);
|
|
11688
11805
|
}
|
|
11689
|
-
loadSegmentNow(e14, t2) {
|
|
11806
|
+
loadSegmentNow(e14, t2, s2) {
|
|
11690
11807
|
this.prepareChapterForSegmentLoad(e14);
|
|
11691
|
-
const
|
|
11692
|
-
if (!
|
|
11693
|
-
const
|
|
11694
|
-
if (!
|
|
11695
|
-
if (t2 < 0 || t2 >=
|
|
11696
|
-
const
|
|
11697
|
-
if (this.documentManager.provides().isDocumentOpen(
|
|
11698
|
-
const
|
|
11699
|
-
if (
|
|
11700
|
-
const
|
|
11701
|
-
this.pendingSegmentLoadPromises.delete(
|
|
11808
|
+
const n9 = this.findChapter(e14);
|
|
11809
|
+
if (!n9) return Promise.resolve("error");
|
|
11810
|
+
const r2 = Ot(n9);
|
|
11811
|
+
if (!r2) return 0 !== t2 ? Promise.resolve(this.isSegmentDocumentOpen(e14, 0) ? "loaded" : "error") : this.ensureSingleDocumentChapter(n9);
|
|
11812
|
+
if (t2 < 0 || t2 >= r2.segments.length) return Promise.resolve("error");
|
|
11813
|
+
const a2 = r2.segments[t2], i2 = a2.documentId;
|
|
11814
|
+
if (this.documentManager.provides().isDocumentOpen(i2)) return this.chapterLastUsed.set(e14, Date.now()), 0 === t2 && this.syncChapterStatusFromDocuments(e14), Promise.resolve("loaded");
|
|
11815
|
+
const o2 = this.pendingSegmentLoadPromises.get(i2);
|
|
11816
|
+
if (o2) return o2;
|
|
11817
|
+
const h2 = this.startLoadSegment(n9, a2, s2).finally(() => {
|
|
11818
|
+
this.pendingSegmentLoadPromises.delete(i2);
|
|
11702
11819
|
});
|
|
11703
|
-
return this.pendingSegmentLoadPromises.set(
|
|
11820
|
+
return this.pendingSegmentLoadPromises.set(i2, h2), h2;
|
|
11704
11821
|
}
|
|
11705
11822
|
ensureSingleDocumentChapter(e14) {
|
|
11706
11823
|
const t2 = e14.chapterId, s2 = this.pendingChapterLoadPromises.get(t2);
|
|
@@ -11774,24 +11891,27 @@ const Kt = class n7 extends BasePlugin {
|
|
|
11774
11891
|
if (null == r2 ? void 0 : r2.loadPdf) return r2.loadPdf(e14, t2);
|
|
11775
11892
|
throw new Error(`Chapter "${e14.chapterId}" has no PDF source; configure source or chapterPdfLoader`);
|
|
11776
11893
|
}
|
|
11777
|
-
async startLoadSegment(e14, t2) {
|
|
11778
|
-
var
|
|
11779
|
-
const
|
|
11780
|
-
|
|
11894
|
+
async startLoadSegment(e14, t2, s2) {
|
|
11895
|
+
var r2;
|
|
11896
|
+
const a2 = e14.chapterId, i2 = (null == t2 ? void 0 : t2.index) ?? 0, o2 = (null == t2 ? void 0 : t2.documentId) ?? a2;
|
|
11897
|
+
let h2 = false;
|
|
11898
|
+
this.chapterErrorMessages.delete(a2), this.anySegmentOpen(a2) || this.updateStatus(a2, "loading"), this.chapterLastUsed.set(a2, Date.now());
|
|
11781
11899
|
try {
|
|
11782
|
-
const n9 = e14.encrypted && (null == (
|
|
11783
|
-
|
|
11900
|
+
const n9 = e14.encrypted && (null == (r2 = this.passwordProvider) ? void 0 : r2.getCachedPassword) ? this.passwordProvider.getCachedPassword(a2) : null, l = await this.resolvePdfPayload(e14, i2), d2 = this.documentManager.provides(), c2 = "url" in l ? d2.openDocumentUrl({ documentId: o2, url: l.url, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false }) : d2.openDocumentBuffer({ documentId: o2, buffer: l.buffer, name: t2 ? `${e14.title} (${t2.index + 1})` : e14.title, password: n9 ?? void 0, autoActivate: false });
|
|
11901
|
+
h2 || (h2 = true, null == s2 || s2());
|
|
11902
|
+
const u2 = await new Promise((e15, t3) => {
|
|
11903
|
+
c2.wait((t4) => e15(t4), (e16) => t3(e16));
|
|
11784
11904
|
});
|
|
11785
11905
|
return await new Promise((e15, t3) => {
|
|
11786
|
-
|
|
11787
|
-
}),
|
|
11788
|
-
} catch (
|
|
11789
|
-
const e15 = this.chapterStatus.get(
|
|
11906
|
+
u2.task.wait(() => e15(), (e16) => t3(e16));
|
|
11907
|
+
}), d2.isDocumentOpen(o2) && this.syncChapterStatusFromDocuments(a2), this.waitForTerminalStatus(a2);
|
|
11908
|
+
} catch (l) {
|
|
11909
|
+
const e15 = this.chapterStatus.get(a2);
|
|
11790
11910
|
if ("loaded" !== e15 && "password-required" !== e15) {
|
|
11791
|
-
const e16 =
|
|
11792
|
-
this.logger.error(n7.id, "LoadChapter", e16,
|
|
11911
|
+
const e16 = l instanceof Error ? l.message : `Failed to load chapter "${a2}"`;
|
|
11912
|
+
this.logger.error(n7.id, "LoadChapter", e16, l), 0 !== i2 || this.isAnySegmentWorkPending(a2) || this.updateStatus(a2, "error", e16);
|
|
11793
11913
|
}
|
|
11794
|
-
return this.chapterStatus.get(
|
|
11914
|
+
return this.chapterStatus.get(a2) ?? "error";
|
|
11795
11915
|
}
|
|
11796
11916
|
}
|
|
11797
11917
|
waitForTerminalStatus(e14) {
|
|
@@ -12901,10 +13021,14 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
|
12901
13021
|
stalled = 0;
|
|
12902
13022
|
this.prepareChapterForSegmentLoad(t2.chapterId);
|
|
12903
13023
|
this.activeVisibleSegmentLoads++;
|
|
12904
|
-
|
|
13024
|
+
let released = false;
|
|
13025
|
+
const releaseSlot = () => {
|
|
13026
|
+
if (released) return;
|
|
13027
|
+
released = true;
|
|
12905
13028
|
this.activeVisibleSegmentLoads--;
|
|
12906
13029
|
this.pumpVisibleSegmentBacklog();
|
|
12907
|
-
}
|
|
13030
|
+
};
|
|
13031
|
+
void this.loadSegmentNow(t2.chapterId, t2.segmentIndex, releaseSlot).finally(releaseSlot);
|
|
12908
13032
|
}
|
|
12909
13033
|
}
|
|
12910
13034
|
prepareChapterForSegmentLoad(chapterId) {
|
|
@@ -13026,7 +13150,7 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
|
13026
13150
|
ensureSegmentLoaded(chapterId, segmentIndex) {
|
|
13027
13151
|
return this.loadSegmentNow(chapterId, segmentIndex);
|
|
13028
13152
|
}
|
|
13029
|
-
loadSegmentNow(chapterId, segmentIndex) {
|
|
13153
|
+
loadSegmentNow(chapterId, segmentIndex, onDispatched) {
|
|
13030
13154
|
this.prepareChapterForSegmentLoad(chapterId);
|
|
13031
13155
|
const chapter = this.findChapter(chapterId);
|
|
13032
13156
|
if (!chapter) return Promise.resolve("error");
|
|
@@ -13050,7 +13174,7 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
|
13050
13174
|
}
|
|
13051
13175
|
const existing = this.pendingSegmentLoadPromises.get(documentId);
|
|
13052
13176
|
if (existing) return existing;
|
|
13053
|
-
const promise = this.startLoadSegment(chapter, segment).finally(() => {
|
|
13177
|
+
const promise = this.startLoadSegment(chapter, segment, onDispatched).finally(() => {
|
|
13054
13178
|
this.pendingSegmentLoadPromises.delete(documentId);
|
|
13055
13179
|
});
|
|
13056
13180
|
this.pendingSegmentLoadPromises.set(documentId, promise);
|
|
@@ -13175,11 +13299,17 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
|
13175
13299
|
`Chapter "${chapter.chapterId}" has no PDF source; configure source or chapterPdfLoader`
|
|
13176
13300
|
);
|
|
13177
13301
|
}
|
|
13178
|
-
async startLoadSegment(chapter, segment) {
|
|
13302
|
+
async startLoadSegment(chapter, segment, onDispatched) {
|
|
13179
13303
|
var _a2;
|
|
13180
13304
|
const chapterId = chapter.chapterId;
|
|
13181
13305
|
const segmentIndex = (segment == null ? void 0 : segment.index) ?? 0;
|
|
13182
13306
|
const documentId = (segment == null ? void 0 : segment.documentId) ?? chapterId;
|
|
13307
|
+
let dispatched = false;
|
|
13308
|
+
const markDispatched = () => {
|
|
13309
|
+
if (dispatched) return;
|
|
13310
|
+
dispatched = true;
|
|
13311
|
+
onDispatched == null ? void 0 : onDispatched();
|
|
13312
|
+
};
|
|
13183
13313
|
this.chapterErrorMessages.delete(chapterId);
|
|
13184
13314
|
if (!this.anySegmentOpen(chapterId)) {
|
|
13185
13315
|
this.updateStatus(chapterId, "loading");
|
|
@@ -13202,6 +13332,7 @@ const _ChapterManagerPlugin = class _ChapterManagerPlugin2 extends BasePlugin {
|
|
|
13202
13332
|
password: cachedPwd ?? void 0,
|
|
13203
13333
|
autoActivate: false
|
|
13204
13334
|
});
|
|
13335
|
+
markDispatched();
|
|
13205
13336
|
const openResult = await new Promise((resolve, reject) => {
|
|
13206
13337
|
openTask.wait((res) => resolve(res), (err) => reject(err));
|
|
13207
13338
|
});
|