(function(){$.extend(u8.Crm.PhoneLauncherProxy.prototype,{_initDiagnostics:function(){},activateDiagnostics:function(){if(this._diagnosticsActive){return $.Deferred.withValue(true)}var e=this;return this._createDiagnosticSession().then(this._startupDiagnostics.bind(this)).then(this._createDiagnosticsScheduler.bind(this)).done(function(){e._diagnosticsActive=true}).fail(function(e){u8.log.error("phone",e.message)})},_createDiagnosticSession:function(){var e=this;var t=$.Deferred();this._subscribeDiagnostics();u8.services.launcher.call(e.diagnosticsApi+"create",{}).done(function(n){e._diagnosticsId=n;t.resolve()}).fail(function(){t.reject({message:"PhoneLauncherProxy.Diagnostics: Even though launcher is connected, could not talk to phone diagnostics.",showUserMessage:false})});return t.promise()},_startupDiagnostics:function(){var e=this;return this._callDiagnosticsMethod("ActivateEmulationMode").then(function(){e._callDiagnosticsMethod("Clear")})},_createDiagnosticsScheduler:function(){var e=this,t=$.Deferred();u8.using({types:"PhoneExecutionPlanScheduler"},function(){e.scheduler=new u8.Crm.PhoneExecutionPlanScheduler({onCreate:function(n,i){n.bind("EventSimulate",e._onSchedulerEvent.bind(e));t.resolve()}})});return t.promise()},_callDiagnosticsMethod:function(e,t){var n=[this.diagnosticsApi+e,this._diagnosticsId];if(arguments.length>1){n=n.concat([].slice.call(arguments,1))}return u8.services.launcher.call.apply(u8.services.launcher,n)},_onSchedulerEvent:function(e,t){if("id"in t.eventArgs&&typeof t.eventArgs.id!="number"){t.eventArgs.id=parseInt(t.eventArgs.id)}if("id2"in t.eventArgs&&typeof t.eventArgs.id2!="number"){t.eventArgs.id2=parseInt(t.eventArgs.id2)}this._callDiagnosticsMethod(t.name,t.eventArgs).then(function(){if(t.callback){t.callback()}})}});function e(e){if(typeof e=="string"){var t={alpha:1};if(e.startsWith("#")){var n=parseInt(e.replace("#","0x"));t.color=((n&255)<<16)+(n&65280)+((n&16711680)>>>16)}else{var i=e.match(/^rgba\((\d+),\s*(\d+),\s*(\d+),\s*(\d+\.\d+)\)$/);if(i&&i.length==5){t.color=(parseInt(i[3])<<16)+(parseInt(i[2])<<8)+parseInt(i[1]);t.alpha=parseFloat(i[4])}}return t}return e}})();