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