From f84f2a1591bf0b8575751217966cc6f5156019e5 Mon Sep 17 00:00:00 2001 From: William Johnson Date: Fri, 1 Apr 2022 20:45:13 -0700 Subject: [PATCH] Fix issues clearing session and doing file query in Electron build (hopefully). 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. --- CMakeLists.txt | 15 +---------- InterSpec_resources/SpecMeasManager.css | 1 + src/InterSpecApp.cpp | 2 +- src/SpecFileQueryWidget.cpp | 4 +-- target/electron/ElectronUtils.cpp | 34 ++++++++++++++----------- target/electron/ElectronUtils.h | 21 +++++++-------- 6 files changed, 33 insertions(+), 44 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a81d4116..ca65d4aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} ) @@ -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 "" @@ -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 diff --git a/InterSpec_resources/SpecMeasManager.css b/InterSpec_resources/SpecMeasManager.css index bbf893b8..8361f177 100644 --- a/InterSpec_resources/SpecMeasManager.css +++ b/InterSpec_resources/SpecMeasManager.css @@ -100,4 +100,5 @@ float: right; .SelectDrfFromMult .Credits { margin-top: 5px; + max-width: 50vw; } diff --git a/src/InterSpecApp.cpp b/src/InterSpecApp.cpp index 6690d504..64922ed0 100644 --- a/src/InterSpecApp.cpp +++ b/src/InterSpecApp.cpp @@ -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" diff --git a/src/SpecFileQueryWidget.cpp b/src/SpecFileQueryWidget.cpp index 9b36b840..e2a9e782 100644 --- a/src/SpecFileQueryWidget.cpp +++ b/src/SpecFileQueryWidget.cpp @@ -2035,7 +2035,7 @@ void SpecFileQueryWidget::basePathChanged() { m_numberFiles->setText( "Updating # of files" ); const size_t maxsize_mb = static_cast(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 ) ); @@ -2349,7 +2349,7 @@ void SpecFileQueryWidget::searchRequestedCallback( const std::string &queryJson database = std::make_shared( 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 ) ); diff --git a/target/electron/ElectronUtils.cpp b/target/electron/ElectronUtils.cpp index d0bd9b7e..7b1ffc0e 100644 --- a/target/electron/ElectronUtils.cpp +++ b/target/electron/ElectronUtils.cpp @@ -54,8 +54,6 @@ using namespace std; namespace ElectronUtils { - -#if( USING_ELECTRON_NATIVE_MENU ) bool requestNewCleanSession() { auto app = dynamic_cast(wApp); @@ -63,20 +61,23 @@ bool requestNewCleanSession() 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 { @@ -85,7 +86,7 @@ bool requestNewCleanSession() return false; }//void requestNewCleanSession() -#endif //USING_ELECTRON_NATIVE_MENU + bool notifyNodeJsOfNewSessionLoad() { @@ -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(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(...) @@ -230,7 +238,7 @@ 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(...) @@ -238,7 +246,6 @@ bool browse_for_directory( const std::string &window_title, }//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 ) @@ -409,6 +416,3 @@ void interspec_kill_server() { InterSpecServer::killServer(); }//void interspec_kill_server() - - -#endif //#if( BUILD_AS_ELECTRON_APP ) diff --git a/target/electron/ElectronUtils.h b/target/electron/ElectronUtils.h index ff8a293d..7d68fff1 100644 --- a/target/electron/ElectronUtils.h +++ b/target/electron/ElectronUtils.h @@ -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 ); /**