# HG changeset patch # User Benjamin Golinvaux # Date 1558370559 -7200 # Node ID 636eb0e4c9dd680427ed9de629c2b054516a892f # Parent 90f3a60576a9f08dcf783752a7f67ce0615a5371 Adding SetApplicationParameters diff -r 90f3a60576a9 -r 636eb0e4c9dd Platforms/Wasm/wasm-application-runner.ts --- a/Platforms/Wasm/wasm-application-runner.ts Tue Apr 02 14:02:12 2019 +0000 +++ b/Platforms/Wasm/wasm-application-runner.ts Mon May 20 18:42:39 2019 +0200 @@ -22,14 +22,25 @@ var StartWasmApplication: Function = null; export var SendSerializedMessageToStoneApplication: Function = null; +var auxiliaryParameters : Map = null; + +export function SetApplicationParameters(params : Map) { + if (auxiliaryParameters != null) { + console.warn("wasm-application-runner.SetApplicationParameters: about to overwrite the existing application parameters!") + } + auxiliaryParameters = params; +} + function DoAnimationThread() { if (WasmDoAnimation != null) { WasmDoAnimation(); } - setTimeout(DoAnimationThread, 100); // Update the viewport content every 100ms if need be + // Update the viewport content every 100ms if need be + setTimeout(DoAnimationThread, 100); } + function GetUriParameters(): Map { var parameters = window.location.search.substr(1); @@ -42,10 +53,12 @@ var tmp = tokens[i].split('='); if (tmp.length == 2) { result[tmp[0]] = decodeURIComponent(tmp[1]); + } else if(tmp.length == 1) { + // if there is no '=', we treat ot afterwards as a flag-style param + result[tmp[0]] = ""; } } - - return result; + return result; } else { return new Map(); @@ -60,11 +73,22 @@ CreateWasmApplication(); - // parse uri and transmit the parameters to the app before initializing it + // transmit the API-specified parameters to the app before initializing it + for (let key in auxiliaryParameters) { + if (auxiliaryParameters.hasOwnProperty(key)) { + Logger.defaultLogger.debug( + `About to call SetStartupParameter("${key}","${auxiliaryParameters[key]}")`); + SetStartupParameter(key, auxiliaryParameters[key]); + } + } + + // parse uri and transmit the URI parameters to the app before initializing it let parameters = GetUriParameters(); for (let key in parameters) { if (parameters.hasOwnProperty(key)) { + Logger.defaultLogger.debug( + `About to call SetStartupParameter("${key}","${parameters[key]}")`); SetStartupParameter(key, parameters[key]); } } @@ -92,6 +116,8 @@ CreateCppViewport = ( window).StoneFrameworkModule.cwrap('CreateCppViewport', 'number', []); ReleaseCppViewport = ( window).StoneFrameworkModule.cwrap('ReleaseCppViewport', null, ['number']); StartWasmApplication = ( window).StoneFrameworkModule.cwrap('StartWasmApplication', null, ['string']); + ( window).IsTraceLevelEnabled = ( window).StoneFrameworkModule.cwrap('WasmIsTraceLevelEnabled', 'boolean', null); + ( window).IsInfoLevelEnabled = ( window).StoneFrameworkModule.cwrap('WasmIsInfoLevelEnabled', 'boolean', null); ( window).WasmWebService_NotifyCachedSuccess = ( window).StoneFrameworkModule.cwrap('WasmWebService_NotifyCachedSuccess', null, ['number']); ( window).WasmWebService_NotifySuccess = ( window).StoneFrameworkModule.cwrap('WasmWebService_NotifySuccess', null, ['number', 'string', 'array', 'number', 'number']);