summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2019-03-17 16:09:08 +0300
committerAndrew Dolgov <[email protected]>2019-03-17 16:09:08 +0300
commitffdbe905b5aea4c88aa4b7df2fa9b28b7610239a (patch)
tree30342cea5973fc7e03a2954efc550d91fdfd821b
parented54f4da3591b3ca290d62e954d8396d117cc6f1 (diff)
openfile: fix race condition
-rwxr-xr-xreader.js86
1 files changed, 43 insertions, 43 deletions
diff --git a/reader.js b/reader.js
index 8907554..d7f46a2 100755
--- a/reader.js
+++ b/reader.js
@@ -112,66 +112,66 @@ function Model() {
};
self.openFile = function (file) {
- self.closeFile();
+ model.closeFile().then(() => {
+ console.log('openFile', file, typeof file);
- console.log('openFile', file, typeof file);
+ if (typeof file != "string") {
+ self.errorMessage("Can't open file: incorrect type.");
+ return;
+ }
- if (typeof file != "string") {
- self.errorMessage("Can't open file: incorrect type.");
- return;
- }
+ self.isLoading(true);
- self.isLoading(true);
+ window.setTimeout(() => {
- window.setTimeout(() => {
+ try {
+ const AdmZip = require('adm-zip');
+ self._zip = new AdmZip(file);
- try {
- const AdmZip = require('adm-zip');
- self._zip = new AdmZip(file);
+ const zipEntries = self._zip.getEntries();
- const zipEntries = self._zip.getEntries();
+ for (let i = 0; i < zipEntries.length; i++) {
+ const ze = zipEntries[i];
- for (let i = 0; i < zipEntries.length; i++) {
- const ze = zipEntries[i];
-
- if (ze.entryName.match(/\.(jpe?g|gif|bmp|png|webp)$/i)) {
- // prevent observer events (?) - open faster
- self._zipEntries().push(ze);
+ if (ze.entryName.match(/\.(jpe?g|gif|bmp|png|webp)$/i)) {
+ // prevent observer events (?) - open faster
+ self._zipEntries().push(ze);
+ }
}
- }
- self._zipEntries.sort(function(a, b) {
- return a.entryName.localeCompare(b.entryName);
- });
+ self._zipEntries.sort(function(a, b) {
+ return a.entryName.localeCompare(b.entryName);
+ });
- localforage.setItem("TTC:LAST-OPENED-FILE", file).then(() => {
- self.mruList(file);
- self.fileName(file.split(/[\\/]/).pop());
+ localforage.setItem("TTC:LAST-OPENED-FILE", file).then(() => {
+ self.mruList(file);
+ self.fileName(file.split(/[\\/]/).pop());
- localforage.getItem(model.cacheKey("SINGLE-COLUMN")).then((single) => {
- model.singleColumn(single);
+ localforage.getItem(model.cacheKey("SINGLE-COLUMN")).then((single) => {
+ model.singleColumn(single);
- localforage.getItem(model.cacheKey("FLIP-COLUMNS")).then((flip) => {
- model.flipColumns(flip);
- });
+ localforage.getItem(model.cacheKey("FLIP-COLUMNS")).then((flip) => {
+ model.flipColumns(flip);
+ });
- localforage.getItem(self.cacheKey("POSITION")).then((page) => {
- if (page)
- self.currentPage(page);
- else
- self.currentPage(0);
+ localforage.getItem(self.cacheKey("POSITION")).then((page) => {
+ if (page)
+ self.currentPage(page);
+ else
+ self.currentPage(0);
- self.isLoading(false);
+ self.isLoading(false);
+ });
});
});
- });
- } catch (e) {
- console.warn(e);
- self.errorMessage(e.toString());
+ } catch (e) {
+ console.warn(e);
+ self.errorMessage(e.toString());
- self.isLoading(false);
- }
- }, 100);
+ self.isLoading(false);
+ }
+ }, 100);
+ });
};
self.documentTitle = ko.computed(function () {