several fixes and tweaks + cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-12-10 19:13:48 +03:00
parent 7db2efd948
commit 0f10178948
9 changed files with 84 additions and 141 deletions

View File

@ -811,7 +811,7 @@ module.WindowedAppControl = core.ImageGridFeatures.Feature({
//--------------------------------------------------------------------- //---------------------------------------------------------------------
var AppControl = var AppControl =
module.AppControl = core.ImageGridFeatures.Feature('ui-app-control', [ module.AppControl = core.ImageGridFeatures.Feature('app-control', [
'ui-windowed-app-control', 'ui-windowed-app-control',
'ui-portable-app-control', 'ui-portable-app-control',
]) ])

View File

@ -29,33 +29,12 @@ if(typeof(process) != 'undefined'){
/*********************************************************************/ /*********************************************************************/
// XXX what we need here is:
// - base introspection
// - list features
// - list actions
// - list action scripts / commands
// - call action
// - call action script (a-la git commands)
// - repl (debug/testing)
//
// XXX the main functionality:
// - make previews
// - make index
// - merge
// - clone
//
// XXX a different approach to this would be an "external" cli controller
// script that would contain only cli code and load the ImageGrid
// only in the handler...
// + would be allot faster to load.
// + more flexible as we can load more than one instance...
// This could still be done via features, just load the cli feature
// alone at first and then either create new instances or setup
// additional features as needed...
var CLIActions = actions.Actions({ var CLIActions = actions.Actions({
config: {
// XXX do we care that something is not "ready" here???
'declare-ready-timeout': 0,
},
help: ['- System/Show action help', help: ['- System/Show action help',
function(...actions){ function(...actions){
@ -201,6 +180,7 @@ var CLIActions = actions.Actions({
startREPL: ['- System/Start CLI interpreter', startREPL: ['- System/Start CLI interpreter',
{cli: '@repl'}, {cli: '@repl'},
function(){ function(){
var that = this
var repl = nodeRequire('repl') var repl = nodeRequire('repl')
this.__keep_running = true this.__keep_running = true
@ -230,8 +210,7 @@ var CLIActions = actions.Actions({
//ignoreUndefined: true, //ignoreUndefined: true,
}) })
.on('exit', function(){ .on('exit', function(){
//ig.stop() that.stop() }) }],
process.exit() }) }],
// XXX this is the wrong strategy... // XXX this is the wrong strategy...
// XXX move this to a feature that requires electron... // XXX move this to a feature that requires electron...
// ...and move electron to an optional dependency... // ...and move electron to an optional dependency...
@ -295,12 +274,14 @@ var CLIActions = actions.Actions({
}], }],
//*/ //*/
// XXX test...
// XXX report that can't find an index... // XXX report that can't find an index...
// XXX move options to generic object for re-use...
cliExportImages: ['- System/Export images', cliExportImages: ['- System/Export images',
{cli: argv && argv.Parser({ {cli: argv && argv.Parser({
key: '@export', key: '@export',
//usage: '$SCRIPTNAME to=PATH [OPTIONS]',
// help... // help...
'-help-pattern': { '-help-pattern': {
doc: 'Show image filename pattern info and exit', doc: 'Show image filename pattern info and exit',
@ -351,9 +332,20 @@ var CLIActions = actions.Actions({
})}, })},
function(path, options={}){ function(path, options={}){
var that = this var that = this
return this.loadIndex(path || options.path || '.')
.then(function(){ path = path || options.from
return that.exportImages(options) }) }], path = util.normalizePath(
path ?
pathlib.resolve(process.cwd(), path)
: process.cwd())
return this.loadIndex(path)
.then(
function(){
return that.exportImages(options) },
// XXX for some reason we still get an error up the call stack...
function(err){
console.error('Can\'t find or load index at:', path) }) }],
// Utility... (EXPERIMENTAL) // Utility... (EXPERIMENTAL)
// //
@ -470,6 +462,7 @@ module.CLI = core.ImageGridFeatures.Feature({
var that = this var that = this
var pkg = nodeRequire('./package.json') var pkg = nodeRequire('./package.json')
var wait_for = []
argv.Parser({ argv.Parser({
context: this, context: this,
@ -495,7 +488,7 @@ module.CLI = core.ImageGridFeatures.Feature({
// ...load sets of features and allow user // ...load sets of features and allow user
// to block/add specific features... // to block/add specific features...
// XXX feature config... // XXX config editor...
// ...get/set persistent config values... // ...get/set persistent config values...
// build the action command list... // build the action command list...
@ -510,17 +503,18 @@ module.CLI = core.ImageGridFeatures.Feature({
: (cmd.key || cmd.name) : (cmd.key || cmd.name)
res[name] = cmd instanceof argv.Parser ? res[name] = cmd instanceof argv.Parser ?
// parser...
cmd cmd
// XXX need to call the action...
.then(function(unhandled, value, rest){ .then(function(unhandled, value, rest){
that[action](value, this) }) wait_for.push(that[action](value, this)) })
// single option definition...
: { : {
doc: (that.getActionAttr(action, 'doc') || '') doc: (that.getActionAttr(action, 'doc') || '')
.split(/[\\\/]/g).pop(), .split(/[\\\/]/g).pop(),
// XXX revise argument passing...
// ...this must be as flexible as possible...
handler: function(rest, key, value){ handler: function(rest, key, value){
return that[action](value) }, var res = that[action](value)
wait_for.push(res)
return res },
...cmd, ...cmd,
} }
@ -533,21 +527,19 @@ module.CLI = core.ImageGridFeatures.Feature({
args.push('--help') args.push('--help')
//args.push('gui') //args.push('gui')
}) })
.stop(function(){ process.exit() })
.error(function(){ process.exit() })
.then(function(){ .then(function(){
// XXX // XXX
})() })()
// XXX is this the right way to trigger state change
// from within a state action... // XXX not all promises in the system resolve strictly
!this.__keep_running // after all the work is done, some resolve before that
&& this.afterAction(function(){ // point and this calling process.exit() will interrupt
// NOTE: the timeout is here to let the progress bar // them...
// catch up drawing... this.__keep_running
setTimeout(process.exit.bind(process), 100) }) || this.afterAction(function(){ this.stop() }) }],
// XXX odd, this seems to kill everything BEFORE we
// are done while .afterAction(..) works fine...
//&& setTimeout(process.exit.bind(process), 200)
}],
], ],
}) })

View File

@ -56,15 +56,11 @@ module.Comments = core.ImageGridFeatures.Feature({
['json', ['json',
function(res){ function(res){
if(this.comments != null){ if(this.comments != null){
res.comments = JSON.parse(JSON.stringify(this.comments)) res.comments = JSON.parse(JSON.stringify(this.comments)) } }],
}
}],
['load', ['load',
function(_, data){ function(_, data){
if(data.comments != null){ if(data.comments != null){
this.comments = data.comments this.comments = data.comments } }],
}
}],
// prepare comments for saving to "comments/<keyword>"... // prepare comments for saving to "comments/<keyword>"...
// //
@ -84,10 +80,7 @@ module.Comments = core.ImageGridFeatures.Feature({
// skip the raw field... // skip the raw field...
.filter(function(k){ return k != 'raw' }) .filter(function(k){ return k != 'raw' })
.forEach(function(k){ .forEach(function(k){
res.index['comments/' + k] = comments[k] res.index['comments/' + k] = comments[k] }) } }],
})
}
}],
], ],
}) })
@ -136,8 +129,7 @@ var FileSystemCommentsActions = actions.Actions({
loadComments: ['- File/', loadComments: ['- File/',
function(path, date, logger){ function(path, date, logger){
if(this.location.load != 'loadIndex'){ if(this.location.load != 'loadIndex'){
return return }
}
logger = logger || this.logger logger = logger || this.logger
logger = logger && logger.push('Load comments') logger = logger && logger.push('Load comments')
@ -147,9 +139,7 @@ var FileSystemCommentsActions = actions.Actions({
// prepare empty comments... // prepare empty comments...
// XXX should we reset or just merge??? // XXX should we reset or just merge???
this.comments = { this.comments = { raw: {} }
raw: {}
}
return Promise.all(loaded.map(function(path){ return Promise.all(loaded.map(function(path){
var comments_dir = that.config['index-dir'] +'/comments' var comments_dir = that.config['index-dir'] +'/comments'
@ -160,8 +150,7 @@ var FileSystemCommentsActions = actions.Actions({
// no comments present... // no comments present...
if(c == null){ if(c == null){
return res return res }
}
// if we have no sub-indexes just load the // if we have no sub-indexes just load the
// comments as-is... // comments as-is...
@ -171,13 +160,9 @@ var FileSystemCommentsActions = actions.Actions({
// sub-indexes -> let the client merge their stuff... // sub-indexes -> let the client merge their stuff...
} else { } else {
that.comments.raw[path] = c that.comments.raw[path] = c }
}
return res return res }) })) }],
})
}))
}],
}) })
@ -200,12 +185,13 @@ module.FileSystemComments = core.ImageGridFeatures.Feature({
var that = this var that = this
var delay = that.config['comments-delay-load'] var delay = that.config['comments-delay-load']
res.then(function(){ res.then(
delay < 0 ? function(){
that.loadComments() delay < 0 ?
: setTimeout(function(){ that.loadComments()
that.loadComments() }, delay || 0) }) : setTimeout(function(){
}], that.loadComments() }, delay || 0) },
function(){}) }],
], ],
}) })

View File

@ -706,8 +706,7 @@ var LifeCycleActions = actions.Actions({
var stop = this.__stop_handler = function(){ that.stop() } var stop = this.__stop_handler = function(){ that.stop() }
} else { } else {
return return }
}
// set the runtime... // set the runtime...
var runtime = this.runtime = ImageGridFeatures.runtime var runtime = this.runtime = ImageGridFeatures.runtime
@ -761,8 +760,7 @@ var LifeCycleActions = actions.Actions({
// other... // other...
} else { } else {
// XXX // XXX
console.warn('Unknown runtime:', runtime) console.warn('Unknown runtime:', runtime) }
}
// handle ready event... // handle ready event...
// ...if no one requested to do it. // ...if no one requested to do it.
@ -773,9 +771,7 @@ var LifeCycleActions = actions.Actions({
$(function(){ that.declareReady('start') }) $(function(){ that.declareReady('start') })
} else { } else {
this.declareReady('start') this.declareReady('start') } }
}
}
// ready timeout -> force ready... // ready timeout -> force ready...
this.config['declare-ready-timeout'] > 0 this.config['declare-ready-timeout'] > 0
@ -807,8 +803,7 @@ var LifeCycleActions = actions.Actions({
}.bind(this), this.config['declare-ready-timeout'])) }.bind(this), this.config['declare-ready-timeout']))
// trigger the started event... // trigger the started event...
this.started() this.started() }],
}],
started: ['- System/System started event', started: ['- System/System started event',
doc` doc`
`, `,
@ -868,9 +863,7 @@ var LifeCycleActions = actions.Actions({
|| this.__ready_announce_requested <= 0){ || this.__ready_announce_requested <= 0){
this.__ready = this.__ready this.__ready = this.__ready
|| !!this.ready() || !!this.ready()
delete this.__ready_announce_requested delete this.__ready_announce_requested } }],
}
}],
requestReadyAnnounce: ['- System/', requestReadyAnnounce: ['- System/',
doc`Request to announce the .ready() event. doc`Request to announce the .ready() event.

View File

@ -279,8 +279,7 @@ var FileSystemLoaderActions = actions.Actions({
if(from_date && from_date.emit != null){ if(from_date && from_date.emit != null){
logger = from_date logger = from_date
from_date = null from_date = null }
}
// XXX make this load incrementally (i.e. and EventEmitter // XXX make this load incrementally (i.e. and EventEmitter
// a-la glob).... // a-la glob)....
@ -289,11 +288,6 @@ var FileSystemLoaderActions = actions.Actions({
.then(function(res){ .then(function(res){
var force_full_save = false var force_full_save = false
// XXX if res is empty load raw...
// XXX use the logger...
//console.log('FOUND INDEXES:', Object.keys(res).length)
// skip nested paths... // skip nested paths...
// //
// XXX make this optional... // XXX make this optional...
@ -301,12 +295,15 @@ var FileSystemLoaderActions = actions.Actions({
// indexes, e.g. in .loadIndex(..) // indexes, e.g. in .loadIndex(..)
var skipped = new Set() var skipped = new Set()
var paths = Object.keys(res) var paths = Object.keys(res)
// no indexes found...
if(paths.length == 0){
logger && logger.emit('error: no index at', path)
return Promise.reject('no index at: '+ path) }
paths paths
.forEach(function(p){ .forEach(function(p){
// already removed... // already removed...
if(skipped.has(p) >= 0){ if(skipped.has(p) >= 0){
return } return }
paths paths
// get all paths that fully contain p... // get all paths that fully contain p...
.filter(function(o){ .filter(function(o){
@ -319,8 +316,6 @@ var FileSystemLoaderActions = actions.Actions({
// keep only the valid paths... // keep only the valid paths...
paths = Object.keys(res).sort() paths = Object.keys(res).sort()
//console.log('SKIPPING NESTED:', skipped.length)
var index var index
var base_path var base_path
var loaded = [] var loaded = []
@ -378,15 +373,6 @@ var FileSystemLoaderActions = actions.Actions({
logger && logger.emit('load index', index) logger && logger.emit('load index', index)
// XXX BUG?: some times we reach this point with index
// equaling null
// ...we are not fixing this here as the cause of
// this issue is likely someplace else and that
// needs investigating...
// XXX REMOVE WHEN ISSUE FIXED...
!index
&& console.error('Failed to load index from:', paths)
// prepare the location data... // prepare the location data...
index.location = index.location =
Object.assign( Object.assign(
@ -401,7 +387,8 @@ var FileSystemLoaderActions = actions.Actions({
// this is the critical section, after this point we // this is the critical section, after this point we
// are doing the actual loading.... // are doing the actual loading....
that.loadOrRecover(index) //that.loadOrRecover(index)
return that.loadOrRecover(index)
.then(function(){ .then(function(){
force_full_save force_full_save
// XXX remove as soon as merged index save is done... // XXX remove as soon as merged index save is done...
@ -1002,17 +989,16 @@ module.FileSystemLoader = core.ImageGridFeatures.Feature({
function(res, path){ function(res, path){
if(path){ if(path){
var that = this var that = this
res.then(function(){ res.then(
that.markChanged('none') }) function(){
} that.markChanged('none') },
}], function(){}) } }],
// mark everything changed when loading images... // mark everything changed when loading images...
['loadImages', ['loadImages',
function(res){ function(res){
var that = this var that = this
res.then(function(){ res.then(function(){
that.markChanged('all') }) that.markChanged('all') }) }],
}],
// add new images to changes... // add new images to changes...
['loadNewImages', ['loadNewImages',
function(res){ function(res){
@ -1231,14 +1217,9 @@ var FileSystemLoaderUIActions = actions.Actions({
make(txt) make(txt)
.on('open', function(){ .on('open', function(){
that.loadIndex(p) that.loadIndex(p) }) }) }) })
})
})
})
})
.on('open', function(){ .on('open', function(){
o.close() o.close() })
})
return o return o
})], })],

View File

@ -74,7 +74,7 @@ core.ImageGridFeatures.Feature('imagegrid-ui-minimal', [
core.ImageGridFeatures.Feature('imagegrid-ui', [ core.ImageGridFeatures.Feature('imagegrid-ui', [
'imagegrid-ui-minimal', 'imagegrid-ui-minimal',
'ui-app-control', 'app-control',
'ui-progress', 'ui-progress',

View File

@ -36,13 +36,10 @@ var RecoverActions = actions.Actions({
&& this.config['recover-load-errors-to-previous-location']) ? && this.config['recover-load-errors-to-previous-location']) ?
this.location this.location
: false : false
return function(){ return function(){
// all went well clear the recovery data... // all went well clear the recovery data...
delete this.__recover delete this.__recover } }],
}
}],
// Load data and recover on error... // Load data and recover on error...
// //
@ -87,11 +84,7 @@ var RecoverActions = actions.Actions({
// fail... // fail...
//throw err //throw err
reject(err) reject(err) } } }) }],
}
}
})
}],
// Recover from load error... // Recover from load error...
// //
@ -108,8 +101,7 @@ var RecoverActions = actions.Actions({
// nothing to recover... // nothing to recover...
if(!l){ if(!l){
delete this.__recover delete this.__recover
return return }
}
// NOTE: this will prevent us from entering // NOTE: this will prevent us from entering
// a recover attempt loop... // a recover attempt loop...
@ -118,8 +110,7 @@ var RecoverActions = actions.Actions({
this.__recover = false this.__recover = false
// do the loading... // do the loading...
this.location = l this.location = l }],
}],
}) })
module.Recovery = core.ImageGridFeatures.Feature({ module.Recovery = core.ImageGridFeatures.Feature({

View File

@ -1124,9 +1124,9 @@
} }
}, },
"ig-argv": { "ig-argv": {
"version": "2.15.6", "version": "2.15.7",
"resolved": "https://registry.npmjs.org/ig-argv/-/ig-argv-2.15.6.tgz", "resolved": "https://registry.npmjs.org/ig-argv/-/ig-argv-2.15.7.tgz",
"integrity": "sha512-jQeDbiafqDPKxymYdC81msNEUPEbj5Ocvh4QvucZNFJ0m2DTMxBI4tMgg7IAJJWxlMke1J0U/p7Nhs8m2RStcw==", "integrity": "sha512-o5SpXe6r/mv8TuwMiOr3EmQz2bVmCQ2h9bd4hM9rIJN3LtPh8mtprqC30Yc/+JMtaRH0nkdblGlZKbOJz00wBA==",
"requires": { "requires": {
"ig-object": "^5.2.6" "ig-object": "^5.2.6"
} }

View File

@ -31,7 +31,7 @@
"glob": "^7.1.6", "glob": "^7.1.6",
"guarantee-events": "^1.0.0", "guarantee-events": "^1.0.0",
"ig-actions": "^3.24.22", "ig-actions": "^3.24.22",
"ig-argv": "^2.15.6", "ig-argv": "^2.15.7",
"ig-features": "^3.4.2", "ig-features": "^3.4.2",
"ig-object": "^5.4.12", "ig-object": "^5.4.12",
"ig-types": "^5.0.40", "ig-types": "^5.0.40",