-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
3,297 additions
and
3,469 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.