Reader.vue 55 KB

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