Skip to content

Commit

Permalink
Start adding batch ability to Electron version of the app.
Browse files Browse the repository at this point in the history
Untested, and doesnt print results to terminal.
  • Loading branch information
wcjohns committed Oct 13, 2024
1 parent 95272d4 commit 180c567
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
45 changes: 45 additions & 0 deletions target/electron/InterSpecAddOn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@

#include "target/electron/ElectronUtils.h"

#if( USE_BATCH_TOOLS )
#include "InterSpec/BatchCommandLine.h"
#endif

//A good, simple, N-API tutorial is at:
// https://blog.atulr.com/node-addon-guide/

Expand Down Expand Up @@ -517,6 +521,43 @@ namespace InterSpecAddOn
return Napi::Boolean::New( env, success );
}//void sendMessageToRenderer( const Napi::CallbackInfo &info )

#if( USE_BATCH_TOOLS )
Napi::Number runBatchAnalysis( const Napi::CallbackInfo &info )
{
Napi::Env env = info.Env();


if( info.Length() != 1 || !info[0].IsArray() )
{
Napi::TypeError::New(env, "runBatchAnalysis: Expected one array of strings").ThrowAsJavaScriptException();
return Napi::Number();
}

Napi::Array jsArray = info[0].As<Napi::Array>();
const uint32_t numargs = jsArray.Length();
std::vector<std::string> str_args( numargs );
std::vector<char *> str_args_ptrs( numargs, nullptr );
for( uint32_t i = 0; i < numargs; i++ )
{
Napi::Value element = jsArray.Get(i);

// Check if the element is a string
if (!element.IsString()) {
Napi::TypeError::New(env, "Array elements must be strings").ThrowAsJavaScriptException();
return Napi::Number();
}

str_args[i] = element.ToString();
if( str_args[i].empty() )
str_args[i] = " ";
str_args_ptrs[i] = &(str_args[i][0]);
}

const int rcode = BatchCommandLine::run_batch_command( static_cast<int>(numargs), &(str_args_ptrs[0]) );

return Napi::Number::New( env, rcode );
}//Napi::Number runBatchAnalysis( const Napi::CallbackInfo &info )
#endif

bool browse_for_directory( const std::string &session_token,
const std::string &window_title,
Expand Down Expand Up @@ -601,6 +642,10 @@ Napi::Object InitAll(Napi::Env env, Napi::Object exports) {

exports.Set( "sendMessageToRenderer", Napi::Function::New(env, InterSpecAddOn::sendMessageToRenderer));

#if( USE_BATCH_TOOLS )
exports.Set( "runBatchAnalysis", Napi::Function::New(env, InterSpecAddOn::runBatchAnalysis));
#endif

return exports;
}

Expand Down
14 changes: 14 additions & 0 deletions target/electron/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ let interspec_url = null;

global.__basedir = __dirname;

// Check if we only want to run
for( let path_string of process.argv ) {
if( path_string.startsWith("--batch") || path_string.startsWith("/batch") ) {
console.log( "Will run batch");

//TODO: redirect stderr/stdout to console.log
const rdcode = interspec.runBatchAnalysis( process.argv );

console.log( "Batch analysis returned code " + rcode );

app.quit();
return;
}
}

// Keep a global reference of the window objects, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
Expand Down

0 comments on commit 180c567

Please sign in to comment.