stumbled on erros in nw.js blocking moving the preview creation code to a seporate process...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-05-22 23:11:12 +03:00
parent d9f4c52f8c
commit 55ca190585

View File

@ -21,6 +21,7 @@ try{
}
if(typeof(process) != 'undefined'){
var cp = requirejs('child_process')
var fse = requirejs('fs-extra')
var pathlib = requirejs('path')
var glob = requirejs('glob')
@ -45,8 +46,8 @@ var SharpActions = actions.Actions({
'preview-normalized': true,
'preview-sizes': [
//1920,
//1280,
1920,
1280,
900,
350,
150,
@ -54,6 +55,20 @@ var SharpActions = actions.Actions({
]
},
// XXX BUG (nw.js): this does not work until child_process.fork(..) is fixed...
startWorker: ['- Sharp/',
function(){
if(this.previewConstructorWorker){
return
}
this.previewConstructorWorker = cp.form('./worker/preview-constructor')
}],
stopWorker: ['- Sharp/',
function(){
this.previewConstructorWorker && this.previewConstructorWorker.kill()
delete this.previewConstructorWorker
}],
// .makePreviews()
// .makePreviews('current')
// -> actions
@ -68,6 +83,7 @@ var SharpActions = actions.Actions({
// -> actions
//
// XXX should this account for non-jpeg images???
// XXX do this in the background...
makePreviews: ['Sharp/Make image previews',
function(images, sizes, logger){
logger = logger || this.logger
@ -173,6 +189,10 @@ module.Sharp = core.ImageGridFeatures.Feature({
isApplicable: function(){ return !!sharp },
handlers: [
// XXX need to:
// - if image too large to set the preview to "loading..."
// - create previews...
// - update image...
['updateImage.pre',
function(gid){
var that = this
@ -180,9 +200,18 @@ module.Sharp = core.ImageGridFeatures.Feature({
sharp(this.getImagePath(gid))
.metadata()
.then(function(metadata){
// current image is larger than any of the previews...
if(Math.max(metadata.width, metadata.height)
> Math.max.apply(Math, that.config['preview-sizes'])){
// create the currently needed preview first...
that.makePreviews(gid, that.ribbons.getVisibleImageSize())
.then(function(){
// load the created preview...
that.ribbons.updateImage(gid)
// create the rest...
that.makePreviews(gid)
})
}
})
}