Reader.vue 52 KB

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