Reader.vue 56 KB

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