Reader.vue 52 KB

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