Reader.vue 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. <template>
  2. <div class="column no-wrap">
  3. <div v-show="toolBarActive" ref="header" class="header">
  4. <div ref="buttons" class="row justify-between no-wrap">
  5. <div>
  6. <button ref="loader" v-ripple class="tool-button" :class="buttonActiveClass('loader')" @click="buttonClick('loader')">
  7. <q-icon name="la la-arrow-left" size="32px" />
  8. <q-tooltip :delay="1500" anchor="bottom right" content-style="font-size: 80%">
  9. {{ rstore.readerActions['loader'] }}
  10. </q-tooltip>
  11. </button>
  12. <button v-show="showToolButton['loadFile']" ref="loadFile" v-ripple class="tool-button" :class="buttonActiveClass('loadFile')" @click="buttonClick('loadFile')">
  13. <q-icon name="la la-caret-square-up" size="32px" />
  14. <q-tooltip :delay="1500" anchor="bottom right" content-style="font-size: 80%">
  15. {{ rstore.readerActions['loadFile'] }}
  16. </q-tooltip>
  17. </button>
  18. <button v-show="showToolButton['loadBuffer']" ref="loadBuffer" v-ripple class="tool-button" :class="buttonActiveClass('loadBuffer')" @click="buttonClick('loadBuffer')">
  19. <q-icon name="la la-comment" size="32px" />
  20. <q-tooltip :delay="1500" anchor="bottom right" content-style="font-size: 80%">
  21. {{ rstore.readerActions['loadBuffer'] }}
  22. </q-tooltip>
  23. </button>
  24. <button v-show="showToolButton['help']" ref="help" v-ripple class="tool-button" :class="buttonActiveClass('help')" @click="buttonClick('help')">
  25. <q-icon name="la la-question" size="32px" />
  26. <q-tooltip :delay="1500" anchor="bottom right" content-style="font-size: 80%">
  27. {{ rstore.readerActions['help'] }}
  28. </q-tooltip>
  29. </button>
  30. </div>
  31. <div>
  32. <button v-show="showToolButton['undoAction']" ref="undoAction" v-ripple class="tool-button" :class="buttonActiveClass('undoAction')" @click="buttonClick('undoAction')">
  33. <q-icon name="la la-angle-left" size="32px" />
  34. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  35. {{ rstore.readerActions['undoAction'] }}
  36. </q-tooltip>
  37. </button>
  38. <button v-show="showToolButton['redoAction']" ref="redoAction" v-ripple class="tool-button" :class="buttonActiveClass('redoAction')" @click="buttonClick('redoAction')">
  39. <q-icon name="la la-angle-right" size="32px" />
  40. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  41. {{ rstore.readerActions['redoAction'] }}
  42. </q-tooltip>
  43. </button>
  44. <div class="space"></div>
  45. <button v-show="showToolButton['fullScreen']" ref="fullScreen" v-ripple class="tool-button" :class="buttonActiveClass('fullScreen')" @click="buttonClick('fullScreen')">
  46. <q-icon :name="(fullScreenActive ? 'la la-compress-arrows-alt': 'la la-expand-arrows-alt')" size="32px" />
  47. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  48. {{ rstore.readerActions['fullScreen'] }}
  49. </q-tooltip>
  50. </button>
  51. <button v-show="showToolButton['scrolling']" ref="scrolling" v-ripple class="tool-button" :class="buttonActiveClass('scrolling')" @click="buttonClick('scrolling')">
  52. <q-icon name="la la-film" size="32px" />
  53. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  54. {{ rstore.readerActions['scrolling'] }}
  55. </q-tooltip>
  56. </button>
  57. <button v-show="showToolButton['setPosition']" ref="setPosition" v-ripple class="tool-button" :class="buttonActiveClass('setPosition')" @click="buttonClick('setPosition')">
  58. <q-icon name="la la-angle-double-right" size="32px" />
  59. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  60. {{ rstore.readerActions['setPosition'] }}
  61. </q-tooltip>
  62. </button>
  63. <button v-show="showToolButton['search']" ref="search" v-ripple class="tool-button" :class="buttonActiveClass('search')" @click="buttonClick('search')">
  64. <q-icon name="la la-search" size="32px" />
  65. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  66. {{ rstore.readerActions['search'] }}
  67. </q-tooltip>
  68. </button>
  69. <button v-show="showToolButton['copyText']" ref="copyText" v-ripple class="tool-button" :class="buttonActiveClass('copyText')" @click="buttonClick('copyText')">
  70. <q-icon name="la la-copy" size="32px" />
  71. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  72. {{ rstore.readerActions['copyText'] }}
  73. </q-tooltip>
  74. </button>
  75. <button v-show="showToolButton['convOptions']" ref="convOptions" v-ripple class="tool-button" :class="buttonActiveClass('convOptions')" @click="buttonClick('convOptions')">
  76. <q-icon name="la la-magic" size="32px" />
  77. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  78. {{ rstore.readerActions['convOptions'] }}
  79. </q-tooltip>
  80. </button>
  81. <button v-show="showToolButton['refresh']" ref="refresh" v-ripple class="tool-button" :class="buttonActiveClass('refresh')" @click="buttonClick('refresh')">
  82. <q-icon name="la la-sync" size="32px" :class="{clear: !showRefreshIcon}" />
  83. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  84. {{ rstore.readerActions['refresh'] }}
  85. </q-tooltip>
  86. </button>
  87. <div class="space"></div>
  88. <button v-show="showToolButton['contents']" ref="contents" v-ripple class="tool-button" :class="buttonActiveClass('contents')" @click="buttonClick('contents')">
  89. <q-icon name="la la-list" size="32px" />
  90. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  91. {{ rstore.readerActions['contents'] }}
  92. </q-tooltip>
  93. </button>
  94. <button v-show="mode == 'liberama.top' && showToolButton['libs']" ref="libs" v-ripple class="tool-button" :class="buttonActiveClass('libs')" @click="buttonClick('libs')">
  95. <q-icon name="la la-sitemap" size="32px" />
  96. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  97. {{ rstore.readerActions['libs'] }}
  98. </q-tooltip>
  99. </button>
  100. <button v-show="showToolButton['recentBooks']" ref="recentBooks" v-ripple class="tool-button" :class="buttonActiveClass('recentBooks')" @click="buttonClick('recentBooks')">
  101. <q-icon name="la la-book-open" size="32px" />
  102. <q-tooltip :delay="1500" anchor="bottom middle" content-style="font-size: 80%">
  103. {{ rstore.readerActions['recentBooks'] }}
  104. </q-tooltip>
  105. </button>
  106. </div>
  107. <div>
  108. <button v-show="showToolButton['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"></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. this.updateHeaderMinWidth();
  319. (async() => {
  320. await wallpaperStorage.init();
  321. await bookManager.init(this.settings);
  322. bookManager.addEventListener(this.bookManagerEvent);
  323. if (this.$root.getRootRoute() == '/reader') {
  324. if (this.routeParamUrl) {
  325. await this.loadBook({url: this.routeParamUrl, bookPos: this.routeParamPos, force: this.routeParamRefresh});
  326. } else {
  327. this.loaderActive = true;
  328. }
  329. }
  330. await this.$refs.serverStorage.init();
  331. this.checkSetStorageAccessKey();
  332. this.checkActivateDonateHelpPage();
  333. this.loading = false;
  334. //проверим состояние Settings, и обновим, если надо
  335. const newSettings = rstore.addDefaultsToSettings(this.settings);
  336. if (newSettings) {
  337. this.commit('reader/setSettings', newSettings);
  338. }
  339. this.updateRoute();
  340. await this.$refs.dialogs.init();
  341. })();
  342. (async() => {
  343. this.isFirstNeedUpdateNotify = true;
  344. //вечный цикл, запрашиваем периодически конфиг для проверки выхода новой версии читалки
  345. while (true) {// eslint-disable-line no-constant-condition
  346. await this.checkNewVersionAvailable();
  347. await utils.sleep(3600*1000); //каждый час
  348. }
  349. //дальше кода нет
  350. })();
  351. }
  352. loadSettings() {
  353. const settings = this.settings;
  354. this.allowUrlParamBookPos = settings.allowUrlParamBookPos;
  355. this.copyFullText = settings.copyFullText;
  356. this.showClickMapPage = settings.showClickMapPage;
  357. this.clickControl = settings.clickControl;
  358. this.clickControlActive = this.clickControl;
  359. this.blinkCachedLoad = settings.blinkCachedLoad;
  360. this.showToolButton = settings.showToolButton;
  361. this.enableSitesFilter = settings.enableSitesFilter;
  362. this.showNeedUpdateNotify = settings.showNeedUpdateNotify;
  363. this.splitToPara = settings.splitToPara;
  364. this.djvuQuality = settings.djvuQuality;
  365. this.pdfAsText = settings.pdfAsText;
  366. this.pdfQuality = settings.pdfQuality;
  367. this.dualPageMode = settings.dualPageMode;
  368. this.userWallpapers = settings.userWallpapers;
  369. this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
  370. this.$root.readerActionByKeyEvent = (event) => {
  371. return this.readerActionByKeyCode[utils.keyEventToCode(event)];
  372. }
  373. this.updateHeaderMinWidth();
  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. updateHeaderMinWidth() {
  429. const showButtonCount = Object.values(this.showToolButton).reduce((a, b) => a + (b ? 1 : 0), 0);
  430. if (this.$refs.buttons)
  431. this.$refs.buttons.style.minWidth = 65*showButtonCount + 'px';
  432. (async() => {
  433. await utils.sleep(1000);
  434. if (this.$refs.header)
  435. this.$refs.header.style.overflowX = 'auto';
  436. })();
  437. }
  438. checkSetStorageAccessKey() {
  439. const q = this.$route.query;
  440. if (q['setStorageAccessKey']) {
  441. this.$router.replace(`/reader`);
  442. this.settingsToggle();
  443. this.$nextTick(() => {
  444. this.$refs.settingsPage.enterServerStorageKey(
  445. Buffer.from(utils.fromBase58(q['setStorageAccessKey'])).toString()
  446. );
  447. });
  448. }
  449. }
  450. checkActivateDonateHelpPage() {
  451. const q = this.$route.query;
  452. if (q['donate']) {
  453. this.$router.replace(`/reader`);
  454. this.helpToggle();
  455. this.$nextTick(() => {
  456. this.$refs.helpPage.activateDonateHelpPage();
  457. });
  458. }
  459. }
  460. checkBookPosPercent() {
  461. const q = this.$route.query;
  462. if (q['__pp']) {
  463. let pp = q['__pp'];
  464. if (pp) {
  465. pp = parseFloat(pp) || 0;
  466. const recent = this.mostRecentBook();
  467. (async() => {
  468. await utils.sleep(100);
  469. this.bookPos = Math.floor(recent.textLength*pp/100);
  470. })();
  471. }
  472. }
  473. }
  474. get routeParamPos() {
  475. let result = undefined;
  476. const q = this.$route.query;
  477. if (q['__p']) {
  478. result = q['__p'];
  479. if (Array.isArray(result))
  480. result = result[0];
  481. }
  482. return (result ? parseInt(result, 10) || 0 : result);
  483. }
  484. updateRoute(isNewRoute) {
  485. if (this.loading)
  486. return;
  487. const recent = this.mostRecentBook();
  488. const pos = (recent && recent.bookPos && this.allowUrlParamBookPos ? `__p=${recent.bookPos}&` : '');
  489. const url = (recent ? `url=${recent.url}` : '');
  490. if (isNewRoute)
  491. this.$router.push(`/reader?${pos}${url}`).catch(() => {});
  492. else
  493. this.$router.replace(`/reader?${pos}${url}`).catch(() => {});
  494. }
  495. get mode() {
  496. return this.$store.state.config.mode;
  497. }
  498. get version() {
  499. return this.$store.state.config.version;
  500. }
  501. get clientVersion() {
  502. return versionHistory[0].version;
  503. }
  504. get routeParamUrl() {
  505. let result = '';
  506. const path = this.$route.fullPath;
  507. const i = path.indexOf('url=');
  508. if (i >= 0) {
  509. result = path.substr(i + 4);
  510. }
  511. return decodeURIComponent(result);
  512. }
  513. get routeParamRefresh() {
  514. const q = this.$route.query;
  515. return !!q['__refresh'];
  516. }
  517. bookPosChanged(event) {
  518. if (event.bookPosSeen !== undefined)
  519. this.bookPosSeen = event.bookPosSeen;
  520. this.bookPos = event.bookPos;
  521. }
  522. async bookManagerEvent(eventName, value) {
  523. if (eventName == 'set-recent' || eventName == 'recent-deleted') {
  524. const oldBook = (this.textPage ? this.textPage.lastBook : null);
  525. const oldPos = (this.textPage ? this.textPage.bookPos : null);
  526. const newBook = bookManager.mostRecentBook();
  527. if (!(oldBook && newBook && oldBook.key == newBook.key)) {
  528. this.mostRecentBook();
  529. }
  530. if (oldBook && newBook) {
  531. if (oldBook.key != newBook.key || oldBook.path != newBook.path) {
  532. this.loadingBook = true;
  533. try {
  534. await this.loadBook(newBook);
  535. } finally {
  536. this.loadingBook = false;
  537. }
  538. } else if (oldPos != newBook.bookPos) {
  539. while (this.loadingBook) await utils.sleep(100);
  540. this.bookPosChanged({bookPos: newBook.bookPos});
  541. }
  542. }
  543. }
  544. if (eventName == 'recent-changed') {
  545. if (this.recentBooksActive) {
  546. await this.$refs.recentBooksPage.updateTableData();
  547. }
  548. //сохранение в serverStorage
  549. if (value) {
  550. await utils.sleep(500);
  551. let timer = setTimeout(() => {
  552. if (!this.offlineModeActive)
  553. this.$root.notify.error('Таймаут соединения');
  554. }, 10000);
  555. try {
  556. await this.$refs.serverStorage.saveRecent(value);
  557. } catch (e) {
  558. if (!this.offlineModeActive)
  559. this.$root.notify.error(e.message);
  560. } finally {
  561. clearTimeout(timer);
  562. }
  563. }
  564. }
  565. }
  566. get toolBarActive() {
  567. return this.reader.toolBarActive;
  568. }
  569. mostRecentBook() {
  570. const result = bookManager.mostRecentBook();
  571. this.mostRecentBookReactive = result;
  572. return result;
  573. }
  574. get settings() {
  575. return this.$store.state.reader.settings;
  576. }
  577. addAction(pos) {
  578. let a = this.actionList;
  579. if (!a.length || a[a.length - 1] != pos) {
  580. a.push(pos);
  581. if (a.length > 20)
  582. a.shift();
  583. this.actionCur = a.length - 1;
  584. }
  585. }
  586. toolBarToggle() {
  587. this.commit('reader/setToolBarActive', !this.toolBarActive);
  588. this.$root.eventHook('resize');
  589. }
  590. fullScreenToggle() {
  591. this.fullScreenActive = !this.fullScreenActive;
  592. if (this.fullScreenActive) {
  593. this.$q.fullscreen.request();
  594. } else {
  595. this.$q.fullscreen.exit();
  596. }
  597. }
  598. closeAllWindows() {
  599. this.setPositionActive = false;
  600. this.copyTextActive = false;
  601. this.recentBooksActive = false;
  602. this.settingsActive = false;
  603. this.stopScrolling();
  604. this.stopSearch();
  605. this.helpActive = false;
  606. this.contentsActive = false;
  607. }
  608. loaderToggle() {
  609. this.loaderActive = !this.loaderActive;
  610. if (this.loaderActive) {
  611. this.closeAllWindows();
  612. }
  613. }
  614. loadFileToggle() {
  615. if (!this.loaderActive)
  616. this.loaderToggle();
  617. this.$nextTick(() => {
  618. const page = this.$refs.page;
  619. if (this.activePage == 'LoaderPage' && page.loadFileClick) {
  620. page.loadFileClick();
  621. }
  622. });
  623. }
  624. loadBufferToggle() {
  625. if (!this.loaderActive)
  626. this.loaderToggle();
  627. this.$nextTick(() => {
  628. const page = this.$refs.page;
  629. if (this.activePage == 'LoaderPage' && page.showPasteText) {
  630. page.showPasteText();
  631. }
  632. });
  633. }
  634. setPositionToggle() {
  635. this.setPositionActive = !this.setPositionActive;
  636. const page = this.$refs.page;
  637. if (this.setPositionActive && this.activePage == 'TextPage' && page.parsed) {
  638. this.closeAllWindows();
  639. this.setPositionActive = true;
  640. this.$nextTick(() => {
  641. const recent = this.mostRecentBook();
  642. this.$refs.setPositionPage.init(recent.bookPos, recent.textLength - 1);
  643. });
  644. } else {
  645. this.setPositionActive = false;
  646. }
  647. }
  648. stopScrolling() {
  649. if (this.scrollingActive)
  650. this.scrollingToggle();
  651. }
  652. scrollingToggle() {
  653. this.scrollingActive = !this.scrollingActive;
  654. if (this.activePage == 'TextPage') {
  655. const page = this.$refs.page;
  656. if (this.scrollingActive) {
  657. page.startTextScrolling();
  658. } else {
  659. page.stopTextScrolling();
  660. }
  661. }
  662. if (!this.scrollingActive) {
  663. this.scrollingSetRecentBook.flush();
  664. }
  665. }
  666. stopSearch() {
  667. if (this.searchActive)
  668. this.searchToggle();
  669. }
  670. startTextSearch(opts) {
  671. if (this.activePage == 'TextPage')
  672. this.$refs.page.startSearch(opts.needle);
  673. }
  674. stopTextSearch() {
  675. if (this.activePage == 'TextPage')
  676. this.$refs.page.stopSearch();
  677. }
  678. searchToggle() {
  679. this.searchActive = !this.searchActive;
  680. const page = this.$refs.page;
  681. if (this.searchActive && this.activePage == 'TextPage' && page.parsed) {
  682. this.closeAllWindows();
  683. this.searchActive = true;
  684. this.$nextTick(() => {
  685. this.$refs.searchPage.init(page.parsed);
  686. });
  687. } else {
  688. this.stopTextSearch();
  689. this.searchActive = false;
  690. }
  691. }
  692. copyTextToggle() {
  693. this.copyTextActive = !this.copyTextActive;
  694. const page = this.$refs.page;
  695. if (this.copyTextActive && this.activePage == 'TextPage' && page.parsed) {
  696. this.closeAllWindows();
  697. this.copyTextActive = true;
  698. this.$nextTick(() => {
  699. this.$refs.copyTextPage.init(this.mostRecentBook().bookPos, page.parsed, this.copyFullText);
  700. });
  701. } else {
  702. this.copyTextActive = false;
  703. }
  704. }
  705. recentBooksClose() {
  706. this.recentBooksActive = false;
  707. }
  708. recentBooksToggle() {
  709. this.recentBooksActive = !this.recentBooksActive;
  710. if (this.recentBooksActive) {
  711. this.closeAllWindows();
  712. this.$refs.recentBooksPage.init();
  713. this.recentBooksActive = true;
  714. } else {
  715. this.recentBooksActive = false;
  716. }
  717. }
  718. contentsPageToggle() {
  719. this.contentsActive = !this.contentsActive;
  720. const page = this.$refs.page;
  721. if (this.contentsActive && this.activePage == 'TextPage' && page.parsed) {
  722. this.closeAllWindows();
  723. this.contentsActive = true;
  724. this.$nextTick(() => {
  725. this.$refs.contentsPage.init(this.mostRecentBook(), page.parsed);
  726. });
  727. } else {
  728. this.contentsActive = false;
  729. }
  730. }
  731. libsClose() {
  732. if (this.libsActive)
  733. this.libsToogle();
  734. }
  735. libsToogle() {
  736. this.libsActive = !this.libsActive;
  737. if (this.libsActive) {
  738. this.$refs.libsPage.init();
  739. } else {
  740. this.$refs.libsPage.done();
  741. }
  742. }
  743. clickControlToggle() {
  744. const newSettings = _.cloneDeep(this.settings);
  745. newSettings.clickControl = !this.clickControl;
  746. this.commit('reader/setSettings', newSettings);
  747. }
  748. offlineModeToggle() {
  749. this.offlineModeActive = !this.offlineModeActive;
  750. this.$refs.serverStorage.offlineModeActive = this.offlineModeActive;
  751. }
  752. settingsToggle() {
  753. this.settingsActive = !this.settingsActive;
  754. if (this.settingsActive) {
  755. this.closeAllWindows();
  756. this.settingsActive = true;
  757. this.$nextTick(() => {
  758. this.$refs.settingsPage.init();
  759. });
  760. } else {
  761. this.settingsActive = false;
  762. }
  763. }
  764. convOptionsToggle() {
  765. this.settingsToggle();
  766. if (this.settingsActive)
  767. this.$refs.settingsPage.selectedTab = 'convert';
  768. }
  769. helpToggle() {
  770. this.helpActive = !this.helpActive;
  771. if (this.helpActive) {
  772. this.closeAllWindows();
  773. this.helpActive = true;
  774. }
  775. }
  776. donateToggle() {
  777. this.helpToggle();
  778. if (this.helpActive) {
  779. this.$nextTick(() => {
  780. this.$refs.helpPage.activateDonateHelpPage();
  781. });
  782. }
  783. }
  784. versionHistoryToggle() {
  785. this.helpToggle();
  786. if (this.helpActive) {
  787. this.$nextTick(() => {
  788. this.$refs.helpPage.activateVersionHistoryHelpPage();
  789. });
  790. }
  791. }
  792. refreshBook() {
  793. const mrb = this.mostRecentBook();
  794. this.loadBook({url: mrb.url, uploadFileName: mrb.uploadFileName, force: true});
  795. }
  796. undoAction() {
  797. if (this.actionCur > 0) {
  798. this.actionCur--;
  799. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  800. }
  801. }
  802. redoAction() {
  803. if (this.actionCur < this.actionList.length - 1) {
  804. this.actionCur++;
  805. this.bookPosChanged({bookPos: this.actionList[this.actionCur]});
  806. }
  807. }
  808. buttonClick(action) {
  809. const activeClass = this.buttonActiveClass(action);
  810. this.$refs[action].blur();
  811. if (activeClass['tool-button-disabled'])
  812. return;
  813. this.doAction({action});
  814. }
  815. buttonActiveClass(action) {
  816. const classActive = { 'tool-button-active': true, 'tool-button-active:hover': true };
  817. const classDisabled = { 'tool-button-disabled': true, 'tool-button-disabled:hover': true };
  818. let classResult = {};
  819. switch (action) {
  820. case 'loader':
  821. case 'loadFile':
  822. case 'loadBuffer':
  823. case 'help':
  824. case 'fullScreen':
  825. case 'setPosition':
  826. case 'search':
  827. case 'copyText':
  828. case 'convOptions':
  829. case 'refresh':
  830. case 'contents':
  831. case 'libs':
  832. case 'recentBooks':
  833. case 'clickControl':
  834. case 'offlineMode':
  835. case 'settings':
  836. if (this.progressActive) {
  837. classResult = classDisabled;
  838. } else if (this[`${action}Active`]) {
  839. classResult = classActive;
  840. }
  841. break;
  842. case 'scrolling':
  843. if (this.progressActive || this.dualPageMode) {
  844. classResult = classDisabled;
  845. } else if (this[`${action}Active`]) {
  846. classResult = classActive;
  847. }
  848. break;
  849. case 'undoAction':
  850. if (this.actionCur <= 0)
  851. classResult = classDisabled;
  852. break;
  853. case 'redoAction':
  854. if (this.actionCur == this.actionList.length - 1)
  855. classResult = classDisabled;
  856. break;
  857. }
  858. if (this.activePage == 'LoaderPage' || !this.mostRecentBookReactive) {
  859. switch (action) {
  860. case 'undoAction':
  861. case 'redoAction':
  862. case 'setPosition':
  863. case 'scrolling':
  864. case 'search':
  865. case 'copyText':
  866. case 'contents':
  867. classResult = classDisabled;
  868. break;
  869. case 'refresh':
  870. case 'recentBooks':
  871. if (!this.mostRecentBookReactive)
  872. classResult = classDisabled;
  873. break;
  874. }
  875. }
  876. return classResult;
  877. }
  878. async activateClickMapPage() {
  879. if (this.clickControl && this.showClickMapPage && !this.clickMapActive) {
  880. this.clickMapActive = true;
  881. await this.$refs.clickMapPage.slowDisappear();
  882. this.clickMapActive = false;
  883. }
  884. }
  885. get activePage() {
  886. let result = undefined;
  887. if (this.progressActive)
  888. result = 'ProgressPage';
  889. else if (this.loaderActive)
  890. result = 'LoaderPage';
  891. else if (this.mostRecentBookReactive)
  892. result = 'TextPage';
  893. if (!result && !this.loading) {
  894. this.loaderActive = true;
  895. result = 'LoaderPage';
  896. }
  897. if (result != 'TextPage') {
  898. this.$root.setAppTitle();
  899. }
  900. // на LoaderPage всегда показываем toolBar
  901. if (result == 'LoaderPage' && !this.toolBarActive) {
  902. this.toolBarToggle();
  903. }
  904. if (this.lastActivePage != result && result == 'TextPage') {
  905. //акивируем страницу с текстом
  906. this.$nextTick(async() => {
  907. const last = this.mostRecentBookReactive;
  908. const isParsed = await bookManager.hasBookParsed(last);
  909. if (!isParsed) {
  910. this.$root.setAppTitle();
  911. return;
  912. }
  913. this.updateRoute();
  914. const textPage = this.$refs.page;
  915. if (textPage.showBook) {
  916. this.textPage = textPage;
  917. textPage.lastBook = last;
  918. textPage.bookPos = (last.bookPos !== undefined ? last.bookPos : 0);
  919. textPage.showBook();
  920. }
  921. });
  922. }
  923. this.lastActivePage = result;
  924. return result;
  925. }
  926. async loadBook(opts) {
  927. if (!opts || !opts.url) {
  928. this.mostRecentBook();
  929. return;
  930. }
  931. this.closeAllWindows();
  932. let url = encodeURI(decodeURI(opts.url));
  933. //TODO: убрать конвертирование 'file://' после 06.2021
  934. if (url.length == 71 && url.indexOf('file://') == 0)
  935. url = url.replace(/^file/, 'disk');
  936. if ((url.indexOf('http://') != 0) && (url.indexOf('https://') != 0) &&
  937. (url.indexOf('disk://') != 0))
  938. url = 'http://' + url;
  939. // уже просматривается сейчас
  940. const lastBook = (this.textPage ? this.textPage.lastBook : null);
  941. if (!opts.force && lastBook && lastBook.url == url &&
  942. (!opts.path || opts.path == lastBook.path) &&
  943. await bookManager.hasBookParsed(lastBook)) {
  944. this.loaderActive = false;
  945. return;
  946. }
  947. this.progressActive = true;
  948. await this.$nextTick();
  949. const progress = this.$refs.page;
  950. this.actionList = [];
  951. this.actionCur = -1;
  952. try {
  953. progress.show();
  954. progress.setState({state: 'parse'});
  955. // есть ли среди недавних
  956. const key = bookManager.keyFromUrl(url);
  957. let wasOpened = await bookManager.getRecentBook({key});
  958. wasOpened = (wasOpened ? wasOpened : {});
  959. const bookPos = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPos);
  960. const bookPosSeen = (opts.bookPos !== undefined ? opts.bookPos : wasOpened.bookPosSeen);
  961. const uploadFileName = (opts.uploadFileName ? opts.uploadFileName : '');
  962. let book = null;
  963. if (!opts.force) {
  964. // пытаемся загрузить и распарсить книгу в менеджере из локального кэша
  965. const bookParsed = await bookManager.getBook({url, path: opts.path}, (prog) => {
  966. progress.setState({progress: prog});
  967. });
  968. // если есть в локальном кэше
  969. if (bookParsed) {
  970. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen}, bookParsed));
  971. this.mostRecentBook();
  972. this.addAction(bookPos);
  973. this.loaderActive = false;
  974. progress.hide(); this.progressActive = false;
  975. this.blinkCachedLoadMessage();
  976. this.checkBookPosPercent();
  977. await this.activateClickMapPage();
  978. return;
  979. }
  980. // иначе идем на сервер
  981. // пытаемся загрузить готовый файл с сервера
  982. if (wasOpened.path) {
  983. progress.setState({totalSteps: 5});
  984. try {
  985. const resp = await readerApi.loadCachedBook(wasOpened.path, (state) => {
  986. progress.setState(state);
  987. });
  988. book = Object.assign({}, wasOpened, {data: resp.data});
  989. } catch (e) {
  990. //молчим
  991. }
  992. }
  993. }
  994. progress.setState({totalSteps: 5});
  995. // не удалось, скачиваем книгу полностью с конвертацией
  996. let loadCached = true;
  997. if (!book) {
  998. book = await readerApi.loadBook({
  999. url,
  1000. uploadFileName,
  1001. enableSitesFilter: this.enableSitesFilter,
  1002. skipHtmlCheck: (this.splitToPara ? true : false),
  1003. isText: (this.splitToPara ? true : false),
  1004. djvuQuality: this.djvuQuality,
  1005. pdfAsText: this.pdfAsText,
  1006. pdfQuality: this.pdfQuality,
  1007. },
  1008. (state) => {
  1009. progress.setState(state);
  1010. }
  1011. );
  1012. loadCached = false;
  1013. }
  1014. // добавляем в bookManager
  1015. progress.setState({state: 'parse', step: 5});
  1016. const addedBook = await bookManager.addBook(book, (prog) => {
  1017. progress.setState({progress: prog});
  1018. });
  1019. // добавляем в историю
  1020. await bookManager.setRecentBook(Object.assign({bookPos, bookPosSeen, uploadFileName}, addedBook));
  1021. this.mostRecentBook();
  1022. this.addAction(bookPos);
  1023. this.updateRoute(true);
  1024. this.loaderActive = false;
  1025. progress.hide(); this.progressActive = false;
  1026. if (loadCached) {
  1027. this.blinkCachedLoadMessage();
  1028. } else
  1029. this.stopBlink = true;
  1030. this.checkBookPosPercent();
  1031. await this.activateClickMapPage();
  1032. } catch (e) {
  1033. progress.hide(); this.progressActive = false;
  1034. this.loaderActive = true;
  1035. if (!this.showHelpOnErrorIfNeeded(e.message)) {
  1036. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  1037. }
  1038. } finally {
  1039. this.checkNewVersionAvailable();
  1040. }
  1041. }
  1042. async loadFile(opts) {
  1043. this.progressActive = true;
  1044. await this.$nextTick();
  1045. const progress = this.$refs.page;
  1046. try {
  1047. progress.show();
  1048. progress.setState({state: 'upload'});
  1049. const url = await readerApi.uploadFile(opts.file, this.config.maxUploadFileSize, (state) => {
  1050. progress.setState(state);
  1051. });
  1052. progress.hide(); this.progressActive = false;
  1053. await this.loadBook({url, uploadFileName: opts.file.name, force: true});
  1054. } catch (e) {
  1055. progress.hide(); this.progressActive = false;
  1056. this.loaderActive = true;
  1057. this.$root.stdDialog.alert(e.message, 'Ошибка', {color: 'negative'});
  1058. }
  1059. }
  1060. blinkCachedLoadMessage() {
  1061. if (!this.blinkCachedLoad)
  1062. return;
  1063. this.blinkCount = 30;
  1064. if (!this.inBlink) {
  1065. this.inBlink = true;
  1066. this.stopBlink = false;
  1067. this.$nextTick(async() => {
  1068. let page = this.$refs.page;
  1069. while (this.blinkCount) {
  1070. this.showRefreshIcon = !this.showRefreshIcon;
  1071. if (page && page.blinkCachedLoadMessage)
  1072. page.blinkCachedLoadMessage(this.showRefreshIcon);
  1073. await utils.sleep(500);
  1074. if (this.stopBlink)
  1075. break;
  1076. this.blinkCount--;
  1077. page = this.$refs.page;
  1078. }
  1079. this.showRefreshIcon = true;
  1080. this.inBlink = false;
  1081. if (page && page.blinkCachedLoadMessage)
  1082. page.blinkCachedLoadMessage('finish');
  1083. });
  1084. }
  1085. }
  1086. doAction(opts) {
  1087. let result = true;
  1088. let {action = '', event = false} = opts;
  1089. switch (action) {
  1090. case 'loader':
  1091. this.loaderToggle();
  1092. break;
  1093. case 'loadFile':
  1094. this.loadFileToggle();
  1095. break;
  1096. case 'loadBuffer':
  1097. this.loadBufferToggle();
  1098. break;
  1099. case 'help':
  1100. this.helpToggle();
  1101. break;
  1102. case 'undoAction':
  1103. this.undoAction();
  1104. break;
  1105. case 'redoAction':
  1106. this.redoAction();
  1107. break;
  1108. case 'fullScreen':
  1109. this.fullScreenToggle();
  1110. break;
  1111. case 'scrolling':
  1112. this.scrollingToggle();
  1113. break;
  1114. case 'stopScrolling':
  1115. this.stopScrolling();
  1116. break;
  1117. case 'setPosition':
  1118. this.setPositionToggle();
  1119. break;
  1120. case 'search':
  1121. this.searchToggle();
  1122. break;
  1123. case 'copyText':
  1124. this.copyTextToggle();
  1125. break;
  1126. case 'convOptions':
  1127. this.convOptionsToggle();
  1128. break;
  1129. case 'refresh':
  1130. this.refreshBook();
  1131. break;
  1132. case 'contents':
  1133. this.contentsPageToggle();
  1134. break;
  1135. case 'libs':
  1136. this.libsToogle();
  1137. break;
  1138. case 'recentBooks':
  1139. this.recentBooksToggle();
  1140. break;
  1141. case 'clickControl':
  1142. this.clickControlToggle();
  1143. break;
  1144. case 'offlineMode':
  1145. this.offlineModeToggle();
  1146. break;
  1147. case 'settings':
  1148. this.settingsToggle();
  1149. break;
  1150. case 'switchToolbar':
  1151. this.toolBarToggle();
  1152. break;
  1153. case 'donate':
  1154. this.donateToggle();
  1155. break;
  1156. default:
  1157. result = false;
  1158. break;
  1159. }
  1160. if (!result && this.activePage == 'TextPage' && this.$refs.page) {
  1161. result = true;
  1162. const textPage = this.$refs.page;
  1163. switch (action) {
  1164. case 'bookBegin':
  1165. textPage.doHome();
  1166. break;
  1167. case 'bookEnd':
  1168. textPage.doEnd();
  1169. break;
  1170. case 'pageBack':
  1171. textPage.doPageUp();
  1172. break;
  1173. case 'pageForward':
  1174. textPage.doPageDown();
  1175. break;
  1176. case 'lineBack':
  1177. textPage.doUp();
  1178. break;
  1179. case 'lineForward':
  1180. textPage.doDown();
  1181. break;
  1182. case 'incFontSize':
  1183. textPage.doFontSizeInc();
  1184. break;
  1185. case 'decFontSize':
  1186. textPage.doFontSizeDec();
  1187. break;
  1188. case 'scrollingSpeedUp':
  1189. textPage.doScrollingSpeedUp();
  1190. break;
  1191. case 'scrollingSpeedDown':
  1192. textPage.doScrollingSpeedDown();
  1193. break;
  1194. default:
  1195. result = false;
  1196. break;
  1197. }
  1198. }
  1199. if (result && event) {
  1200. event.preventDefault();
  1201. event.stopPropagation();
  1202. }
  1203. return result;
  1204. }
  1205. keyHook(event) {
  1206. let result = false;
  1207. if (this.$root.getRootRoute() == '/reader') {
  1208. if (this.$root.stdDialog.active)
  1209. return result;
  1210. if (!result)
  1211. result = this.$refs.dialogs.keyHook(event);
  1212. if (!result && this.helpActive)
  1213. result = this.$refs.helpPage.keyHook(event);
  1214. if (!result && this.settingsActive)
  1215. result = this.$refs.settingsPage.keyHook(event);
  1216. if (!result && this.recentBooksActive)
  1217. result = this.$refs.recentBooksPage.keyHook(event);
  1218. if (!result && this.setPositionActive)
  1219. result = this.$refs.setPositionPage.keyHook(event);
  1220. if (!result && this.searchActive)
  1221. result = this.$refs.searchPage.keyHook(event);
  1222. if (!result && this.copyTextActive)
  1223. result = this.$refs.copyTextPage.keyHook(event);
  1224. if (!result && this.contentsActive)
  1225. result = this.$refs.contentsPage.keyHook(event);
  1226. if (!result && this.$refs.page && this.$refs.page.keyHook)
  1227. result = this.$refs.page.keyHook(event);
  1228. if (!result && event.type == 'keydown') {
  1229. const action = this.$root.readerActionByKeyEvent(event);
  1230. /*if (action == 'loader') {
  1231. result = this.doAction({action, event});
  1232. }
  1233. if (!result && this.activePage == 'TextPage') {
  1234. result = this.doAction({action, event});
  1235. }*/
  1236. result = this.doAction({action, event});
  1237. }
  1238. }
  1239. return result;
  1240. }
  1241. }
  1242. export default vueComponent(Reader);
  1243. //-----------------------------------------------------------------------------
  1244. </script>
  1245. <style scoped>
  1246. .header {
  1247. padding-left: 5px;
  1248. padding-right: 5px;
  1249. background-color: #1B695F;
  1250. color: #000;
  1251. overflow: hidden;
  1252. height: 50px;
  1253. }
  1254. .main {
  1255. background-color: #EBE2C9;
  1256. color: #000;
  1257. }
  1258. .tool-button {
  1259. margin: 0px 2px 0 2px;
  1260. padding: 0;
  1261. color: #3E843E;
  1262. background-color: #E6EDF4;
  1263. margin-top: 5px;
  1264. height: 38px;
  1265. width: 38px;
  1266. border: 0;
  1267. border-radius: 6px;
  1268. box-shadow: 3px 3px 5px black;
  1269. outline: 0;
  1270. }
  1271. .tool-button:hover {
  1272. background-color: white;
  1273. cursor: pointer;
  1274. }
  1275. .tool-button-active {
  1276. box-shadow: 0 0 0;
  1277. color: white;
  1278. background-color: #8AB45F;
  1279. position: relative;
  1280. top: 1px;
  1281. left: 1px;
  1282. }
  1283. .tool-button-active:hover {
  1284. color: white;
  1285. background-color: #81C581;
  1286. cursor: pointer;
  1287. }
  1288. .tool-button-disabled {
  1289. color: lightgray;
  1290. background-color: gray;
  1291. cursor: default;
  1292. }
  1293. .tool-button-disabled:hover {
  1294. color: lightgray;
  1295. background-color: gray;
  1296. cursor: default;
  1297. }
  1298. .space {
  1299. width: 10px;
  1300. display: inline-block;
  1301. }
  1302. .clear {
  1303. color: rgba(0,0,0,0);
  1304. }
  1305. </style>