Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sandialabs/InterSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
wcjohns committed Oct 16, 2024
2 parents b8a4a10 + f3eeac8 commit 0aab75d
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 19 deletions.
1 change: 1 addition & 0 deletions target/electron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set( BUILD_AS_LOCAL_SERVER OFF CACHE BOOL "N/A" )
set( USE_OSX_NATIVE_MENU OFF CACHE BOOL "N/A" )
set( USE_SPECRUM_FILE_QUERY_WIDGET ON CACHE BOOL "Enable Spectrum File Query Widget" )
set( USE_REMOTE_RID ON CACHE BOOL "Enables using remote RID tool" )
set( USE_BATCH_TOOLS ON CACHE BOOL "Enables using batch tool" )

IF(WIN32)
add_definitions(-DBOOST_ALL_NO_LIB) #Prevent boost auto-linking, which seems to call in vc141 boost libs instead of vc142
Expand Down
63 changes: 60 additions & 3 deletions target/electron/InterSpecAddOn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
#include "target/electron/ElectronUtils.h"

#if( USE_BATCH_TOOLS )
#include "SpecUtils/StringAlgo.h"
#include "SpecUtils/Filesystem.h"

#include "InterSpec/InterSpec.h"
#include "InterSpec/BatchCommandLine.h"
#endif

Expand Down Expand Up @@ -542,16 +546,69 @@ namespace InterSpecAddOn
Napi::Value element = jsArray.Get(i);

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

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


auto checkarg = [&str_args,i,numargs]( const std::string &teststr ) -> std::string {

if( !SpecUtils::istarts_with(str_args[i], teststr) )
return "";
std::string docroot;
if( (str_args[i].length() > (teststr.size()+1)) && (str_args[i][teststr.size()] == '=') )
docroot = str_args[i].substr(teststr.size() + 1);
else if( (i+1) < numargs )
docroot = str_args[i+1];
else
return "";

if( docroot.length() && ((docroot.front()=='\"') || (docroot.front()=='\'')) )
docroot = docroot.substr(1);
if( docroot.length() && ((docroot.back()=='\"') || (docroot.back()=='\'')) )
docroot = docroot.substr(0, docroot.size() - 1);
return docroot;
};//checkarg lambda

// TODO: this setting directories should either be brought out to node.js stuff, or integrated into BatchCommandLine::run_batch_command(...)
const std::string docroot = checkarg( "--docroot" );
const std::string userdatadir = checkarg( "--userdatadir" );

if( !docroot.empty() )
{
const std::string datadir = SpecUtils::append_path( docroot, "data" );

try
{
InterSpec::setStaticDataDirectory( datadir );
}catch( std::exception &e )
{
std::cerr << "Failed to set static data directory: " << e.what() << std::endl;
Napi::Number::New( env, -7 );
}
}//if( !docroot.empty() )

if( !userdatadir.empty() )
{
try
{
InterSpec::setWritableDataDirectory( userdatadir );
}catch( std::exception &e )
{
std::cerr << "Warning: Failed to set user data directory: " << e.what() << std::endl
<< "Use the '--userdatadir' option to set this to the same one the InterSpec GUI app"
<< " uses, if you would like to share detectors, or other files." << std::endl;
//return -8;
}
}//if( !userdatadir.empty() )
}//for( uint32_t i = 0; i < numargs; i++ )

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

Expand Down
1 change: 1 addition & 0 deletions target/electron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ npm install uglify-js -g
npm install uglifycss -g
npm install cmake-js -g
npm install --save-dev node-addon-api --arch=x64
npm install node-api-headers
npm install electron --arch=x64
npm install electron-packager

Expand Down
39 changes: 24 additions & 15 deletions target/electron/app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,6 @@ 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 Expand Up @@ -999,7 +985,30 @@ function browseForDirectory( token, title, msg ){
return (dirs.length<1) ? '' : dirs[0];
};//function browseForDirectory

// 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");

let has_docroot = false, has_userdata = false;
for( let str of process.argv ) {
has_docroot = (has_docroot || str.startsWith('--docroot'));
has_userdata = (has_userdata || str.startsWith('--userdatadir'));
}

if( !has_docroot )
process.argv.push( "--docroot=\'" + path.dirname(require.main.filename) + "'");
if( !has_userdata )
process.argv.push( "--userdatadir=\'" + userdata + "'")

const rcode = interspec.runBatchAnalysis( process.argv );

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

app.quit();
return;
}
}


// This method will be called when Electron has finished
Expand All @@ -1008,7 +1017,7 @@ function browseForDirectory( token, title, msg ){
app.on('ready', function(){
const process_name = require.main.filename;
//actually process.cwd()==path.dirname(require.main.filename) when running using node from command line

//It looks like we dont need to change the CWD anymore (I think everywhere in
// InterSpec no longer assumes a specific CWD), but lets do it anyway.
process.chdir( path.dirname(require.main.filename) );
Expand Down
2 changes: 1 addition & 1 deletion target/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"license": "LGPL-2.1-only",
"dependencies": {
"cmake-js": "^6.1.0",
"node-api-headers": "^1.1.0"
"node-api-headers": "^1.3.0"
},
"devDependencies": {
"electron": "^21.4.4",
Expand Down

0 comments on commit 0aab75d

Please sign in to comment.