Skip to content

Commit

Permalink
Merge branch develop
Browse files Browse the repository at this point in the history
  • Loading branch information
geblanco committed Feb 21, 2019
2 parents 65ec174 + 22ae726 commit b7ffbda
Show file tree
Hide file tree
Showing 43 changed files with 3,297 additions and 3,469 deletions.
98 changes: 49 additions & 49 deletions apps/appUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
depends on child_process
depends on child_process
*/

'use strict'
Expand All @@ -8,68 +8,68 @@ var spawn = require('child_process').spawn;

// Export
module.exports.spawn = function( cmd, opts, cwd ){
if( !cmd ){
throw new Error('Spawner fucked up');
}
if( !opts ){
opts = [];
}else if( !(opts instanceof Array) ){
opts = [opts];
}
Logger.log('[UTILS] Spawning', cmd, 'with options', opts);
var child = spawn(cmd, opts, {
detached: true,
stdio: [ 'ignore', 'ignore', 'ignore' ],
cwd: cwd?cwd:process.cwd()
});
child.unref();
if( !cmd ){
throw new Error('Spawner fucked up');
}
if( !opts ){
opts = [];
}else if( !(opts instanceof Array) ){
opts = [opts];
}
Logger.log('[UTILS] Spawning', cmd, 'with options', opts);
var child = spawn(cmd, opts, {
detached: true,
stdio: [ 'ignore', 'ignore', 'ignore' ],
cwd: cwd?cwd:process.cwd()
});
child.unref();
}

module.exports.strSearch = function( str, query ){
if( typeof str !== 'string' || typeof query !== 'string' ){
return -1;
}
str = str.toLowerCase();
query = query.toLowerCase();
return str.indexOf(query);
if( typeof str !== 'string' || typeof query !== 'string' ){
return -1;
}
str = str.toLowerCase();
query = query.toLowerCase();
return str.indexOf(query);

}

// Given an array of possible regex, clean the query
// out of it, if no match is found null is returned
module.exports.cleanQuery = function( regexArr, query ){

//Logger.log('[APP_UTILS]', 'cleanQuery', 'regexArr', regexArr, 'query', query)
var ret = null;
if( regexArr instanceof Array ){
regexArr.forEach(function( reg ){
if( ret ) return;
if( reg instanceof RegExp ){
ret = reg.exec( query );
}
});
//Logger.log('[APP_UTILS]', 'cleanQuery', 'regexArr', regexArr, 'query', query)
var ret = null;
if( regexArr instanceof Array ){
regexArr.forEach(function( reg ){
if( ret ) return;
if( reg instanceof RegExp ){
ret = reg.exec( query );
}
});

if( ret && ret[1] !== undefined ){
ret = ret[1].trim();
}
}
if( ret && ret[1] !== undefined ){
ret = ret[1].trim();
}
}

Logger.log('[APP_UTILS]', 'cleanQuery', 'result', ret)
Logger.log('[APP_UTILS]', 'cleanQuery', 'result', ret)

return ret;
return ret;
}

module.exports.wrapRegex = function( reg ){
reg || (reg = '');
if( reg instanceof RegExp ){
return reg.source.replace(/\^|\(\.\*\)/g, '');
}
// Todo: Non regexp case
return '';
reg || (reg = '');
if( reg instanceof RegExp ){
return reg.source.replace(/\^|\(\.\*\)/g, '');
}
// Todo: Non regexp case
return '';
}
170 changes: 81 additions & 89 deletions apps/index.js
Original file line number Diff line number Diff line change
@@ -1,115 +1,107 @@
/*
depends on lodash, electron-router, systemApps, nativeApps
globals upath, db, async
globalizes app{ utils, URL_REGEX }
depends on lodash, electron-router, systemApps, nativeApps
globals upath, db, async
globalizes app{ utils, URL_REGEX }
*/

'use strict';

let _ = require('lodash')
let _systemApps = require( global.upath.join( __dirname, 'system', 'index' ) )
let _nativeApps = require( global.upath.join( __dirname, 'native', 'index' ) )
const { uniqBy } = require('lodash')
const _systemApps = require( global.upath.join( __dirname, 'system', 'index' ) )
const _nativeApps = require( global.upath.join( __dirname, 'native', 'index' ) )
const BrowserHistory = require( global.upath.join( __dirname, 'system', 'BrowserHistory' ) )
// Apps namespace
global.app = {
utils: require('./appUtils'),
URL_REGEX: new RegExp(/^(?:http(?:s)?\:\/\/(?:www\.)?)([^ ]+)$/gi)
utils: require('./appUtils'),
URL_REGEX: new RegExp(/^(?:http(?:s)?\:\/\/(?:www\.)?)([^ ]+)$/gi)
}

let _searchBrowserHistory = function( query, callback ){

global.db.query('browsers', query, ( err, results ) => {

if( err ){
return callback( err );
}
callback( null, _.uniqBy(results, ( a ) => a.title ).map(( result ) => {
// Deep copy
let aux = _systemApps.getInternalApp('browserHistory')
// Come in the form:
// url: ...
// title: ...
// browser: ...
aux.name = result.title
aux.text = result.url
return aux
}))

})
function _searchBrowserHistory( query, callback ){

global.db.query('browsers', query, ( err, results ) => {

}

let _lateAppend = function( err, results ){
if( err ){
return callback( err );
}

if( !err && results && results.length){
// Send data back to UI
//Logger.log('[APP LOADER]', 'Late Append', results.length, results);
router.send('UI::AppendToView', results);
}else{
Logger.log('[APP LOADER]', 'Late Append failed', err);
}
const ret = uniqBy(results, ( a ) => a.title )
.map(( result ) => new BrowserHistory({
name: result.title, text: result.url
}).getWrapper())

callback( null, ret )
})
}

let _registerEvents = function( callback ){

router.on('launchApp', ( data ) => {
//Logger.log('[APP LOADER]', data.app);
// TODO => Type check should not be against undefined but a type
if( '_native_' === data.app.type ){
Logger.log('[APP LOADER] for spawner', data.app, data.query);
global.app.utils.spawn( data.app.exec );
}else{
_systemApps.launchApp( data.app.exec, data.app, data.query );
}
});

router.get('query', ( req, res ) => {
Logger.log('[APP LOADER]', 'query', req.params[0])
let query = req.params[0];
let matches = [];

if( query !== '' && query !== ' '){

// Internal apps: Preferences, Quit, Url
matches = matches.concat( _systemApps.searchApp( query, _lateAppend ) );
// Native apps: User installed applications
matches = matches.concat( _nativeApps.searchApp( query, _lateAppend ) );
// Broswser History files
_searchBrowserHistory( query, _lateAppend)

}
// If nothing was found, just insert netSearch option
if( matches.length < 2 ){
matches.push( _systemApps.getInternalApp('netSearch') );
}
Logger.log('[APP LOADER]', 'Sending back', matches.length)
res.json( null, matches );

matches = null;

})

callback();
function _lateAppend( err, results ){

if( !err && results && results.length){
// Send data back to UI
//Logger.log('[APP LOADER]', 'Late Append', results.length, results);
router.send('UI::AppendToView', results);
}else{
Logger.log('[APP LOADER]', 'Late Append failed', err);
}
}

function _registerEvents( callback ){

router.on('launchApp', ( data ) => {
//Logger.log('[APP LOADER]', data.app);
// TODO => Type check should not be against undefined but a type
if( '_native_' === data.app.type ){
Logger.log('[APP LOADER] for spawner', data.app, data.query);
global.app.utils.spawn( data.app.exec );
}else{
_systemApps.launchApp( data.app.exec, data.app, data.query );
}
});

router.get('query', ( req, res ) => {
Logger.log('[APP LOADER]', 'query', req.params[0])
let query = req.params[0];
let matches = [];

if( query !== '' && query !== ' '){

// Internal apps: Preferences, Quit, Url
matches = matches.concat( _systemApps.searchApp( query, _lateAppend ) );
// Native apps: User installed applications
matches = matches.concat( _nativeApps.searchApp( query, _lateAppend ) );
// Broswser History files
_searchBrowserHistory( query, _lateAppend)

}
// If nothing was found, just insert netSearch option
if( matches.length < 2 ){
matches.push( _systemApps.getInternalApp('netSearch') );
}
Logger.log('[APP LOADER]', 'Sending back', matches.length)
res.json( null, matches );

matches = null;

})

callback();
}

let _start = function( callback ){
function _start( callback ){

global.async.parallel([

_systemApps.start,
_nativeApps.start,
_registerEvents
global.async.parallel([

], ( err ) => {
_systemApps.start,
_nativeApps.start,
_registerEvents

Logger.log('[APP LOADER] Done starting modules', (err?err:''));
callback( err );
], ( err ) => {

});
Logger.log('[APP LOADER] Done starting modules', (err?err:''));
callback( err );

});
}

module.exports = {
start: _start
start: _start
}
Loading

0 comments on commit b7ffbda

Please sign in to comment.