Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
geblanco committed Apr 8, 2020
2 parents b7ffbda + 66275f3 commit 0b08b7f
Show file tree
Hide file tree
Showing 78 changed files with 3,214 additions and 10,271 deletions.
3 changes: 2 additions & 1 deletion .gitignore
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ tests

# Distro files
*.desktop
PKGBUILD*
PKGBUILD*
dist
Empty file modified LICENSE
100755 → 100644
Empty file.
Empty file modified Model.md
100755 → 100644
Empty file.
10 changes: 2 additions & 8 deletions README.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,10 @@ Get in the project dir
cd mutant
```

Source the necessary variables (electron dependant)
Run npm installation under electron runtime

```bash
source install/envVars.sh
```

Install node modules

```bash
npm i
npm run install-for-electron
```

Launch app
Expand Down
24 changes: 14 additions & 10 deletions apps/appUtils.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@

'use strict'

var spawn = require('child_process').spawn;
const { spawn, exec } = require('child_process');

// 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, {
var child = null
var childOpts = {
detached: true,
stdio: [ 'ignore', 'ignore', 'ignore' ],
cwd: cwd?cwd:process.cwd()
});
child.unref();
}
if (opts !== undefined && !(opts instanceof Array) ){
opts = [opts]
}
Logger.log('[UTILS] Spawning', cmd, 'with options', opts)
if( opts === undefined ){
child = exec(cmd, childOpts)
}else{
child = spawn(cmd, opts, childOpts)
}
child.unref()
}

module.exports.strSearch = function( str, query ){
Expand Down
59 changes: 35 additions & 24 deletions apps/index.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
globalizes app{ utils, URL_REGEX }
*/

'use strict';
'use strict'

const { uniqBy } = require('lodash')
const _systemApps = require( global.upath.join( __dirname, 'system', 'index' ) )
Expand All @@ -18,10 +18,10 @@ global.app = {

function _searchBrowserHistory( query, callback ){

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

if( err ){
return callback( err );
return callback( err )
}

const ret = uniqBy(results, ( a ) => a.title )
Expand All @@ -37,53 +37,64 @@ 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);
Logger.log('[APP LOADER]', 'Late Append', results.length)
router.send('UI::AppendToView', results)
}else{
Logger.log('[APP LOADER]', 'Late Append failed', err);
Logger.log('[APP LOADER]', 'Late Append failed', err)
}
}

function _updateScore(app){
global.db.getMainDB().findOne({ name: app.name }, (err, doc) => {
if( err ) return
if( doc === null ) return
doc.score += 1
doc.save()
let plainDoc = JSON.parse(JSON.stringify(doc))
Logger.log(`[APP LOADER] New app score (${plainDoc.name} = ${plainDoc.score})`)
})
}

function _registerEvents( callback ){

router.on('launchApp', ( data ) => {
//Logger.log('[APP LOADER]', data.app);
_updateScore(data.app)
// 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 );
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 );
_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 = [];
let query = req.params[0]
let matches = []

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

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

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

matches = null;
res.json( null, matches )

matches = null
})

callback();
callback()
}

function _start( callback ){
Expand All @@ -96,10 +107,10 @@ function _start( callback ){

], ( err ) => {

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

});
})
}

module.exports = {
Expand Down
Loading

0 comments on commit 0b08b7f

Please sign in to comment.