Update preview package

This commit is contained in:
Xuan Sang LE 2020-05-21 14:51:47 +02:00
parent 5df3106328
commit dd58a998d8
5 changed files with 77 additions and 78 deletions

View File

@ -78,11 +78,10 @@
} }
renderPDF(file) { renderPDF(file) {
var q, status; return this.load(new Promise((resolve, reject) => {
var status;
status = `${file.info.name} (${file.info.size} Kb)`; status = `${file.info.name} (${file.info.size} Kb)`;
q = this._api.mid();
return file.read("binary").then((d) => { return file.read("binary").then((d) => {
this._api.loading(q, "RENDERING");
($(this.view)).removeClass(); ($(this.view)).removeClass();
return PDFJS.getDocument({ return PDFJS.getDocument({
data: d data: d
@ -91,7 +90,7 @@
fn = (p) => { fn = (p) => {
if (p > pdf.numPages) { if (p > pdf.numPages) {
this.setStatus(`${status} - loaded`); this.setStatus(`${status} - loaded`);
return this._api.loaded(q, "OK"); return resolve();
} }
return pdf.getPage(p).then((page) => { return pdf.getPage(p).then((page) => {
var canvas, context, div, renderContext, scale, viewport; var canvas, context, div, renderContext, scale, viewport;
@ -111,16 +110,19 @@
page.render(renderContext); page.render(renderContext);
this.setStatus(`${status} - ${p}/${pdf.numPages} loaded`); this.setStatus(`${status} - ${p}/${pdf.numPages} loaded`);
return fn(p + 1); return fn(p + 1);
}).catch(function(e) {
return reject(e);
}); });
}; };
return fn(1); return fn(1);
}).catch((err) => { }).catch(function(e) {
this.error(__("Cannot render the PDF file")); return reject(e);
return this._api.loaded(q, "FAIL");
}); });
}).catch((e) => { }).catch(function(e) {
this._api.loaded(q, "FAIL"); return reject(e);
return this.error(__("Unable to read file: {}", file.path), e); });
})).catch((e) => {
return this.error(__("Unable to view file: {}", file.path), e);
}); });
} }

Binary file not shown.

View File

@ -58,17 +58,16 @@ class Preview extends this.OS.GUI.BaseApplication
($ @status).html t ($ @status).html t
renderPDF: (file) -> renderPDF: (file) ->
@load new Promise (resolve, reject) =>
status = "#{file.info.name} (#{file.info.size} Kb)" status = "#{file.info.name} (#{file.info.size} Kb)"
q = @_api.mid()
file.read("binary").then (d) => file.read("binary").then (d) =>
@_api.loading q, "RENDERING"
($ @view).removeClass() ($ @view).removeClass()
PDFJS.getDocument { data: d } PDFJS.getDocument { data: d }
.then (pdf) => .then (pdf) =>
fn = (p) => fn = (p) =>
if p > pdf.numPages if p > pdf.numPages
@setStatus "#{status} - loaded" @setStatus "#{status} - loaded"
return @_api.loaded q, "OK" return resolve()
pdf.getPage(p).then (page) => pdf.getPage(p).then (page) =>
scale = 1.5 scale = 1.5
viewport = page.getViewport scale viewport = page.getViewport scale
@ -85,13 +84,11 @@ class Preview extends this.OS.GUI.BaseApplication
page.render renderContext page.render renderContext
@setStatus "#{status} - #{p}/#{pdf.numPages} loaded" @setStatus "#{status} - #{p}/#{pdf.numPages} loaded"
fn(p+1) fn(p+1)
.catch (e) -> reject e
fn(1) fn(1)
.catch (err) => .catch (e) -> reject e
@error __("Cannot render the PDF file") .catch (e) -> reject e
@_api.loaded q, "FAIL" .catch (e) => @error __("Unable to view file: {}", file.path), e
.catch (e) =>
@_api.loaded q, "FAIL"
@error __("Unable to read file: {}", file.path), e
renderSVG: (file) -> renderSVG: (file) ->
($ @view).attr("class", "image") ($ @view).attr("class", "image")

View File

@ -6,7 +6,7 @@
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"email": "xsang.le@gmail.com" "email": "xsang.le@gmail.com"
}, },
"version":"0.0.1-a", "version":"0.0.2-a",
"category":"Utils", "category":"Utils",
"iconclass":"fa fa-eye", "iconclass":"fa fa-eye",
"mimes":["[^\/]*/.*pdf", "image/.*"] "mimes":["[^\/]*/.*pdf", "image/.*"]

View File

@ -32,7 +32,7 @@
"description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Preview/README.md", "description": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Preview/README.md",
"category": "Utils", "category": "Utils",
"author": "Xuan Sang LE", "author": "Xuan Sang LE",
"version": "0.0.1-a", "version": "0.0.2-a",
"download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Preview/build/release/Preview.zip" "download": "https://raw.githubusercontent.com/lxsang/antosdk-apps/master/Preview/build/release/Preview.zip"
}, },
{ {