Skip to content

TagSpaces is an offline, open source, document manager with tagging support

viewers - new promise api reafctoring

Borislav Sapundzhiev8aee1aabf837
diff --git a/data/ext/viewerBrowser/extension.js b/data/ext/viewerBrowser/extension.js
index d592450a4..3967b7c9e 100644
--- a/data/ext/viewerBrowser/extension.js
+++ b/data/ext/viewerBrowser/extension.js
@@ -50,7 +50,15 @@ define(function(require, exports, module) {
"nwdisable": "",
"nwfaketop": ""
}));
- TSCORE.IO.loadTextFile(filePath);
+
+ TSCORE.IO.loadTextFilePromise(filePath).then(function(content) {
+ exports.setContent(content);
+ },
+ function(error) {
+ TSCORE.hideLoadingAnimation();
+ TSCORE.showAlertDialog("Loading " + filePath + " failed.");
+ console.error("Loading file " + filePath + " failed " + error);
+ });
} else {
$containerElement.append($('<iframe>', {
// sandbox: "allow-same-origin allow-scripts", // comment out due not loading pdfs in chrome ext
diff --git a/data/ext/viewerHTML/extension.js b/data/ext/viewerHTML/extension.js
index 9ec41cdb5..0406a65ce 100644
--- a/data/ext/viewerHTML/extension.js
+++ b/data/ext/viewerHTML/extension.js
@@ -39,9 +39,15 @@ define(function(require, exports, module) {
//"nwfaketop": "",
"src": extensionDirectory + "/index.html?&locale=" + TSCORE.currentLanguage,
}));
-
- TSCORE.IO.loadTextFile(filePath);
-
+
+ TSCORE.IO.loadTextFilePromise(filePath).then(function(content) {
+ exports.setContent(content);
+ },
+ function(error) {
+ TSCORE.hideLoadingAnimation();
+ TSCORE.showAlertDialog("Loading " + filePath + " failed.");
+ console.error("Loading file " + filePath + " failed " + error);
+ });
/*window.addEventListener("message", receiveMessage, false);
function receiveMessage(event) {
console.log("Test event: " + event);
diff --git a/data/ext/viewerMD/extension.js b/data/ext/viewerMD/extension.js
index ff8092454..e19ad6f8c 100644
--- a/data/ext/viewerMD/extension.js
+++ b/data/ext/viewerMD/extension.js
@@ -60,8 +60,15 @@ define(function(require, exports, module) {
smartLists: true,
smartypants: false
});
-
- TSCORE.IO.loadTextFile(filePath);
+
+ TSCORE.IO.loadTextFilePromise(filePath).then(function(content) {
+ exports.setContent(content);
+ },
+ function(error) {
+ TSCORE.hideLoadingAnimation();
+ TSCORE.showAlertDialog("Loading " + filePath + " failed.");
+ console.error("Loading file " + filePath + " failed " + error);
+ });
});
};
diff --git a/data/ext/viewerText/extension.js b/data/ext/viewerText/extension.js
index 2aa1f0fea..3e8169665 100644
--- a/data/ext/viewerText/extension.js
+++ b/data/ext/viewerText/extension.js
@@ -29,7 +29,14 @@ define(function(require, exports, module) {
containerElID = containerElementID;
$containerElement = $('#' + containerElID);
filePath = fPath;
- TSCORE.IO.loadTextFile(filePath, true);
+ TSCORE.IO.loadTextFilePromise(filePath).then(function(content) {
+ exports.setContent(content);
+ },
+ function(error) {
+ TSCORE.hideLoadingAnimation();
+ TSCORE.showAlertDialog("Loading " + filePath + " failed.");
+ console.error("Loading file " + filePath + " failed " + error);
+ });
};
exports.setFileType = function(fileType) {
diff --git a/data/ext/viewerURL/extension.js b/data/ext/viewerURL/extension.js
index ac4a35f72..c9b2bb514 100644
--- a/data/ext/viewerURL/extension.js
+++ b/data/ext/viewerURL/extension.js
@@ -25,7 +25,14 @@ define(function(require, exports, module) {
$('#' + containerElID).attr("style", "background-color: white;");
currentFilePath = filePath;
require(['css!' + extensionDirectory + '/extension.css'], function() {
- TSCORE.IO.loadTextFile(filePath);
+ TSCORE.IO.loadTextFilePromise(filePath).then(function(content) {
+ exports.setContent(content);
+ },
+ function(error) {
+ TSCORE.hideLoadingAnimation();
+ TSCORE.showAlertDialog("Loading " + filePath + " failed.");
+ console.error("Loading file " + filePath + " failed " + error);
+ });
});
};
diff --git a/data/ext/viewerZIP/extension.js b/data/ext/viewerZIP/extension.js
index 84b121cce..b2f14539c 100644
--- a/data/ext/viewerZIP/extension.js
+++ b/data/ext/viewerZIP/extension.js
@@ -60,7 +60,7 @@ define(function(require, exports, module) {
TSCORE.showLoadingAnimation();
- TSCORE.IO.getFileContent(filePath, function(content) {
+ TSCORE.IO.getFileContentPromise(filePath).then(function(content) {
var zipFile = new JSZip(content);
$previewElement.append("<p> Contents of file " + filePath + "</p>");
var ulFiles = $previewElement.append("<ul/>");