Skip to content

Commit

Permalink
Fix issues clearing session and doing file query in Electron build (h…
Browse files Browse the repository at this point in the history
…opefully).

The SpecFIleQuery tool needed to post to use boost::asio::io_service, instead of WIOService::post (which uses a global strand for processing).
And the loading of a clean new session needed to have main.js generate a new token and trigger the refresh.
  • Loading branch information
wcjohns committed Apr 2, 2022
1 parent e448aff commit f84f2a1
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 44 deletions.
15 changes: 1 addition & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ if(ANDROID)
set(Boost_FILESYSTEM_LIBRARY_RELEASE
${BOOST_LIB_START}filesystem${BOOST_LIB_END}
)
set(Boost_IOSTREAMS_LIBRARY_RELEASE
${BOOST_LIB_START}iostreams${BOOST_LIB_END}
)
set(Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE
${BOOST_LIB_START}program_options${BOOST_LIB_END}
)
Expand Down Expand Up @@ -835,6 +832,7 @@ elseif(BUILD_AS_OSX_APP)
CMAKE_CACHE_ARGS -DWt_INCLUDE_DIR:PATH=${Wt_INCLUDE_DIR}
-DBOOST_ROOT:PATH=${Boost_INCLUDE_DIR}/..
-DBOOST_INCLUDEDIR:PATH=${Boost_INCLUDE_DIR}
-DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
-DCMAKE_BUILD_TYPE:STRING=RELEASE
-DSpecUtils_ENABLE_D3_CHART:BOOL=OFF
INSTALL_COMMAND ""
Expand Down Expand Up @@ -1318,17 +1316,6 @@ if(Wt_MYSQL_LIBRARY)
find_file( HAS_WT_DBO_MYSQL "MySQL" PATHS "${Wt_INCLUDE_DIR}/Wt/Dbo/backend/" NO_DEFAULT_PATH )
endif(Wt_MYSQL_LIBRARY)

INCLUDE( CheckIncludeFiles )

if(ZLIB_FOUND AND Boost_IOSTREAMS_FOUND)
#CHECK_INCLUDE_FILES( "zlib.h" HAS_ZLIB_SUPPORT )
target_link_libraries(
InterSpecLib
PUBLIC
${ZLIB_LIBRARIES}
Boost::iostreams
)
endif(ZLIB_FOUND AND Boost_IOSTREAMS_FOUND)

if(SUPPORT_ZIPPED_SPECTRUM_FILES)
#CMake seems to fail to find zlib on ios/android (even using find_package(ZLIB REQUIRED)), but we know it will be in
Expand Down
1 change: 1 addition & 0 deletions InterSpec_resources/SpecMeasManager.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,5 @@ float: right;
.SelectDrfFromMult .Credits
{
margin-top: 5px;
max-width: 50vw;
}
2 changes: 1 addition & 1 deletion src/InterSpecApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ void InterSpecApp::prepareForEndOfSession()

void InterSpecApp::clearSession()
{
#if( USING_ELECTRON_NATIVE_MENU )
#if( BUILD_AS_ELECTRON_APP )
// As a workaround setup a function ElectronUtils::requestNewCleanSession() that
// sends websocket message to node land to clear menus, and load a new session
// but with argument "restore=no"
Expand Down
4 changes: 2 additions & 2 deletions src/SpecFileQueryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2035,7 +2035,7 @@ void SpecFileQueryWidget::basePathChanged()
{
m_numberFiles->setText( "Updating # of files" );
const size_t maxsize_mb = static_cast<size_t>(maxsize*1024*1024);
server->ioService().post( boost::bind( &SpecFileQueryWidget::updateNumberFiles,
server->ioService().boost::asio::io_service::post( boost::bind( &SpecFileQueryWidget::updateNumberFiles,
basepath, recursive, filter, maxsize_mb,
this, wApp->sessionId(), m_widgetDeleted,
database ) );
Expand Down Expand Up @@ -2349,7 +2349,7 @@ void SpecFileQueryWidget::searchRequestedCallback( const std::string &queryJson
database = std::make_shared<SpecFileQueryDbCache>( false, basepath, m_eventXmlFilters );

m_stopUpdate->store( false );
WServer::instance()->ioService().post(
WServer::instance()->ioService().boost::asio::io_service::post(
boost::bind( &SpecFileQueryWidget::doSearch, this, basepath, options,
maxsize, test, wApp->sessionId(), database, m_stopUpdate,
m_widgetDeleted ) );
Expand Down
34 changes: 19 additions & 15 deletions target/electron/ElectronUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,30 @@ using namespace std;
namespace ElectronUtils
{


#if( USING_ELECTRON_NATIVE_MENU )
bool requestNewCleanSession()
{
auto app = dynamic_cast<InterSpecApp *>(wApp);

const string oldexternalid = app ? app->externalToken() : string();
if( !oldexternalid.empty() )
{
//Have electron reload the page.
ElectronUtils::send_nodejs_message("NewCleanSession", "");

#if( USING_ELECTRON_NATIVE_MENU )
//should check ns_externalid==oldexternalid
string js;
//Speed up loading by defering calls to Menu.setApplicationMenu() until app
//Speed up loading by deferring calls to Menu.setApplicationMenu() until app
// is fully reloaded.
js += "$(window).data('HaveTriggeredMenuUpdate',null);";

//Have electron reload the page.
ElectronUtils::send_nodejs_message("NewCleanSession", "");

//Just in case the page reload doesnt go through, make sure menus will get updated eventually
// (this shouldnt be necassary, right?)
js += "setTimeout(function(){$(window).data('HaveTriggeredMenuUpdate',true);},5000);";

wApp->doJavaScript(js);
#endif

return true;
}else
{
Expand All @@ -85,7 +86,7 @@ bool requestNewCleanSession()

return false;
}//void requestNewCleanSession()
#endif //USING_ELECTRON_NATIVE_MENU


bool notifyNodeJsOfNewSessionLoad()
{
Expand All @@ -105,17 +106,24 @@ bool notifyNodeJsOfNewSessionLoad()
}//bool notifyNodeJsOfNewSessionLoad( const std::string sessionid )


bool send_nodejs_message( const std::string &msg_name, const std::string &msg_data )
void send_nodejs_message( const std::string msg_name, const std::string msg_data )
{
auto app = dynamic_cast<InterSpecApp *>(wApp);
if( !app )
{
cerr << "Error: send_nodejs_message: wApp is null!!!" << endl;
return false;
return;
}

const string session_token = app->externalToken();
return InterSpecAddOn::send_nodejs_message( session_token, msg_name, msg_data );

Wt::WServer *server = Wt::WServer::instance();
assert( server );

Wt::WIOService &io = server->ioService();
io.boost::asio::io_service::post( [=](){
InterSpecAddOn::send_nodejs_message( session_token, msg_name, msg_data );
} );
}//void send_nodejs_message(...)


Expand Down Expand Up @@ -230,15 +238,14 @@ bool browse_for_directory( const std::string &window_title,
assert( server );

Wt::WIOService &io = server->ioService();
io.post( worker );
io.boost::asio::io_service::post( worker );

return true;
}//bool browse_for_directory(...)

}//namespace ElectronUtils


#if( BUILD_AS_ELECTRON_APP )

int interspec_start_server( const char *process_name, const char *userdatadir,
const char *basedir, const char *xml_config_path )
Expand Down Expand Up @@ -409,6 +416,3 @@ void interspec_kill_server()
{
InterSpecServer::killServer();
}//void interspec_kill_server()


#endif //#if( BUILD_AS_ELECTRON_APP )
21 changes: 9 additions & 12 deletions target/electron/ElectronUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,32 @@ extern "C"

namespace ElectronUtils
{
#if( USING_ELECTRON_NATIVE_MENU )
/** Requests main.js to load a new clean session (i.e., don restore any state)
This is a workaround to when the user requests a new session, the normal
mechanism in c++ creates duplicate Electron menu items...
/** Tells main.js to load a new clean session (i.e., don restore any state).
This gives main.js a chance to clear menus (if using native Electron menus),
and generate a new session token to use with the new session.
Must be called from within a WApplication thread (e.g., wApp is valid).
@returns whether message was succesfully sent or not.
@returns whether message was successfully sent or not.
*/
bool requestNewCleanSession();
#endif

/** Notify parent application (main.js, or objective-c) that the session has
loaded.
Must be called from within a WApplication thread (e.g., wApp is valid).
@returns whether message was succesfully sent or not.
@returns whether message was successfully sent or not.
Note: main.js will wait till recieveing this notification before asking the
Note: main.js will wait till receiving this notification before asking the
session to open any files the OS requested.
*/
bool notifyNodeJsOfNewSessionLoad();

/**
Returns true if it thinks message was sent.
/** Sends main.js a message via InterSpecAddOn::send_nodejs_message(...) in another
asio thread.
*/
bool send_nodejs_message( const std::string &msg_name, const std::string &msg_data );
void send_nodejs_message( const std::string msg_name, const std::string msg_data );


/**
Expand Down

0 comments on commit f84f2a1

Please sign in to comment.