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 =
module.AppControl = core.ImageGridFeatures.Feature('ui-app-control', [
module.AppControl = core.ImageGridFeatures.Feature('app-control', [
'ui-windowed-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({
config: {
// XXX do we care that something is not "ready" here???
'declare-ready-timeout': 0,
},
help: ['- System/Show action help',
function(...actions){
@ -201,6 +180,7 @@ var CLIActions = actions.Actions({
startREPL: ['- System/Start CLI interpreter',
{cli: '@repl'},
function(){
var that = this
var repl = nodeRequire('repl')
this.__keep_running = true
@ -230,8 +210,7 @@ var CLIActions = actions.Actions({
//ignoreUndefined: true,
})
.on('exit', function(){
//ig.stop()
process.exit() }) }],
that.stop() }) }],
// XXX this is the wrong strategy...
// XXX move this to a feature that requires electron...
// ...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 move options to generic object for re-use...
cliExportImages: ['- System/Export images',
{cli: argv && argv.Parser({
key: '@export',
//usage: '$SCRIPTNAME to=PATH [OPTIONS]',
// help...
'-help-pattern': {
doc: 'Show image filename pattern info and exit',
@ -351,9 +332,20 @@ var CLIActions = actions.Actions({
})},
function(path, options={}){
var that = this
return this.loadIndex(path || options.path || '.')
.then(function(){
return that.exportImages(options) }) }],
path = path || options.from
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)
//
@ -470,6 +462,7 @@ module.CLI = core.ImageGridFeatures.Feature({
var that = this
var pkg = nodeRequire('./package.json')
var wait_for = []
argv.Parser({
context: this,
@ -495,7 +488,7 @@ module.CLI = core.ImageGridFeatures.Feature({
// ...load sets of features and allow user
// to block/add specific features...
// XXX feature config...
// XXX config editor...
// ...get/set persistent config values...
// build the action command list...
@ -510,17 +503,18 @@ module.CLI = core.ImageGridFeatures.Feature({
: (cmd.key || cmd.name)
res[name] = cmd instanceof argv.Parser ?
// parser...
cmd
// XXX need to call the action...
.then(function(unhandled, value, rest){
that[action](value, this) })
wait_for.push(that[action](value, this)) })
// single option definition...
: {
doc: (that.getActionAttr(action, 'doc') || '')
.split(/[\\\/]/g).pop(),
// XXX revise argument passing...
// ...this must be as flexible as possible...
handler: function(rest, key, value){
return that[action](value) },
var res = that[action](value)
wait_for.push(res)
return res },
...cmd,
}
@ -533,21 +527,19 @@ module.CLI = core.ImageGridFeatures.Feature({
args.push('--help')
//args.push('gui')
})
.stop(function(){ process.exit() })
.error(function(){ process.exit() })
.then(function(){
// XXX
})()
// XXX is this the right way to trigger state change
// from within a state action...
!this.__keep_running
&& this.afterAction(function(){
// NOTE: the timeout is here to let the progress bar
// catch up drawing...
setTimeout(process.exit.bind(process), 100) })
// XXX odd, this seems to kill everything BEFORE we
// are done while .afterAction(..) works fine...
//&& setTimeout(process.exit.bind(process), 200)
}],
// XXX not all promises in the system resolve strictly
// after all the work is done, some resolve before that
// point and this calling process.exit() will interrupt
// them...
this.__keep_running
|| this.afterAction(function(){ this.stop() }) }],
],
})

View File

@ -56,15 +56,11 @@ module.Comments = core.ImageGridFeatures.Feature({
['json',
function(res){
if(this.comments != null){
res.comments = JSON.parse(JSON.stringify(this.comments))
}
}],
res.comments = JSON.parse(JSON.stringify(this.comments)) } }],
['load',
function(_, data){
if(data.comments != null){
this.comments = data.comments
}
}],
this.comments = data.comments } }],
// prepare comments for saving to "comments/<keyword>"...
//
@ -84,10 +80,7 @@ module.Comments = core.ImageGridFeatures.Feature({
// skip the raw field...
.filter(function(k){ return k != 'raw' })
.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/',
function(path, date, logger){
if(this.location.load != 'loadIndex'){
return
}
return }
logger = logger || this.logger
logger = logger && logger.push('Load comments')
@ -147,9 +139,7 @@ var FileSystemCommentsActions = actions.Actions({
// prepare empty comments...
// XXX should we reset or just merge???
this.comments = {
raw: {}
}
this.comments = { raw: {} }
return Promise.all(loaded.map(function(path){
var comments_dir = that.config['index-dir'] +'/comments'
@ -160,8 +150,7 @@ var FileSystemCommentsActions = actions.Actions({
// no comments present...
if(c == null){
return res
}
return res }
// if we have no sub-indexes just load the
// comments as-is...
@ -171,13 +160,9 @@ var FileSystemCommentsActions = actions.Actions({
// sub-indexes -> let the client merge their stuff...
} 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 delay = that.config['comments-delay-load']
res.then(function(){
delay < 0 ?
that.loadComments()
: setTimeout(function(){
that.loadComments() }, delay || 0) })
}],
res.then(
function(){
delay < 0 ?
that.loadComments()
: 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() }
} else {
return
}
return }
// set the runtime...
var runtime = this.runtime = ImageGridFeatures.runtime
@ -761,8 +760,7 @@ var LifeCycleActions = actions.Actions({
// other...
} else {
// XXX
console.warn('Unknown runtime:', runtime)
}
console.warn('Unknown runtime:', runtime) }
// handle ready event...
// ...if no one requested to do it.
@ -773,9 +771,7 @@ var LifeCycleActions = actions.Actions({
$(function(){ that.declareReady('start') })
} else {
this.declareReady('start')
}
}
this.declareReady('start') } }
// ready timeout -> force ready...
this.config['declare-ready-timeout'] > 0
@ -807,8 +803,7 @@ var LifeCycleActions = actions.Actions({
}.bind(this), this.config['declare-ready-timeout']))
// trigger the started event...
this.started()
}],
this.started() }],
started: ['- System/System started event',
doc`
`,
@ -868,9 +863,7 @@ var LifeCycleActions = actions.Actions({
|| this.__ready_announce_requested <= 0){
this.__ready = this.__ready
|| !!this.ready()
delete this.__ready_announce_requested
}
}],
delete this.__ready_announce_requested } }],
requestReadyAnnounce: ['- System/',
doc`Request to announce the .ready() event.

View File

@ -279,8 +279,7 @@ var FileSystemLoaderActions = actions.Actions({
if(from_date && from_date.emit != null){
logger = from_date
from_date = null
}
from_date = null }
// XXX make this load incrementally (i.e. and EventEmitter
// a-la glob)....
@ -289,11 +288,6 @@ var FileSystemLoaderActions = actions.Actions({
.then(function(res){
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...
//
// XXX make this optional...
@ -301,12 +295,15 @@ var FileSystemLoaderActions = actions.Actions({
// indexes, e.g. in .loadIndex(..)
var skipped = new Set()
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
.forEach(function(p){
// already removed...
if(skipped.has(p) >= 0){
return }
paths
// get all paths that fully contain p...
.filter(function(o){
@ -319,8 +316,6 @@ var FileSystemLoaderActions = actions.Actions({
// keep only the valid paths...
paths = Object.keys(res).sort()
//console.log('SKIPPING NESTED:', skipped.length)
var index
var base_path
var loaded = []
@ -378,15 +373,6 @@ var FileSystemLoaderActions = actions.Actions({
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...
index.location =
Object.assign(
@ -401,7 +387,8 @@ var FileSystemLoaderActions = actions.Actions({
// this is the critical section, after this point we
// are doing the actual loading....
that.loadOrRecover(index)
//that.loadOrRecover(index)
return that.loadOrRecover(index)
.then(function(){
force_full_save
// XXX remove as soon as merged index save is done...
@ -1002,17 +989,16 @@ module.FileSystemLoader = core.ImageGridFeatures.Feature({
function(res, path){
if(path){
var that = this
res.then(function(){
that.markChanged('none') })
}
}],
res.then(
function(){
that.markChanged('none') },
function(){}) } }],
// mark everything changed when loading images...
['loadImages',
function(res){
var that = this
res.then(function(){
that.markChanged('all') })
}],
that.markChanged('all') }) }],
// add new images to changes...
['loadNewImages',
function(res){
@ -1231,14 +1217,9 @@ var FileSystemLoaderUIActions = actions.Actions({
make(txt)
.on('open', function(){
that.loadIndex(p)
})
})
})
})
that.loadIndex(p) }) }) }) })
.on('open', function(){
o.close()
})
o.close() })
return o
})],

View File

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

View File

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

View File

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

View File

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