Reader.vue 55 KB

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