Reader.vue 56 KB

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