Reader.vue 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. <template>
  2. <div class="column no-wrap">
  3. <div v-show="toolBarActive" ref="header" class="header">
  4. <div ref="buttons" class="row justify-between no-wrap">
  5. <div class="row no-wrap">
  6. <button ref="loader" v-ripple class="tool-button" :class="buttonActiveClass('loader')" @click="buttonClick('loader')">
  7. <q-icon name="la la-arrow-left" size="32px" />
  8. <q-tooltip :delay="1500" anchor="bottom right" content-style="font-size: 80%">
  9. {{ rstore.readerActions['loader'] }}
  10. </q-tooltip>
  11. </button>
  12. <button v-show="showToolButton['loadFile']" ref="loadFile" v-ripple class="tool-button" :class="buttonActiveClass('loadFile')" @click="buttonClick('loadFile')">
  13. <q-icon name="la la-caret-square-up" size="32px" />
  14. <q-tooltip :delay="1500" anchor="bottom right" content-style="font-size: 80%">
  15. {{ rstore.readerActions['loadFile'] }}
  16. </q-tooltip>
  17. </button>
  18. <button v-show="showToolButton['loadBuffer']" ref="loadBuffer" v-ripple class="tool-button" :class="buttonActiveClass('loadBuffer')" @click="buttonClick('loadBuffer')">
  19. <q-icon name="la la-comment" size="32px" />
  20. <q-tooltip :delay="1500" anchor="bottom right" content-style="font-size: 80%">
  21. {{ rstore.readerActions['loadBuffer'] }}
  22. </q-tooltip>
  23. </button>
  24. <button v-show="showToolButton['help']" ref="help" v-ripple class="tool-button" :class="buttonActiveClass('help')" @click="buttonClick('help')">
  25. <q-icon name="la la-question" size="32px" />
  26. <q-tooltip :delay="1500" anchor="bottom right" content-style="font-size: 80%">
  27. {{ rstore.readerActions['help'] }}
  28. </q-tooltip>
  29. </button>
  30. </div>
  31. <div class="row no-wrap">
  32. <div class="space"></div>
  33. <button v-show="showToolButton['undoAction']" ref="undoAction" v-ripple class="tool-button" :class="buttonActiveClass('undoAction')" @click="buttonClick('undoAction')">
  34. <q-icon name="la la-angle-left" size="32px" />
  35. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  36. {{ rstore.readerActions['undoAction'] }}
  37. </q-tooltip>
  38. </button>
  39. <button v-show="showToolButton['redoAction']" ref="redoAction" v-ripple class="tool-button" :class="buttonActiveClass('redoAction')" @click="buttonClick('redoAction')">
  40. <q-icon name="la la-angle-right" size="32px" />
  41. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  42. {{ rstore.readerActions['redoAction'] }}
  43. </q-tooltip>
  44. </button>
  45. <div class="space"></div>
  46. <button v-show="showToolButton['fullScreen']" ref="fullScreen" v-ripple class="tool-button" :class="buttonActiveClass('fullScreen')" @click="buttonClick('fullScreen')">
  47. <q-icon :name="(fullScreenActive ? 'la la-compress-arrows-alt': 'la la-expand-arrows-alt')" size="32px" />
  48. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  49. {{ rstore.readerActions['fullScreen'] }}
  50. </q-tooltip>
  51. </button>
  52. <button v-show="showToolButton['scrolling']" ref="scrolling" v-ripple class="tool-button" :class="buttonActiveClass('scrolling')" @click="buttonClick('scrolling')">
  53. <q-icon name="la la-film" size="32px" />
  54. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  55. {{ rstore.readerActions['scrolling'] }}
  56. </q-tooltip>
  57. </button>
  58. <button v-show="showToolButton['setPosition']" ref="setPosition" v-ripple class="tool-button" :class="buttonActiveClass('setPosition')" @click="buttonClick('setPosition')">
  59. <q-icon name="la la-angle-double-right" size="32px" />
  60. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  61. {{ rstore.readerActions['setPosition'] }}
  62. </q-tooltip>
  63. </button>
  64. <button v-show="showToolButton['search']" ref="search" v-ripple class="tool-button" :class="buttonActiveClass('search')" @click="buttonClick('search')">
  65. <q-icon name="la la-search" size="32px" />
  66. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  67. {{ rstore.readerActions['search'] }}
  68. </q-tooltip>
  69. </button>
  70. <button v-show="showToolButton['copyText']" ref="copyText" v-ripple class="tool-button" :class="buttonActiveClass('copyText')" @click="buttonClick('copyText')">
  71. <q-icon name="la la-copy" size="32px" />
  72. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  73. {{ rstore.readerActions['copyText'] }}
  74. </q-tooltip>
  75. </button>
  76. <button v-show="showToolButton['convOptions']" ref="convOptions" v-ripple class="tool-button" :class="buttonActiveClass('convOptions')" @click="buttonClick('convOptions')">
  77. <q-icon name="la la-magic" size="32px" />
  78. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  79. {{ rstore.readerActions['convOptions'] }}
  80. </q-tooltip>
  81. </button>
  82. <button v-show="showToolButton['refresh']" ref="refresh" v-ripple class="tool-button" :class="buttonActiveClass('refresh')" @click="buttonClick('refresh')">
  83. <q-icon name="la la-sync" size="32px" :class="{clear: !showRefreshIcon}" />
  84. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  85. {{ rstore.readerActions['refresh'] }}
  86. </q-tooltip>
  87. </button>
  88. <div class="space"></div>
  89. <button v-show="showToolButton['contents']" ref="contents" v-ripple class="tool-button" :class="buttonActiveClass('contents')" @click="buttonClick('contents')">
  90. <q-icon name="la la-list" size="32px" />
  91. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  92. {{ rstore.readerActions['contents'] }}
  93. </q-tooltip>
  94. </button>
  95. <button v-show="mode == 'liberama.top' && showToolButton['libs']" ref="libs" v-ripple class="tool-button" :class="buttonActiveClass('libs')" @click="buttonClick('libs')">
  96. <q-icon name="la la-sitemap" size="32px" />
  97. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  98. {{ rstore.readerActions['libs'] }}
  99. </q-tooltip>
  100. </button>
  101. <button v-show="showToolButton['recentBooks']" ref="recentBooks" v-ripple class="tool-button" :class="buttonActiveClass('recentBooks')" @click="buttonClick('recentBooks')">
  102. <q-icon name="la la-book-open" size="32px" />
  103. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  104. {{ rstore.readerActions['recentBooks'] }}
  105. </q-tooltip>
  106. </button>
  107. <div class="space"></div>
  108. </div>
  109. <div class="row no-wrap">
  110. <button v-show="showToolButton['clickControl']" ref="clickControl" v-ripple class="tool-button" :class="buttonActiveClass('clickControl')" @click="buttonClick('clickControl')">
  111. <q-icon name="la la-mouse" size="32px" />
  112. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  113. {{ rstore.readerActions['clickControl'] }}
  114. </q-tooltip>
  115. </button>
  116. <button v-show="showToolButton['offlineMode']" ref="offlineMode" v-ripple class="tool-button" :class="buttonActiveClass('offlineMode')" @click="buttonClick('offlineMode')">
  117. <q-icon name="la la-unlink" size="32px" />
  118. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  119. {{ rstore.readerActions['offlineMode'] }}
  120. </q-tooltip>
  121. </button>
  122. <button ref="settings" v-ripple class="tool-button" :class="buttonActiveClass('settings')" @click="buttonClick('settings')">
  123. <q-icon name="la la-cog" size="32px" />
  124. <q-tooltip :delay="1500" anchor="bottom left" content-style="font-size: 80%">
  125. {{ rstore.readerActions['settings'] }}
  126. </q-tooltip>
  127. </button>
  128. </div>
  129. </div>
  130. </div>
  131. <div class="main col row relative-position">
  132. <keep-alive>
  133. <component
  134. :is="activePage"
  135. ref="page"
  136. class="col"
  137. @load-book="loadBook"
  138. @load-file="loadFile"
  139. @book-pos-changed="bookPosChanged"
  140. @do-action="doAction"
  141. @hide-tool-bar="hideToolBar"
  142. ></component>
  143. </keep-alive>
  144. <SetPositionPage v-if="setPositionActive" ref="setPositionPage" @set-position-toggle="setPositionToggle" @book-pos-changed="bookPosChanged"></SetPositionPage>
  145. <SearchPage
  146. v-show="searchActive"
  147. ref="searchPage"
  148. @do-action="doAction"
  149. @book-pos-changed="bookPosChanged"
  150. @start-text-search="startTextSearch"
  151. @stop-text-search="stopTextSearch"
  152. ></SearchPage>
  153. <CopyTextPage v-if="copyTextActive" ref="copyTextPage" @do-action="doAction"></CopyTextPage>
  154. <LibsPage v-show="hidden" ref="libsPage" @load-book="loadBook" @libs-close="libsClose" @do-action="doAction"></LibsPage>
  155. <RecentBooksPage v-show="recentBooksActive" ref="recentBooksPage" @load-book="loadBook" @recent-books-close="recentBooksClose"></RecentBooksPage>
  156. <SettingsPage v-show="settingsActive" ref="settingsPage" @do-action="doAction"></SettingsPage>
  157. <HelpPage v-if="helpActive" ref="helpPage" @do-action="doAction"></HelpPage>
  158. <ClickMapPage v-show="clickMapActive" ref="clickMapPage"></ClickMapPage>
  159. <ContentsPage v-show="contentsActive" ref="contentsPage" :book-pos="bookPos" :is-visible="contentsActive" @do-action="doAction" @book-pos-changed="bookPosChanged"></ContentsPage>
  160. <ServerStorage v-show="hidden" ref="serverStorage"></ServerStorage>
  161. <ReaderDialogs ref="dialogs" @donate-toggle="donateToggle" @version-history-toggle="versionHistoryToggle" @load-buffer-toggle="loadBufferToggle"></ReaderDialogs>
  162. </div>
  163. </div>
  164. </template>
  165. <script>
  166. //-----------------------------------------------------------------------------
  167. import vueComponent from '../vueComponent.js';
  168. import _ from 'lodash';
  169. import {Buffer} from 'safe-buffer';
  170. import LoaderPage from './LoaderPage/LoaderPage.vue';
  171. import TextPage from './TextPage/TextPage.vue';
  172. import ProgressPage from './ProgressPage/ProgressPage.vue';
  173. import SetPositionPage from './SetPositionPage/SetPositionPage.vue';
  174. import SearchPage from './SearchPage/SearchPage.vue';
  175. import CopyTextPage from './CopyTextPage/CopyTextPage.vue';
  176. import LibsPage from './LibsPage/LibsPage.vue';
  177. import RecentBooksPage from './RecentBooksPage/RecentBooksPage.vue';
  178. import SettingsPage from './SettingsPage/SettingsPage.vue';
  179. import HelpPage from './HelpPage/HelpPage.vue';
  180. import ClickMapPage from './ClickMapPage/ClickMapPage.vue';
  181. import ContentsPage from './ContentsPage/ContentsPage.vue';
  182. import ServerStorage from './ServerStorage/ServerStorage.vue';
  183. import ReaderDialogs from './ReaderDialogs/ReaderDialogs.vue';
  184. import bookManager from './share/bookManager';
  185. import wallpaperStorage from './share/wallpaperStorage';
  186. import coversStorage from './share/coversStorage';
  187. import dynamicCss from '../../share/dynamicCss';
  188. import rstore from '../../store/modules/reader';
  189. import readerApi from '../../api/reader';
  190. import miscApi from '../../api/misc';
  191. import {versionHistory} from './versionHistory';
  192. import * as utils from '../../share/utils';
  193. import LockQueue from '../../share/LockQueue';
  194. const componentOptions = {
  195. components: {
  196. LoaderPage,
  197. TextPage,
  198. ProgressPage,
  199. SetPositionPage,
  200. SearchPage,
  201. CopyTextPage,
  202. LibsPage,
  203. RecentBooksPage,
  204. SettingsPage,
  205. HelpPage,
  206. ClickMapPage,
  207. ContentsPage,
  208. ServerStorage,
  209. ReaderDialogs,
  210. },
  211. watch: {
  212. bookPos: function(newValue) {
  213. if (newValue !== undefined && this.activePage == 'TextPage') {
  214. const textPage = this.$refs.page;
  215. if (textPage.bookPos != newValue) {
  216. textPage.bookPos = newValue;
  217. }
  218. if (!this.scrollingActive)
  219. this.debouncedSetRecentBook(newValue);
  220. else
  221. this.scrollingSetRecentBook(newValue);
  222. }
  223. },
  224. routeParamPos: function(newValue) {
  225. if (!this.paramPosIgnore && newValue !== undefined && newValue != this.bookPos) {
  226. this.bookPos = newValue;
  227. }
  228. },
  229. routeParamUrl: function(newValue) {
  230. if (newValue !== '' && newValue !== this.mostRecentBook().url) {
  231. this.loadBook({url: newValue, bookPos: this.routeParamPos});
  232. }
  233. },
  234. settings: function() {
  235. this.loadSettings();
  236. this.updateRoute();
  237. },
  238. loaderActive: function(newValue) {
  239. (async() => {
  240. const recent = this.mostRecentBook();
  241. if (!newValue && !this.loading && recent && !await bookManager.hasBookParsed(recent)) {
  242. this.loadBook(recent);
  243. }
  244. })();
  245. },
  246. dualPageMode(newValue) {
  247. if (newValue)
  248. this.stopScrolling();
  249. },
  250. },
  251. };
  252. class Reader {
  253. _options = componentOptions;
  254. rstore = {};
  255. loaderActive = false;
  256. loadFileActive = false;
  257. loadBufferActive = false;
  258. fullScreenActive = false;
  259. setPositionActive = false;
  260. searchActive = false;
  261. copyTextActive = false;
  262. convOptionsActive = false;
  263. refreshActive = false;
  264. contentsActive = false;
  265. libsActive = false;
  266. recentBooksActive = false;
  267. clickControlActive = false;
  268. offlineModeActive = false;
  269. settingsActive = false;
  270. clickMapActive = false;
  271. helpActive = false;
  272. scrollingActive = false;
  273. progressActive = false;
  274. bookPos = null;
  275. allowUrlParamBookPos = false;
  276. showRefreshIcon = true;
  277. mostRecentBookReactive = null;
  278. showToolButton = {};
  279. actionList = [];
  280. actionCur = -1;
  281. hidden = false;
  282. whatsNewVisible = false;
  283. whatsNewContent = '';
  284. donationVisible = false;
  285. dualPageMode = false;
  286. bucEnabled = false;
  287. created() {
  288. this.rstore = rstore;
  289. this.loading = true;
  290. this.commit = this.$store.commit;
  291. this.reader = this.$store.state.reader;
  292. this.config = this.$store.state.config;
  293. this.lock = new LockQueue(100);
  294. this.$root.addEventHook('key', this.keyHook);
  295. this.lastActivePage = false;
  296. this.$watch(
  297. () => this.$route.path,
  298. (newValue) => {
  299. if (newValue == '/reader') {
  300. this.updateRoute();
  301. }
  302. }
  303. );
  304. this.debouncedSetRecentBook = _.debounce(async(newValue) => {
  305. const recent = this.mostRecentBook();
  306. if (recent && (recent.bookPos != newValue || recent.bookPosSeen !== this.bookPosSeen)) {
  307. await bookManager.setRecentBook(Object.assign({}, recent, {bookPos: newValue, bookPosSeen: this.bookPosSeen}));
  308. if (this.actionCur < 0 || (this.actionCur >= 0 && this.actionList[this.actionCur] != newValue))
  309. this.addAction(newValue);
  310. this.paramPosIgnore = true;
  311. this.updateRoute();
  312. await this.$nextTick();
  313. this.paramPosIgnore = false;
  314. }
  315. }, 250, {maxWait: 5000});
  316. this.scrollingSetRecentBook = _.debounce((newValue) => {
  317. this.debouncedSetRecentBook(newValue);
  318. }, 15000, {maxWait: 20000});
  319. this.debouncedHideToolBar = _.debounce((event) => {
  320. if (this.toolBarHideOnScroll && this.toolBarActive !== !!event.show) {
  321. this.commit('reader/setToolBarActive', !!event.show);
  322. this.$root.eventHook('resize');
  323. }
  324. }, 200);
  325. this.recentItemKeys = [];
  326. this.saveRecentChanges = _.debounce(async() => {
  327. let timer = setTimeout(() => {
  328. if (!this.offlineModeActive)
  329. this.$root.notify.error('Таймаут соединения');
  330. }, 10000);
  331. try {
  332. const itemKeys = this.recentItemKeys;
  333. this.recentItemKeys = [];
  334. //сохранение в удаленном хранилище
  335. await this.$refs.serverStorage.saveRecent(itemKeys);
  336. } catch (e) {
  337. if (!this.offlineModeActive)
  338. this.$root.notify.error(e.message);
  339. } finally {
  340. clearTimeout(timer);
  341. }
  342. }, 500, {maxWait: 1000});
  343. document.addEventListener('fullscreenchange', () => {
  344. this.fullScreenActive = (document.fullscreenElement !== null);
  345. });
  346. this.loadSettings();
  347. }
  348. mounted() {
  349. (async() => {
  350. await wallpaperStorage.init();
  351. await coversStorage.init();
  352. await bookManager.init(this.settings);
  353. bookManager.addEventListener(this.bookManagerEvent);
  354. if (this.$root.getRootRoute() == '/reader') {
  355. if (this.routeParamUrl) {
  356. await this.loadBook({url: this.routeParamUrl, bookPos: this.routeParamPos, force: this.routeParamRefresh});
  357. } else {
  358. this.loaderActive = true;
  359. }
  360. }
  361. await this.$refs.serverStorage.init();
  362. this.checkSetStorageAccessKey();
  363. this.checkActivateDonateHelpPage();
  364. this.loading = false;
  365. //проверим состояние Settings, и обновим, если надо
  366. const newSettings = rstore.addDefaultsToSettings(this.settings);
  367. if (newSettings) {
  368. this.commit('reader/setSettings', newSettings);
  369. }
  370. this.updateRoute();
  371. await this.$refs.dialogs.init();
  372. })();
  373. //проверки обновлений читалки
  374. (async() => {
  375. this.isFirstNeedUpdateNotify = true;
  376. //вечный цикл, запрашиваем периодически конфиг для проверки выхода новой версии читалки
  377. while (1) {// eslint-disable-line no-constant-condition
  378. await this.checkNewVersionAvailable();
  379. await utils.sleep(3600*1000); //каждый час
  380. }
  381. //дальше хода нет
  382. })();
  383. //проверки обновлений книг
  384. (async() => {
  385. await utils.sleep(1*1000); //подождем неск. секунд перед первым запросом
  386. //вечный цикл, запрашиваем периодически обновления
  387. while (1) {// eslint-disable-line no-constant-condition
  388. await this.checkBuc();
  389. await utils.sleep(70*60*1000); //каждые 70 минут
  390. }
  391. //дальше хода нет
  392. })();
  393. }
  394. loadSettings() {
  395. const settings = this.settings;
  396. this.allowUrlParamBookPos = settings.allowUrlParamBookPos;
  397. this.copyFullText = settings.copyFullText;
  398. this.showClickMapPage = settings.showClickMapPage;
  399. this.clickControl = settings.clickControl;
  400. this.clickControlActive = this.clickControl;
  401. this.blinkCachedLoad = settings.blinkCachedLoad;
  402. this.showToolButton = settings.showToolButton;
  403. this.toolBarHideOnScroll = settings.toolBarHideOnScroll;
  404. this.enableSitesFilter = settings.enableSitesFilter;
  405. this.showNeedUpdateNotify = settings.showNeedUpdateNotify;
  406. this.splitToPara = settings.splitToPara;
  407. this.djvuQuality = settings.djvuQuality;
  408. this.pdfAsText = settings.pdfAsText;
  409. this.pdfQuality = settings.pdfQuality;
  410. this.dualPageMode = settings.dualPageMode;
  411. this.userWallpapers = settings.userWallpapers;
  412. this.bucEnabled = settings.bucEnabled;
  413. this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
  414. this.$root.readerActionByKeyEvent = (event) => {
  415. return this.readerActionByKeyCode[utils.keyEventToCode(event)];
  416. }
  417. this.loadWallpapers();//no await
  418. }
  419. showHelpOnErrorIfNeeded(errorMessage) {
  420. //небольшая эвристика
  421. let i = errorMessage.indexOf('http://');
  422. if (i < 0)
  423. i = errorMessage.indexOf('https://');
  424. errorMessage = errorMessage.substring(i + 7);
  425. const perCount = errorMessage.split('%').length - 1;
  426. if (perCount > errorMessage.length/3.2) {
  427. this.$refs.dialogs.showUrlHelp();
  428. return true;
  429. }
  430. return false;
  431. }
  432. //wallpaper css
  433. async loadWallpapers() {
  434. if (!_.isEqual(this.userWallpapers, this.prevUserWallpapers)) {//оптимизация
  435. this.prevUserWallpapers = _.cloneDeep(this.userWallpapers);
  436. let newCss = '';
  437. let updated = false;
  438. const wallpaperExists = new Set();
  439. for (const wp of this.userWallpapers) {
  440. wallpaperExists.add(wp.cssClass);
  441. let data = await wallpaperStorage.getData(wp.cssClass);
  442. if (!data) {
  443. //здесь будем восстанавливать данные с сервера
  444. const url = `disk://${wp.cssClass.replace('user-paper', '')}`;
  445. try {
  446. data = await readerApi.getUploadedFileBuf(url);
  447. await wallpaperStorage.setData(wp.cssClass, data);
  448. updated = true;
  449. } catch (e) {
  450. console.error(e);
  451. }
  452. }
  453. if (data) {
  454. newCss += `.${wp.cssClass} {background: url(${data}) center; background-size: 100% 100%;}`;
  455. }
  456. }
  457. //почистим wallpaperStorage
  458. for (const key of await wallpaperStorage.getKeys()) {
  459. if (!wallpaperExists.has(key)) {
  460. await wallpaperStorage.removeData(key);
  461. }
  462. }
  463. //обновим settings, если загружали обои из /upload/
  464. if (updated) {
  465. const newSettings = _.cloneDeep(this.settings);
  466. newSettings.needUpdateSettingsView = (newSettings.needUpdateSettingsView < 10 ? newSettings.needUpdateSettingsView + 1 : 0);
  467. this.commit('reader/setSettings', newSettings);
  468. }
  469. dynamicCss.replace('wallpapers', newCss);
  470. }
  471. }
  472. async checkNewVersionAvailable() {
  473. if (!this.checkingNewVersion && this.showNeedUpdateNotify) {
  474. this.checkingNewVersion = true;
  475. try {
  476. await utils.sleep(15*1000); //подождем 15 секунд, чтобы прогрузился ServiceWorker при выходе новой версии
  477. const config = await miscApi.loadConfig();
  478. this.commit('config/setConfig', config);
  479. let againMes = '';
  480. if (this.isFirstNeedUpdateNotify) {
  481. againMes = ' еще один раз';
  482. }
  483. if (this.version != this.clientVersion)
  484. this.$root.notify.info(`Вышла новая версия (v${this.version}) читалки.<br>Пожалуйста, обновите страницу${againMes}.`, 'Обновление');
  485. } catch(e) {
  486. console.error(e);
  487. } finally {
  488. this.checkingNewVersion = false;
  489. }
  490. this.isFirstNeedUpdateNotify = false;
  491. }
  492. }
  493. async checkBuc() {
  494. if (!this.bothBucEnabled)
  495. return;
  496. try {
  497. const sorted = bookManager.getSortedRecent();
  498. //выберем все кандидиаты на обновление
  499. const updateUrls = new Set();
  500. for (const book of sorted) {
  501. if (!book.deleted && book.checkBuc && book.url && book.url.indexOf('disk://') !== 0)
  502. updateUrls.add(book.url);
  503. }
  504. //теперь по кусочкам запросим сервер
  505. const arr = Array.from(updateUrls);
  506. const chunkSize = 100;
  507. for (let i = 0; i < arr.length; i += chunkSize) {
  508. const chunk = arr.slice(i, i + chunkSize);
  509. const data = await readerApi.checkBuc(chunk);
  510. console.log(data);
  511. await utils.sleep(1000);//чтобы не ддосить сервер
  512. }
  513. console.log('checkBuc finished', arr);
  514. } catch (e) {
  515. console.error(e);
  516. }
  517. }
  518. checkSetStorageAccessKey() {
  519. const q = this.$route.query;
  520. if (q['setStorageAccessKey']) {
  521. this.$router.replace(`/reader`);
  522. this.settingsToggle();
  523. this.$nextTick(() => {
  524. this.$refs.settingsPage.enterServerStorageKey(
  525. Buffer.from(utils.fromBase58(q['setStorageAccessKey'])).toString()
  526. );
  527. });
  528. }
  529. }
  530. checkActivateDonateHelpPage() {
  531. const q = this.$route.query;
  532. if (q['donate']) {
  533. this.$router.replace(`/reader`);
  534. this.helpToggle();
  535. this.$nextTick(() => {
  536. this.$refs.helpPage.activateDonateHelpPage();
  537. });
  538. }
  539. }
  540. checkBookPosPercent() {
  541. const q = this.$route.query;
  542. if (q['__pp']) {
  543. let pp = q['__pp'];
  544. if (pp) {
  545. pp = parseFloat(pp) || 0;
  546. const recent = this.mostRecentBook();
  547. (async() => {
  548. await utils.sleep(100);
  549. this.bookPos = Math.floor(recent.textLength*pp/100);
  550. })();
  551. }
  552. }
  553. }
  554. get routeParamPos() {
  555. let result = undefined;
  556. const q = this.$route.query;
  557. if (q['__p']) {
  558. result = q['__p'];
  559. if (Array.isArray(result))
  560. result = result[0];
  561. }
  562. return (result ? parseInt(result, 10) || 0 : result);
  563. }
  564. updateRoute(isNewRoute) {
  565. if (this.loading)
  566. return;
  567. const recent = this.mostRecentBook();
  568. const pos = (recent && recent.bookPos && this.allowUrlParamBookPos ? `__p=${recent.bookPos}&` : '');
  569. const url = (recent ? `url=${recent.url}` : '');
  570. if (isNewRoute)
  571. this.$router.push(`/reader?${pos}${url}`).catch(() => {});
  572. else
  573. this.$router.replace(`/reader?${pos}${url}`).catch(() => {});
  574. }
  575. get mode() {
  576. return this.$store.state.config.mode;
  577. }
  578. get version() {
  579. return this.$store.state.config.version;
  580. }
  581. get clientVersion() {
  582. return versionHistory[0].version;
  583. }
  584. get bothBucEnabled() {
  585. return this.$store.state.config.bucEnabled && this.bucEnabled;
  586. }
  587. get routeParamUrl() {
  588. let result = '';
  589. const path = this.$route.fullPath;
  590. const i = path.indexOf('url=');
  591. if (i >= 0) {
  592. result = path.substr(i + 4);
  593. }
  594. return decodeURIComponent(result);
  595. }
  596. get routeParamRefresh() {
  597. const q = this.$route.query;
  598. return !!q['__refresh'];
  599. }
  600. bookPosChanged(event) {
  601. if (event.bookPosSeen !== undefined)
  602. this.bookPosSeen = event.bookPosSeen;
  603. this.bookPos = event.bookPos;
  604. }
  605. async bookManagerEvent(eventName, value) {
  606. if (eventName == 'set-recent' || eventName == 'recent-deleted') {
  607. const oldBook = (this.textPage ? this.textPage.lastBook : null);
  608. const oldPos = (this.textPage ? this.textPage.bookPos : null);
  609. const newBook = bookManager.mostRecentBook();
  610. if (!(oldBook && newBook && oldBook.key == newBook.key)) {
  611. this.mostRecentBook();
  612. }
  613. if (oldBook && newBook) {
  614. if (oldBook.key != newBook.key || oldBook.path != newBook.path) {
  615. this.loadingBook = true;
  616. try {
  617. await this.loadBook(newBook);
  618. } finally {
  619. this.loadingBook = false;
  620. }
  621. } else if (oldPos != newBook.bookPos) {
  622. while (this.loadingBook) await utils.sleep(100);
  623. this.bookPosChanged({bookPos: newBook.bookPos});
  624. }
  625. }
  626. }
  627. if (eventName == 'recent-changed') {
  628. if (this.recentBooksActive) {
  629. await this.$refs.recentBooksPage.updateTableData();
  630. }
  631. //сохранение в serverStorage
  632. if (value && this.recentItemKeys.indexOf(value) < 0) {
  633. this.recentItemKeys.push(value);
  634. this.saveRecentChanges();
  635. }
  636. }
  637. }
  638. get toolBarActive() {
  639. return this.reader.toolBarActive;
  640. }
  641. mostRecentBook() {
  642. const result = bookManager.mostRecentBook();
  643. this.mostRecentBookReactive = result;
  644. return result;
  645. }
  646. get settings() {
  647. return this.$store.state.reader.settings;
  648. }
  649. addAction(pos) {
  650. let a = this.actionList;
  651. if (!a.length || a[a.length - 1] != pos) {
  652. a.push(pos);
  653. if (a.length > 20)
  654. a.shift();
  655. this.actionCur = a.length - 1;
  656. }
  657. }
  658. toolBarToggle() {
  659. this.commit('reader/setToolBarActive', !this.toolBarActive);
  660. this.$root.eventHook('resize');
  661. }
  662. hideToolBar(event) {
  663. this.debouncedHideToolBar(event);
  664. }
  665. fullScreenToggle() {
  666. this.fullScreenActive = !this.fullScreenActive;
  667. if (this.fullScreenActive) {
  668. this.$q.fullscreen.request();
  669. } else {
  670. this.$q.fullscreen.exit();
  671. }
  672. }
  673. closeAllWindows() {
  674. this.setPositionActive = false;
  675. this.copyTextActive = false;
  676. this.recentBooksActive = false;
  677. this.settingsActive = false;
  678. this.stopScrolling();
  679. this.stopSearch();
  680. this.helpActive = false;
  681. this.contentsActive = false;
  682. }
  683. loaderToggle() {
  684. this.loaderActive = !this.loaderActive;
  685. if (this.loaderActive) {
  686. this.closeAllWindows();
  687. }
  688. }
  689. loadFileToggle() {
  690. if (!this.loaderActive)
  691. this.loaderToggle();
  692. this.$nextTick(() => {
  693. const page = this.$refs.page;
  694. if (this.activePage == 'LoaderPage' && page.loadFileClick) {
  695. page.loadFileClick();
  696. }
  697. });
  698. }
  699. loadBufferToggle() {
  700. if (!this.loaderActive)
  701. this.loaderToggle();
  702. this.$nextTick(() => {
  703. const page = this.$refs.page;
  704. if (this.activePage == 'LoaderPage' && page.showPasteText) {
  705. page.showPasteText();
  706. }
  707. });
  708. }
  709. setPositionToggle() {
  710. this.setPositionActive = !this.setPositionActive;
  711. const page = this.$refs.page;
  712. if (this.setPositionActive && this.activePage == 'TextPage' && page.parsed) {
  713. this.closeAllWindows();
  714. this.setPositionActive = true;
  715. this.$nextTick(() => {
  716. const recent = this.mostRecentBook();
  717. this.$refs.setPositionPage.init(recent.bookPos, recent.textLength - 1);
  718. });
  719. } else {
  720. this.setPositionActive = false;
  721. }
  722. }
  723. stopScrolling() {
  724. if (this.scrollingActive)
  725. this.scrollingToggle();
  726. }
  727. scrollingToggle() {
  728. this.scrollingActive = !this.scrollingActive;
  729. if (this.activePage == 'TextPage') {
  730. const page = this.$refs.page;
  731. if (this.scrollingActive) {
  732. page.startTextScrolling();
  733. } else {
  734. page.stopTextScrolling();
  735. }
  736. }
  737. if (!this.scrollingActive) {
  738. this.scrollingSetRecentBook.flush();
  739. }
  740. }
  741. stopSearch() {
  742. if (this.searchActive)
  743. this.searchToggle();
  744. }
  745. startTextSearch(opts) {
  746. if (this.activePage == 'TextPage')
  747. this.$refs.page.startSearch(opts.needle);
  748. }
  749. stopTextSearch() {
  750. if (this.activePage == 'TextPage')
  751. this.$refs.page.stopSearch();
  752. }
  753. searchToggle() {
  754. this.searchActive = !this.searchActive;
  755. const page = this.$refs.page;
  756. if (this.searchActive && this.activePage == 'TextPage' && page.parsed) {
  757. this.closeAllWindows();
  758. this.searchActive = true;
  759. this.$nextTick(() => {
  760. this.$refs.searchPage.init(page.parsed);
  761. });
  762. } else {
  763. this.stopTextSearch();
  764. this.searchActive = false;
  765. }
  766. }
  767. copyTextToggle() {
  768. this.copyTextActive = !this.copyTextActive;
  769. const page = this.$refs.page;
  770. if (this.copyTextActive && this.activePage == 'TextPage' && page.parsed) {
  771. this.closeAllWindows();
  772. this.copyTextActive = true;
  773. this.$nextTick(() => {
  774. this.$refs.copyTextPage.init(this.mostRecentBook().bookPos, page.parsed, this.copyFullText);
  775. });
  776. } else {
  777. this.copyTextActive = false;
  778. }
  779. }
  780. recentBooksClose() {
  781. this.recentBooksActive = false;
  782. }
  783. recentBooksToggle() {
  784. this.recentBooksActive = !this.recentBooksActive;
  785. if (this.recentBooksActive) {
  786. this.closeAllWindows();
  787. this.$refs.recentBooksPage.init();
  788. this.recentBooksActive = true;
  789. } else {
  790. this.recentBooksActive = false;
  791. }
  792. }
  793. contentsPageToggle() {
  794. this.contentsActive = !this.contentsActive;
  795. const page = this.$refs.page;
  796. if (this.contentsActive && this.activePage == 'TextPage' && page.parsed) {
  797. this.closeAllWindows();
  798. this.contentsActive = true;
  799. this.$nextTick(() => {
  800. this.$refs.contentsPage.init(this.mostRecentBook(), page.parsed);
  801. });
  802. } else {
  803. this.contentsActive = false;
  804. }
  805. }
  806. libsClose() {
  807. if (this.libsActive)
  808. this.libsToogle();
  809. }
  810. libsToogle() {
  811. this.libsActive = !this.libsActive;
  812. if (this.libsActive) {
  813. this.$refs.libsPage.init();
  814. } else {
  815. this.$refs.libsPage.done();
  816. }
  817. }
  818. clickControlToggle() {
  819. const newSettings = _.cloneDeep(this.settings);
  820. newSettings.clickControl = !this.clickControl;
  821. this.commit('reader/setSettings', newSettings);
  822. }
  823. offlineModeToggle() {
  824. this.offlineModeActive = !this.offlineModeActive;
  825. this.$refs.serverStorage.offlineModeActive = this.offlineModeActive;
  826. }
  827. settingsToggle() {
  828. this.settingsActive = !this.settingsActive;
  829. if (this.settingsActive) {
  830. this.closeAllWindows();
  831. this.settingsActive = true;
  832. this.$nextTick(() => {
  833. this.$refs.settingsPage.init();
  834. });
  835. } else {
  836. this.settingsActive = false;
  837. }
  838. }
  839. convOptionsToggle() {
  840. this.settingsToggle();
  841. if (this.settingsActive)
  842. this.$refs.settingsPage.selectedTab = 'convert';
  843. }
  844. helpToggle() {
  845. this.helpActive = !this.helpActive;
  846. if (this.helpActive) {
  847. this.closeAllWindows();
  848. this.helpActive = true;
  849. }
  850. }
  851. donateToggle() {
  852. this.helpToggle();
  853. if (this.helpActive) {
  854. this.$nextTick(() => {
  855. this.$refs.helpPage.activateDonateHelpPage();
  856. });
  857. }
  858. }
  859. versionHistoryToggle() {
  860. this.helpToggle();
  861. if (this.helpActive) {
  862. this.$nextTick(() => {
  863. this.$refs.helpPage.activateVersionHistoryHelpPage();
  864. });
  865. }
  866. }
  867. refreshBook() {
  868. const mrb = this.mostRecentBook();
  869. this.loadBook(Object.assign({}, mrb, {force: true}));
  870. }
  871. undoAction() {
  872. if (this.actionCur > 0) {
  873. this.actionCur--;
  874. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  875. }
  876. }
  877. redoAction() {
  878. if (this.actionCur < this.actionList.length - 1) {
  879. this.actionCur++;
  880. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  881. }
  882. }
  883. buttonClick(action) {
  884. const activeClass = this.buttonActiveClass(action);
  885. this.$refs[action].blur();
  886. if (activeClass['tool-button-disabled'])
  887. return;
  888. this.doAction({action});
  889. }
  890. buttonActiveClass(action) {
  891. const classActive = { 'tool-button-active': true, 'tool-button-active:hover': true };
  892. const classDisabled = { 'tool-button-disabled': true, 'tool-button-disabled:hover': true };
  893. let classResult = {};
  894. switch (action) {
  895. case 'loader':
  896. case 'loadFile':
  897. case 'loadBuffer':
  898. case 'help':
  899. case 'fullScreen':
  900. case 'setPosition':
  901. case 'search':
  902. case 'copyText':
  903. case 'convOptions':
  904. case 'refresh':
  905. case 'contents':
  906. case 'libs':
  907. case 'recentBooks':
  908. case 'clickControl':
  909. case 'offlineMode':
  910. case 'settings':
  911. if (this.progressActive) {
  912. classResult = classDisabled;
  913. } else if (this[`${action}Active`]) {
  914. classResult = classActive;
  915. }
  916. break;
  917. case 'scrolling':
  918. if (this.progressActive || this.dualPageMode) {
  919. classResult = classDisabled;
  920. } else if (this[`${action}Active`]) {
  921. classResult = classActive;
  922. }
  923. break;
  924. case 'undoAction':
  925. if (this.actionCur <= 0)
  926. classResult = classDisabled;
  927. break;
  928. case 'redoAction':
  929. if (this.actionCur == this.actionList.length - 1)
  930. classResult = classDisabled;
  931. break;
  932. }
  933. if (this.activePage == 'LoaderPage' || !this.mostRecentBookReactive) {
  934. switch (action) {
  935. case 'undoAction':
  936. case 'redoAction':
  937. case 'setPosition':
  938. case 'scrolling':
  939. case 'search':
  940. case 'copyText':
  941. case 'contents':
  942. classResult = classDisabled;
  943. break;
  944. case 'refresh':
  945. if (!this.mostRecentBookReactive)
  946. classResult = classDisabled;
  947. break;
  948. }
  949. }
  950. return classResult;
  951. }
  952. async activateClickMapPage() {
  953. if (this.clickControl && this.showClickMapPage && !this.clickMapActive) {
  954. this.clickMapActive = true;
  955. await this.$refs.clickMapPage.slowDisappear();
  956. this.clickMapActive = false;
  957. }
  958. }
  959. get activePage() {
  960. let result = undefined;
  961. if (this.progressActive)
  962. result = 'ProgressPage';
  963. else if (this.loaderActive)
  964. result = 'LoaderPage';
  965. else if (this.mostRecentBookReactive)
  966. result = 'TextPage';
  967. if (!result && !this.loading) {
  968. this.loaderActive = true;
  969. result = 'LoaderPage';
  970. }
  971. if (result != 'TextPage') {
  972. this.$root.setAppTitle();
  973. }
  974. // на LoaderPage всегда показываем toolBar
  975. if (result == 'LoaderPage' && !this.toolBarActive) {
  976. this.toolBarToggle();
  977. }
  978. if (this.lastActivePage != result && result == 'TextPage') {
  979. //акивируем страницу с текстом
  980. this.$nextTick(async() => {
  981. const last = this.mostRecentBookReactive;
  982. const isParsed = await bookManager.hasBookParsed(last);
  983. if (!isParsed) {
  984. this.$root.setAppTitle();
  985. return;
  986. }
  987. this.updateRoute();
  988. const textPage = this.$refs.page;
  989. if (textPage.showBook) {
  990. this.textPage = textPage;
  991. textPage.lastBook = last;
  992. textPage.bookPos = (last.bookPos !== undefined ? last.bookPos : 0);
  993. textPage.showBook();
  994. }
  995. });
  996. }
  997. this.lastActivePage = result;
  998. return result;
  999. }
  1000. async _loadBook(opts) {
  1001. if (!opts || !opts.url) {
  1002. this.mostRecentBook();
  1003. return;
  1004. }
  1005. this.closeAllWindows();
  1006. let url = encodeURI(decodeURI(opts.url));
  1007. if ((url.indexOf('http://') != 0) && (url.indexOf('https://') != 0) &&
  1008. (url.indexOf('disk://') != 0))
  1009. url = 'http://' + url;
  1010. // уже просматривается сейчас
  1011. const lastBook = (this.textPage ? this.textPage.lastBook : null);
  1012. if (!opts.force && lastBook && lastBook.url == url &&
  1013. (!opts.path || opts.path == lastBook.path) &&
  1014. await bookManager.hasBookParsed(lastBook)) {
  1015. this.loaderActive = false;
  1016. return;
  1017. }
  1018. this.progressActive = true;
  1019. await this.$nextTick();
  1020. const progress = this.$refs.page;
  1021. this.actionList = [];
  1022. this.actionCur = -1;
  1023. try {
  1024. progress.show();
  1025. progress.setState({state: 'parse'});
  1026. // есть ли среди загруженных
  1027. let wasOpened = bookManager.findRecentByUrlAndPath(url, opts.path);
  1028. wasOpened = (wasOpened ? _.cloneDeep(wasOpened) : {});
  1029. wasOpened = Object.assign(wasOpened, {
  1030. url: (opts.url !== undefined ? opts.url : wasOpened.url),
  1031. path: (opts.path !== undefined ? opts.path : wasOpened.path),
  1032. bookPos: (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos),
  1033. bookPosSeen: (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPosSeen),
  1034. uploadFileName: (opts.uploadFileName ? opts.uploadFileName : wasOpened.uploadFileName),
  1035. });
  1036. let book = null;
  1037. if (!opts.force) {
  1038. // пытаемся загрузить и распарсить книгу в менеджере из локального кэша
  1039. const bookParsed = await bookManager.getBook(wasOpened, (prog) => {
  1040. progress.setState({progress: prog});
  1041. });
  1042. // если есть в локальном кэше
  1043. if (bookParsed) {
  1044. await bookManager.setRecentBook(Object.assign(wasOpened, bookParsed));
  1045. this.mostRecentBook();
  1046. this.addAction(wasOpened.bookPos);
  1047. this.loaderActive = false;
  1048. progress.hide(); this.progressActive = false;
  1049. this.blinkCachedLoadMessage();
  1050. this.checkBookPosPercent();
  1051. this.activateClickMapPage();//no await
  1052. return;
  1053. }
  1054. // иначе идем на сервер
  1055. // пытаемся загрузить готовый файл с сервера
  1056. if (wasOpened.path) {
  1057. progress.setState({totalSteps: 5});
  1058. try {
  1059. const resp = await readerApi.loadCachedBook(wasOpened.path, (state) => {
  1060. progress.setState(state);
  1061. });
  1062. book = Object.assign({}, wasOpened, {data: resp.data});
  1063. } catch (e) {
  1064. this.$root.notify.error('Конвертированный файл не найден на сервере.<br>Пробуем загрузить оригинал.', 'Ошибка загрузки');
  1065. }
  1066. }
  1067. }
  1068. progress.setState({totalSteps: 5});
  1069. // не удалось, скачиваем книгу полностью с конвертацией
  1070. let loadCached = true;
  1071. if (!book) {
  1072. book = await readerApi.loadBook({
  1073. url,
  1074. uploadFileName: wasOpened.uploadFileName,
  1075. enableSitesFilter: this.enableSitesFilter,
  1076. skipHtmlCheck: (this.splitToPara ? true : false),
  1077. isText: (this.splitToPara ? true : false),
  1078. djvuQuality: this.djvuQuality,
  1079. pdfAsText: this.pdfAsText,
  1080. pdfQuality: this.pdfQuality,
  1081. },
  1082. (state) => {
  1083. progress.setState(state);
  1084. }
  1085. );
  1086. loadCached = false;
  1087. }
  1088. // добавляем в bookManager
  1089. progress.setState({state: 'parse', step: 5});
  1090. const addedBook = await bookManager.addBook(book, (prog) => {
  1091. progress.setState({progress: prog});
  1092. });
  1093. // sameBookKey
  1094. if (url.indexOf('disk://') == 0) {
  1095. //ищем такой файл в загруженных
  1096. let found = bookManager.findRecentBySameBookKey(wasOpened.uploadFileName);
  1097. found = (found ? _.cloneDeep(found) : found);
  1098. if (found) {
  1099. if (wasOpened.sameBookKey != found.sameBookKey) {
  1100. //спрашиваем, надо ли объединить файлы
  1101. const askResult = bookManager.keysEqual(found.path, addedBook.path) ||
  1102. await this.$root.stdDialog.askYesNo(`
  1103. Файл с именем "${wasOpened.uploadFileName}" уже есть в загруженных.
  1104. <br>Объединить позицию?`, 'Найдена похожая книга');
  1105. if (askResult) {
  1106. wasOpened.bookPos = found.bookPos;
  1107. wasOpened.bookPosSeen = found.bookPosSeen;
  1108. wasOpened.sameBookKey = found.sameBookKey;
  1109. }
  1110. }
  1111. } else {
  1112. wasOpened.sameBookKey = wasOpened.uploadFileName;
  1113. }
  1114. } else {
  1115. wasOpened.sameBookKey = addedBook.url;
  1116. }
  1117. if (!bookManager.keysEqual(wasOpened.path, addedBook.path))
  1118. delete wasOpened.loadTime;
  1119. // добавляем в историю
  1120. await bookManager.setRecentBook(Object.assign(wasOpened, addedBook));
  1121. this.mostRecentBook();
  1122. this.addAction(wasOpened.bookPos);
  1123. this.updateRoute(true);
  1124. this.loaderActive = false;
  1125. progress.hide(); this.progressActive = false;
  1126. if (loadCached) {
  1127. this.blinkCachedLoadMessage();
  1128. } else
  1129. this.stopBlink = true;
  1130. this.checkBookPosPercent();
  1131. this.activateClickMapPage();//no await
  1132. } catch (e) {
  1133. progress.hide(); this.progressActive = false;
  1134. this.loaderActive = true;
  1135. if (!this.showHelpOnErrorIfNeeded(url)) {
  1136. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  1137. }
  1138. } finally {
  1139. this.checkNewVersionAvailable();
  1140. }
  1141. }
  1142. async loadBook(opts) {
  1143. await this.lock.get();
  1144. try {
  1145. await this._loadBook(opts);
  1146. } finally {
  1147. this.lock.ret();
  1148. }
  1149. }
  1150. async _loadFile(opts) {
  1151. this.progressActive = true;
  1152. await this.$nextTick();
  1153. const progress = this.$refs.page;
  1154. try {
  1155. progress.show();
  1156. progress.setState({state: 'upload'});
  1157. const url = await readerApi.uploadFile(opts.file, this.config.maxUploadFileSize, (state) => {
  1158. progress.setState(state);
  1159. });
  1160. progress.hide(); this.progressActive = false;
  1161. await this._loadBook({url, uploadFileName: opts.file.name, force: true});
  1162. } catch (e) {
  1163. progress.hide(); this.progressActive = false;
  1164. this.loaderActive = true;
  1165. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  1166. }
  1167. }
  1168. async loadFile(opts) {
  1169. await this.lock.get();
  1170. try {
  1171. await this._loadFile(opts);
  1172. } finally {
  1173. this.lock.ret();
  1174. }
  1175. }
  1176. blinkCachedLoadMessage() {
  1177. if (!this.blinkCachedLoad)
  1178. return;
  1179. this.blinkCount = 30;
  1180. if (!this.inBlink) {
  1181. this.inBlink = true;
  1182. this.stopBlink = false;
  1183. this.$nextTick(async() => {
  1184. let page = this.$refs.page;
  1185. while (this.blinkCount) {
  1186. this.showRefreshIcon = !this.showRefreshIcon;
  1187. if (page && page.blinkCachedLoadMessage)
  1188. page.blinkCachedLoadMessage(this.showRefreshIcon);
  1189. await utils.sleep(500);
  1190. if (this.stopBlink)
  1191. break;
  1192. this.blinkCount--;
  1193. page = this.$refs.page;
  1194. }
  1195. this.showRefreshIcon = true;
  1196. this.inBlink = false;
  1197. if (page && page.blinkCachedLoadMessage)
  1198. page.blinkCachedLoadMessage('finish');
  1199. });
  1200. }
  1201. }
  1202. doAction(opts) {
  1203. let result = true;
  1204. let {action = '', event = false} = opts;
  1205. switch (action) {
  1206. case 'loader':
  1207. this.loaderToggle();
  1208. break;
  1209. case 'loadFile':
  1210. this.loadFileToggle();
  1211. break;
  1212. case 'loadBuffer':
  1213. this.loadBufferToggle();
  1214. break;
  1215. case 'help':
  1216. this.helpToggle();
  1217. break;
  1218. case 'undoAction':
  1219. this.undoAction();
  1220. break;
  1221. case 'redoAction':
  1222. this.redoAction();
  1223. break;
  1224. case 'fullScreen':
  1225. this.fullScreenToggle();
  1226. break;
  1227. case 'scrolling':
  1228. this.scrollingToggle();
  1229. break;
  1230. case 'stopScrolling':
  1231. this.stopScrolling();
  1232. break;
  1233. case 'setPosition':
  1234. this.setPositionToggle();
  1235. break;
  1236. case 'search':
  1237. this.searchToggle();
  1238. break;
  1239. case 'copyText':
  1240. this.copyTextToggle();
  1241. break;
  1242. case 'convOptions':
  1243. this.convOptionsToggle();
  1244. break;
  1245. case 'refresh':
  1246. this.refreshBook();
  1247. break;
  1248. case 'contents':
  1249. this.contentsPageToggle();
  1250. break;
  1251. case 'libs':
  1252. this.libsToogle();
  1253. break;
  1254. case 'recentBooks':
  1255. this.recentBooksToggle();
  1256. break;
  1257. case 'clickControl':
  1258. this.clickControlToggle();
  1259. break;
  1260. case 'offlineMode':
  1261. this.offlineModeToggle();
  1262. break;
  1263. case 'settings':
  1264. this.settingsToggle();
  1265. break;
  1266. case 'switchToolbar':
  1267. this.toolBarToggle();
  1268. break;
  1269. case 'donate':
  1270. this.donateToggle();
  1271. break;
  1272. default:
  1273. result = false;
  1274. break;
  1275. }
  1276. if (!result && this.activePage == 'TextPage' && this.$refs.page) {
  1277. result = true;
  1278. const textPage = this.$refs.page;
  1279. switch (action) {
  1280. case 'bookBegin':
  1281. textPage.doHome();
  1282. break;
  1283. case 'bookEnd':
  1284. textPage.doEnd();
  1285. break;
  1286. case 'pageBack':
  1287. textPage.doPageUp();
  1288. break;
  1289. case 'pageForward':
  1290. textPage.doPageDown();
  1291. break;
  1292. case 'lineBack':
  1293. textPage.doUp();
  1294. break;
  1295. case 'lineForward':
  1296. textPage.doDown();
  1297. break;
  1298. case 'incFontSize':
  1299. textPage.doFontSizeInc();
  1300. break;
  1301. case 'decFontSize':
  1302. textPage.doFontSizeDec();
  1303. break;
  1304. case 'scrollingSpeedUp':
  1305. textPage.doScrollingSpeedUp();
  1306. break;
  1307. case 'scrollingSpeedDown':
  1308. textPage.doScrollingSpeedDown();
  1309. break;
  1310. default:
  1311. result = false;
  1312. break;
  1313. }
  1314. }
  1315. if (result && event) {
  1316. event.preventDefault();
  1317. event.stopPropagation();
  1318. }
  1319. return result;
  1320. }
  1321. keyHook(event) {
  1322. let result = false;
  1323. if (this.$root.getRootRoute() == '/reader') {
  1324. if (this.$root.stdDialog.active)
  1325. return result;
  1326. if (!result)
  1327. result = this.$refs.dialogs.keyHook(event);
  1328. if (!result && this.helpActive)
  1329. result = this.$refs.helpPage.keyHook(event);
  1330. if (!result && this.settingsActive)
  1331. result = this.$refs.settingsPage.keyHook(event);
  1332. if (!result && this.recentBooksActive)
  1333. result = this.$refs.recentBooksPage.keyHook(event);
  1334. if (!result && this.setPositionActive)
  1335. result = this.$refs.setPositionPage.keyHook(event);
  1336. if (!result && this.searchActive)
  1337. result = this.$refs.searchPage.keyHook(event);
  1338. if (!result && this.copyTextActive)
  1339. result = this.$refs.copyTextPage.keyHook(event);
  1340. if (!result && this.contentsActive)
  1341. result = this.$refs.contentsPage.keyHook(event);
  1342. if (!result && this.$refs.page && this.$refs.page.keyHook)
  1343. result = this.$refs.page.keyHook(event);
  1344. if (!result && event.type == 'keydown') {
  1345. const action = this.$root.readerActionByKeyEvent(event);
  1346. /*if (action == 'loader') {
  1347. result = this.doAction({action, event});
  1348. }
  1349. if (!result && this.activePage == 'TextPage') {
  1350. result = this.doAction({action, event});
  1351. }*/
  1352. result = this.doAction({action, event});
  1353. }
  1354. }
  1355. return result;
  1356. }
  1357. }
  1358. export default vueComponent(Reader);
  1359. //-----------------------------------------------------------------------------
  1360. </script>
  1361. <style scoped>
  1362. .header {
  1363. height: 50px;
  1364. padding-left: 5px;
  1365. padding-right: 5px;
  1366. background-color: #1B695F;
  1367. color: #000;
  1368. overflow-x: auto;
  1369. overflow-y: hidden;
  1370. scrollbar-color: #c49a60 #e4e4e4;
  1371. }
  1372. .header::-webkit-scrollbar {
  1373. height: 10px;
  1374. }
  1375. .header::-webkit-scrollbar-track {
  1376. background-color: #e4e4e4;
  1377. border-radius: 4px;
  1378. }
  1379. .header::-webkit-scrollbar-thumb {
  1380. background-color: #c49a60;
  1381. border-radius: 4px;
  1382. border: 2px solid #e4e4e4;
  1383. }
  1384. .header::-webkit-scrollbar-thumb:hover {
  1385. background-color: #b48a50;
  1386. }
  1387. .main {
  1388. background-color: #EBE2C9;
  1389. color: #000;
  1390. }
  1391. .tool-button {
  1392. margin: 0px 2px 0 2px;
  1393. padding: 0;
  1394. color: #3E843E;
  1395. background-color: #E6EDF4;
  1396. margin-top: 5px;
  1397. height: 38px;
  1398. width: 38px;
  1399. border: 0;
  1400. border-radius: 6px;
  1401. box-shadow: 3px 3px 5px black;
  1402. outline: 0;
  1403. }
  1404. .tool-button:hover {
  1405. background-color: white;
  1406. cursor: pointer;
  1407. }
  1408. .tool-button-active {
  1409. box-shadow: 0 0 0;
  1410. color: white;
  1411. background-color: #8AB45F;
  1412. position: relative;
  1413. top: 1px;
  1414. left: 1px;
  1415. }
  1416. .tool-button-active:hover {
  1417. color: white;
  1418. background-color: #81C581;
  1419. cursor: pointer;
  1420. }
  1421. .tool-button-disabled {
  1422. color: lightgray;
  1423. background-color: gray;
  1424. cursor: default;
  1425. }
  1426. .tool-button-disabled:hover {
  1427. color: lightgray;
  1428. background-color: gray;
  1429. cursor: default;
  1430. }
  1431. .space {
  1432. width: 10px;
  1433. display: inline-block;
  1434. }
  1435. .clear {
  1436. color: rgba(0,0,0,0);
  1437. }
  1438. </style>