Reader.vue 57 KB

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