Skip to content

Commit f84f2a1

Browse files
committed
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.
1 parent e448aff commit f84f2a1

File tree

6 files changed

+33
-44
lines changed

6 files changed

+33
-44
lines changed

CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,6 @@ if(ANDROID)
241241
set(Boost_FILESYSTEM_LIBRARY_RELEASE
242242
${BOOST_LIB_START}filesystem${BOOST_LIB_END}
243243
)
244-
set(Boost_IOSTREAMS_LIBRARY_RELEASE
245-
${BOOST_LIB_START}iostreams${BOOST_LIB_END}
246-
)
247244
set(Boost_PROGRAM_OPTIONS_LIBRARY_RELEASE
248245
${BOOST_LIB_START}program_options${BOOST_LIB_END}
249246
)
@@ -835,6 +832,7 @@ elseif(BUILD_AS_OSX_APP)
835832
CMAKE_CACHE_ARGS -DWt_INCLUDE_DIR:PATH=${Wt_INCLUDE_DIR}
836833
-DBOOST_ROOT:PATH=${Boost_INCLUDE_DIR}/..
837834
-DBOOST_INCLUDEDIR:PATH=${Boost_INCLUDE_DIR}
835+
-DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}
838836
-DCMAKE_BUILD_TYPE:STRING=RELEASE
839837
-DSpecUtils_ENABLE_D3_CHART:BOOL=OFF
840838
INSTALL_COMMAND ""
@@ -1318,17 +1316,6 @@ if(Wt_MYSQL_LIBRARY)
13181316
find_file( HAS_WT_DBO_MYSQL "MySQL" PATHS "${Wt_INCLUDE_DIR}/Wt/Dbo/backend/" NO_DEFAULT_PATH )
13191317
endif(Wt_MYSQL_LIBRARY)
13201318

1321-
INCLUDE( CheckIncludeFiles )
1322-
1323-
if(ZLIB_FOUND AND Boost_IOSTREAMS_FOUND)
1324-
#CHECK_INCLUDE_FILES( "zlib.h" HAS_ZLIB_SUPPORT )
1325-
target_link_libraries(
1326-
InterSpecLib
1327-
PUBLIC
1328-
${ZLIB_LIBRARIES}
1329-
Boost::iostreams
1330-
)
1331-
endif(ZLIB_FOUND AND Boost_IOSTREAMS_FOUND)
13321319

13331320
if(SUPPORT_ZIPPED_SPECTRUM_FILES)
13341321
#CMake seems to fail to find zlib on ios/android (even using find_package(ZLIB REQUIRED)), but we know it will be in

InterSpec_resources/SpecMeasManager.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,5 @@ float: right;
100100
.SelectDrfFromMult .Credits
101101
{
102102
margin-top: 5px;
103+
max-width: 50vw;
103104
}

src/InterSpecApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ void InterSpecApp::prepareForEndOfSession()
12391239

12401240
void InterSpecApp::clearSession()
12411241
{
1242-
#if( USING_ELECTRON_NATIVE_MENU )
1242+
#if( BUILD_AS_ELECTRON_APP )
12431243
// As a workaround setup a function ElectronUtils::requestNewCleanSession() that
12441244
// sends websocket message to node land to clear menus, and load a new session
12451245
// but with argument "restore=no"

src/SpecFileQueryWidget.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ void SpecFileQueryWidget::basePathChanged()
20352035
{
20362036
m_numberFiles->setText( "Updating # of files" );
20372037
const size_t maxsize_mb = static_cast<size_t>(maxsize*1024*1024);
2038-
server->ioService().post( boost::bind( &SpecFileQueryWidget::updateNumberFiles,
2038+
server->ioService().boost::asio::io_service::post( boost::bind( &SpecFileQueryWidget::updateNumberFiles,
20392039
basepath, recursive, filter, maxsize_mb,
20402040
this, wApp->sessionId(), m_widgetDeleted,
20412041
database ) );
@@ -2349,7 +2349,7 @@ void SpecFileQueryWidget::searchRequestedCallback( const std::string &queryJson
23492349
database = std::make_shared<SpecFileQueryDbCache>( false, basepath, m_eventXmlFilters );
23502350

23512351
m_stopUpdate->store( false );
2352-
WServer::instance()->ioService().post(
2352+
WServer::instance()->ioService().boost::asio::io_service::post(
23532353
boost::bind( &SpecFileQueryWidget::doSearch, this, basepath, options,
23542354
maxsize, test, wApp->sessionId(), database, m_stopUpdate,
23552355
m_widgetDeleted ) );

target/electron/ElectronUtils.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,30 @@ using namespace std;
5454
namespace ElectronUtils
5555
{
5656

57-
58-
#if( USING_ELECTRON_NATIVE_MENU )
5957
bool requestNewCleanSession()
6058
{
6159
auto app = dynamic_cast<InterSpecApp *>(wApp);
6260

6361
const string oldexternalid = app ? app->externalToken() : string();
6462
if( !oldexternalid.empty() )
6563
{
64+
//Have electron reload the page.
65+
ElectronUtils::send_nodejs_message("NewCleanSession", "");
66+
67+
#if( USING_ELECTRON_NATIVE_MENU )
6668
//should check ns_externalid==oldexternalid
6769
string js;
68-
//Speed up loading by defering calls to Menu.setApplicationMenu() until app
70+
//Speed up loading by deferring calls to Menu.setApplicationMenu() until app
6971
// is fully reloaded.
7072
js += "$(window).data('HaveTriggeredMenuUpdate',null);";
7173

72-
//Have electron reload the page.
73-
ElectronUtils::send_nodejs_message("NewCleanSession", "");
74-
7574
//Just in case the page reload doesnt go through, make sure menus will get updated eventually
7675
// (this shouldnt be necassary, right?)
7776
js += "setTimeout(function(){$(window).data('HaveTriggeredMenuUpdate',true);},5000);";
7877

7978
wApp->doJavaScript(js);
79+
#endif
80+
8081
return true;
8182
}else
8283
{
@@ -85,7 +86,7 @@ bool requestNewCleanSession()
8586

8687
return false;
8788
}//void requestNewCleanSession()
88-
#endif //USING_ELECTRON_NATIVE_MENU
89+
8990

9091
bool notifyNodeJsOfNewSessionLoad()
9192
{
@@ -105,17 +106,24 @@ bool notifyNodeJsOfNewSessionLoad()
105106
}//bool notifyNodeJsOfNewSessionLoad( const std::string sessionid )
106107

107108

108-
bool send_nodejs_message( const std::string &msg_name, const std::string &msg_data )
109+
void send_nodejs_message( const std::string msg_name, const std::string msg_data )
109110
{
110111
auto app = dynamic_cast<InterSpecApp *>(wApp);
111112
if( !app )
112113
{
113114
cerr << "Error: send_nodejs_message: wApp is null!!!" << endl;
114-
return false;
115+
return;
115116
}
116117

117118
const string session_token = app->externalToken();
118-
return InterSpecAddOn::send_nodejs_message( session_token, msg_name, msg_data );
119+
120+
Wt::WServer *server = Wt::WServer::instance();
121+
assert( server );
122+
123+
Wt::WIOService &io = server->ioService();
124+
io.boost::asio::io_service::post( [=](){
125+
InterSpecAddOn::send_nodejs_message( session_token, msg_name, msg_data );
126+
} );
119127
}//void send_nodejs_message(...)
120128

121129

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

232240
Wt::WIOService &io = server->ioService();
233-
io.post( worker );
241+
io.boost::asio::io_service::post( worker );
234242

235243
return true;
236244
}//bool browse_for_directory(...)
237245

238246
}//namespace ElectronUtils
239247

240248

241-
#if( BUILD_AS_ELECTRON_APP )
242249

243250
int interspec_start_server( const char *process_name, const char *userdatadir,
244251
const char *basedir, const char *xml_config_path )
@@ -409,6 +416,3 @@ void interspec_kill_server()
409416
{
410417
InterSpecServer::killServer();
411418
}//void interspec_kill_server()
412-
413-
414-
#endif //#if( BUILD_AS_ELECTRON_APP )

target/electron/ElectronUtils.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,35 +100,32 @@ extern "C"
100100

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

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

127-
/**
128-
129-
Returns true if it thinks message was sent.
125+
/** Sends main.js a message via InterSpecAddOn::send_nodejs_message(...) in another
126+
asio thread.
130127
*/
131-
bool send_nodejs_message( const std::string &msg_name, const std::string &msg_data );
128+
void send_nodejs_message( const std::string msg_name, const std::string msg_data );
132129

133130

134131
/**

0 commit comments

Comments
 (0)