diff --git a/build/browser/app.js b/build/browser/app.js index 4ac5d007..34e36b83 100644 --- a/build/browser/app.js +++ b/build/browser/app.js @@ -43,6 +43,32 @@ var app = angular.module('ResinEtcher', [ 'ResinEtcher.logger' ]); +// TrackJS integration +// http://docs.trackjs.com/tracker/framework-integrations +app.config(function($provide) { + 'use strict'; + + $provide.decorator('$exceptionHandler', function($delegate, $window) { + return function(exception, cause) { + $window.trackJs.track(exception); + $delegate(exception, cause); + }; + }); + + $provide.decorator('$log', function($delegate, $window) { + + // Save the original $log.debug() + var debugFn = $delegate.debug; + + $delegate.debug = function(message) { + $window.trackJs.console.debug(message); + debugFn.call(null, message); + }; + + return $delegate; + }); +}); + app.controller('AppController', function($q, DriveScannerService, SelectionStateService, ImageWriterService, LoggerService) { 'use strict'; diff --git a/lib/browser/app.js b/lib/browser/app.js index 6253d097..83e70c8c 100644 --- a/lib/browser/app.js +++ b/lib/browser/app.js @@ -42,6 +42,32 @@ var app = angular.module('ResinEtcher', [ 'ResinEtcher.logger' ]); +// TrackJS integration +// http://docs.trackjs.com/tracker/framework-integrations +app.config(function($provide) { + 'use strict'; + + $provide.decorator('$exceptionHandler', function($delegate, $window) { + return function(exception, cause) { + $window.trackJs.track(exception); + $delegate(exception, cause); + }; + }); + + $provide.decorator('$log', function($delegate, $window) { + + // Save the original $log.debug() + var debugFn = $delegate.debug; + + $delegate.debug = function(message) { + $window.trackJs.console.debug(message); + debugFn.call(null, message); + }; + + return $delegate; + }); +}); + app.controller('AppController', function($q, DriveScannerService, SelectionStateService, ImageWriterService, LoggerService) { 'use strict'; diff --git a/lib/index.html b/lib/index.html index af569951..0f4c252e 100644 --- a/lib/index.html +++ b/lib/index.html @@ -12,6 +12,11 @@ + + + + + diff --git a/vendor/tracker.js b/vendor/tracker.js new file mode 100644 index 00000000..12eec2f2 --- /dev/null +++ b/vendor/tracker.js @@ -0,0 +1,42 @@ +// COPYRIGHT (c) 2015 TrackJS LLC ALL RIGHTS RESERVED +(function(h,q,k){"use awesome";if(h.trackJs)h.console&&h.console.warn&&h.console.warn("TrackJS global conflict");else{var l=function(a,b,c,d,e){this.util=a;this.onError=b;this.onFault=c;this.options=e;e.enabled&&this.initialize(d)};l.prototype={initialize:function(a){a.addEventListener&&(this.wrapAndCatch(a.Element.prototype,"addEventListener",1),this.wrapAndCatch(a.XMLHttpRequest.prototype,"addEventListener",1),this.wrapRemoveEventListener(a.Element.prototype),this.wrapRemoveEventListener(a.XMLHttpRequest.prototype)); +this.wrapAndCatch(a,"setTimeout",0);this.wrapAndCatch(a,"setInterval",0)},wrapAndCatch:function(a,b,c){var d=this,e=a[b];d.util.hasFunction(e,"apply")&&(a[b]=function(){try{var f=Array.prototype.slice.call(arguments),g=f[c],v,h;if(d.options.bindStack)try{throw Error();}catch(k){h=k.stack,v=d.util.isoNow()}if("addEventListener"===b&&(this._trackJsEvt||(this._trackJsEvt=new m),this._trackJsEvt.getWrapped(f[0],g,f[2])))return;g&&d.util.hasFunction(g,"apply")&&(f[c]=function(){try{return g.apply(this, +arguments)}catch(a){throw d.onError("catch",a,{bindTime:v,bindStack:h}),d.util.wrapError(a);}},"addEventListener"===b&&this._trackJsEvt.add(f[0],g,f[2],f[c]));return e.apply(this,f)}catch(l){a[b]=e,d.onFault(l)}})},wrapRemoveEventListener:function(a){if(a&&a.removeEventListener&&this.util.hasFunction(a.removeEventListener,"call")){var b=a.removeEventListener;a.removeEventListener=function(a,d,e){if(this._trackJsEvt){var f=this._trackJsEvt.getWrapped(a,d,e);f&&this._trackJsEvt.remove(a,d,e);return b.call(this, +a,f,e)}return b.call(this,a,d,e)}}}};var m=function(){this.events=[]};m.prototype={add:function(a,b,c,d){-1>=this.indexOf(a,b,c)&&this.events.push([a,b,!!c,d])},remove:function(a,b,c){a=this.indexOf(a,b,!!c);0<=a&&this.events.splice(a,1)},getWrapped:function(a,b,c){a=this.indexOf(a,b,!!c);return 0<=a?this.events[a][3]:k},indexOf:function(a,b,c){for(var d=0;dthis.maxLength&&(this.appender=this.appender.slice(Math.max(this.appender.length-this.maxLength,0)))},add:function(a,b){var c=this.util.uuid();this.appender.push({key:c,category:a,value:b});this.truncate();return c},get:function(a,b){var c,d;for(d=0;db.indexOf("localhost:0")&&(this._trackJs={method:a,url:b});return c.apply(this,arguments)};a.prototype.send=function(){try{if(!this._trackJs)return d.apply(this,arguments);this._trackJs.logId=b.log.add("n",{startedOn:b.util.isoNow(),method:this._trackJs.method,url:this._trackJs.url});b.listenForNetworkComplete(this)}catch(a){b.onFault(a)}return d.apply(this,arguments)};return a},listenForNetworkComplete:function(a){var b= +this;b.window.ProgressEvent&&a.addEventListener&&a.addEventListener("readystatechange",function(){4===a.readyState&&b.finalizeNetworkEvent(a)},!0);a.addEventListener?a.addEventListener("load",function(){b.finalizeNetworkEvent(a);b.checkNetworkFault(a)},!0):setTimeout(function(){try{var c=a.onload;a.onload=function(){b.finalizeNetworkEvent(a);b.checkNetworkFault(a);"function"===typeof c&&b.util.hasFunction(c,"apply")&&c.apply(a,arguments)};var d=a.onerror;a.onerror=function(){b.finalizeNetworkEvent(a); +b.checkNetworkFault(a);"function"===typeof oldOnError&&d.apply(a,arguments)}}catch(e){b.onFault(e)}},0)},finalizeNetworkEvent:function(a){if(a._trackJs){var b=this.log.get("n",a._trackJs.logId);b&&(b.completedOn=this.util.isoNow(),b.statusCode=1223==a.status?204:a.status,b.statusText=1223==a.status?"No Content":a.statusText)}},checkNetworkFault:function(a){if(this.options.error&&400<=a.status&&1223!=a.status){var b=a._trackJs||{};this.onError("ajax",a.status+" "+a.statusText+": "+b.method+" "+b.url)}}, +report:function(){return this.log.all("n")}};var n=function(a){this.util=a;this.disabled=!1;this.throttleStats={attemptCount:0,throttledCount:0,lastAttempt:(new Date).getTime()};h.JSON&&h.JSON.stringify||(this.disabled=!0)};n.prototype={errorEndpoint:function(a){var b="https://capture.trackjs.com/capture";this.util.testCrossdomainXhr()||-1!==h.location.protocol.indexOf("https")||(b="http://capture.trackjs.com/capture");return b+"?token="+a},usageEndpoint:function(a){return this.appendObjectAsQuery(a, +"https://usage.trackjs.com/usage.gif")},trackerFaultEndpoint:function(a){return this.appendObjectAsQuery(a,"https://usage.trackjs.com/fault.gif")},appendObjectAsQuery:function(a,b){b+="?";for(var c in a)a.hasOwnProperty(c)&&(b+=encodeURIComponent(c)+"="+encodeURIComponent(a[c])+"&");return b},getCORSRequest:function(a,b){var c;this.util.testCrossdomainXhr()?(c=new h.XMLHttpRequest,c.open(a,b),c.setRequestHeader("Content-Type","text/plain")):"undefined"!==typeof h.XDomainRequest?(c=new h.XDomainRequest, +c.open(a,b)):c=null;return c},sendTrackerFault:function(a){this.throttle(a)||((new Image).src=this.trackerFaultEndpoint(a))},sendUsage:function(a){(new Image).src=this.usageEndpoint(a)},sendError:function(a,b){var c=this;if(!this.disabled&&!this.throttle(a))try{var d=this.getCORSRequest("POST",this.errorEndpoint(b));d.onreadystatechange=function(){4===d.readyState&&200!==d.status&&(c.disabled=!0)};d._trackJs=k;d.send(h.JSON.stringify(a))}catch(e){throw this.disabled=!0,e;}},throttle:function(a){var b= +(new Date).getTime();this.throttleStats.attemptCount++;if(this.throttleStats.lastAttempt+1E3>=b){if(this.throttleStats.lastAttempt=b,10