Skip to content

Commit b8d4a11

Browse files
committed
Add ArcGis key option to InterSpec_app_settings.json.
1 parent 1d12480 commit b8d4a11

File tree

5 files changed

+63
-14
lines changed

5 files changed

+63
-14
lines changed

InterSpec/InterSpecServer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ namespace InterSpecServer
284284
/** If true, will open the WebView inspector console on launch. */
285285
bool m_open_dev_tools;
286286

287+
#if( USE_LEAFLET_MAP )
288+
/** The key to use to access the https://arcgis.com server to get map tiles from.
289+
This value overides the default one built into InterSpec, if specified.
290+
*/
291+
std::string m_arcgis_key;
292+
#endif
293+
287294
/** Returns application config, as determined from defaults and then
288295
InterSpec_app_settings.json files.
289296

InterSpec/LeafletRadMap.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ class LeafletRadMap : public Wt::WContainerWidget
9696

9797
#if( BUILD_AS_ELECTRON_APP || IOS || ANDROID || BUILD_AS_OSX_APP || BUILD_AS_LOCAL_SERVER || BUILD_AS_WX_WIDGETS_APP )
9898
/** Look in the users data directory for a file named "arcgis\_key.txt", whose contents is the arcgis access key.
99+
If that file isnt present, will look in `InterSpec_app_settings.json` file for a "ArcGisKey" value to use.
99100
100101
Newlines, whitespaces, and some other invalid characters are discarded.
101102
102-
If the file does not exist, an empty string is returned.
103-
If the file exists, but after removing invalid characters, it is less than 6 characters, then "empty" is returned.
104-
If the file exists, and has a somewhat valid seeming contents, will return those.
103+
If the file(s) do not exist, an empty string is returned.
104+
If a file exists, but after removing invalid characters, it is less than 6 characters, then "empty" is returned.
105+
If a file exists, and has a somewhat valid seeming contents, will return those.
105106
106107
\sa InterSpec::writableDataDirectory
107108
*/
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
{
2-
"Usage": "Rename this file to 'InterSpec_app_settings.json' and placed either in the 'data' folder of the InterSpec distribution, or in the user data store (see 'Help' -> 'About InterSpec...' -> 'Data', for example on Windows: 'C:\\Users\\<username>\\AppData\\Roaming\\InterSpec'",
3-
"Purpose": "This file allows you to change settings for how InterSpec is launched; only intended for debugging or advanced usuage. You must close all InterSpec windows before settings will take effect.",
2+
"Usage": "Rename this file to 'InterSpec_app_settings.json' and placed either in the 'data' folder of the InterSpec distribution, or in the user data store (see 'Help' -> 'About InterSpec...' -> 'Data', for example on Windows: 'C:\\Users\\<username>\\AppData\\Roaming\\InterSpec'. All settings in this file are optional, so you can remove any settings you dont want to change/specify, and the default values will be used for that setting.",
3+
"Purpose": "This file allows you to change settings for how InterSpec is launched; only intended for debugging or advanced usage. You must close all InterSpec windows before settings will take effect.",
44

55
"ProxySetting": "",
6-
"ProxySetting_Documentation": "Only applicable to Windows and Linux builds. Valid values are: empty (default), 'direct', 'auto_detect', 'system'; any other string will be interpreted as the 'proxyRules' setting documented at https://www.electronjs.org/docs/latest/api/session#sessetproxyconfig (an value might be 'http=proxy.somecompany.com:80,direct://'). This setting is only applicable if you use the map tool (the only part of InterSpec to use the internet); if map tiles wont load, and you are behind a proxy, you may need to set this setting; usually a value of 'system' will work. If you set this settting, and you are not behind a proxy, InterSpec startup time may hang for ~30 seconds, usually with a white screen, while a proxy request times out.",
6+
"ProxySetting_Documentation": "Only applicable to Windows and Linux builds. Valid values are: empty (default), 'direct', 'auto_detect', 'system'; any other string will be interpreted as the 'proxyRules' setting documented at https://www.electronjs.org/docs/latest/api/session#sessetproxyconfig (an value might be 'http=proxy.somecompany.com:80,direct://'). This setting is only applicable if you use the map tool (the only part of InterSpec to use the internet); if map tiles wont load, and you are behind a proxy, you may need to set this setting; usually a value of 'system' will work. If you set this setting, and you are not behind a proxy, InterSpec startup time may hang for ~30 seconds, usually with a white screen, while a proxy request times out.",
77

88
"HttpPortToServeOn": 0,
9-
"HttpPortToServeOn_Documentation": "The HTTP port to serve the application on; if zero (recomended!), will choose random port on startup. Otherwise choose a port larger than 1024 (e.x., 8080) since ports below this may require admin privledges (never run InterSpec as admin!).",
9+
"HttpPortToServeOn_Documentation": "The HTTP port to serve the application on; if zero (recommended!), will choose random high-numbered port on startup. Otherwise you can choose a port larger than 1024 (e.x., 8080) since ports below this may require admin privileges (never run InterSpec as admin!). If you specify a non-zero value, then only one session of InterSpec can run on your computer at a time (although that one session may have multiple windows open).",
1010

1111
"RestorePreviousSession": true,
1212
"RestorePreviousSession_Documentation": "When true (default), InterSpec may attempt to restore your previous session in InterSpec.",
1313

1414
"AllowTokenFreeSessions": false,
15-
"AllowTokenFreeSessions_Documentation": "Normally external sessions (i.e. 'View' -> 'Use in external browser') get assigned a one-time-use token that is required to load InterSpec into the browser. Without a valid token, you cant load a session in the browser. If you allow external sessions without tokens, then the token wont be needed - and any application that can access your localhost network can create a session and potentually access your data. It is not recomended to to enable this setting.",
15+
"AllowTokenFreeSessions_Documentation": "Normally external sessions (i.e. 'View' -> 'Use in external browser') get assigned a one-time-use token that is required to load InterSpec into the browser. Without a valid token, you cant load a session in the browser. If you allow external sessions without tokens, then the token wont be needed - and any application that can access your localhost network (i.e., your computers internal network that is only accessible on your computer) can create a session and potentially access your data. It is not recommended to to enable this setting.",
1616

1717
"OpenDevTools": false,
18-
"OpenDevTools_Documentation": "Enables right-clicking on an element to open the WebView Dev Tools to allow debugging JavaScript errors you may run into (please report to InterSpec@sandia.gov if you find any). On macOS you will still need to select 'Edit' -> 'Enable Web Inspector'."
18+
"OpenDevTools_Documentation": "Enables right-clicking on an element to open the WebView Dev Tools to allow debugging JavaScript errors you may run into (please report to InterSpec@sandia.gov if you find any). On macOS you will still need to select 'Edit' -> 'Enable Web Inspector'.",
19+
20+
"ArcGisKey": "",
21+
"ArcGisKey_Documentation": "If specified (i.e., non-empty string), this key will be used to use to access the https://arcgis.com server to get map tiles from, when you invoke invoke the map tool."
1922
}

src/InterSpecServer.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,9 @@ std::string file_to_open_on_load( const std::string &session_token )
920920
m_require_token( true ),
921921
m_allow_restore( true ),
922922
m_open_dev_tools( true )
923+
#if( USE_LEAFLET_MAP )
924+
, m_arcgis_key("")
925+
#endif
923926
{
924927
}
925928

@@ -1003,6 +1006,18 @@ std::string file_to_open_on_load( const std::string &session_token )
10031006

10041007
config.m_open_dev_tools = val.toBool();
10051008
}
1009+
1010+
#if( USE_LEAFLET_MAP )
1011+
if( base.contains( "ArcGisKey" ) )
1012+
{
1013+
const Wt::Json::Value &val = base.get( "ArcGisKey" );
1014+
if( val.type() != Wt::Json::Type::StringType )
1015+
throw runtime_error( "ArcGisKey must be string" );
1016+
1017+
config.m_arcgis_key = val.orIfNull("");
1018+
}
1019+
#endif //USE_LEAFLET_MAP
1020+
10061021
};// update_config_from_json_file lamda
10071022

10081023

src/LeafletRadMap.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#if( BUILD_AS_ELECTRON_APP || IOS || ANDROID || BUILD_AS_OSX_APP || BUILD_AS_LOCAL_SERVER || BUILD_AS_WX_WIDGETS_APP )
5656
#include <Wt/Utils>
5757
#include "SpecUtils/Filesystem.h"
58+
#include "InterSpec/InterSpecServer.h"
5859
#endif
5960

6061

@@ -260,15 +261,37 @@ std::string LeafletRadMap::get_user_arcgis_key()
260261
{
261262
try
262263
{
264+
// A user specified arcgis
263265
const string user_data_dir = InterSpec::writableDataDirectory();
264266
const string user_key_file = SpecUtils::append_path(user_data_dir, "arcgis_key.txt" );
265267

268+
string user_key;
269+
270+
266271
if( !SpecUtils::is_file( user_key_file ) )
267-
return "";
268-
269-
std::vector<char> data;
270-
SpecUtils::load_file_data( user_key_file.c_str(), data );
271-
string user_key( begin(data), end(data) );
272+
{
273+
try
274+
{
275+
const string app_data_dir = InterSpec::staticDataDirectory();
276+
277+
const InterSpecServer::DesktopAppConfig app_config
278+
= InterSpecServer::DesktopAppConfig::init( app_data_dir, user_data_dir );
279+
280+
if( app_config.m_arcgis_key.empty() )
281+
return "";
282+
283+
user_key = app_config.m_arcgis_key;
284+
}catch( std::exception & )
285+
{
286+
// This error would have already been reported to the user on application startup.
287+
return "";
288+
}
289+
}else
290+
{
291+
std::vector<char> data;
292+
SpecUtils::load_file_data( user_key_file.c_str(), data );
293+
user_key = string( begin(data), end(data) );
294+
}//if( "arcgis_key.txt" not present ) / else ( "arcgis_key.txt" is present )
272295

273296
// Remove characters we dont expect
274297
while( !user_key.empty() )

0 commit comments

Comments
 (0)