diff --git a/eventPage.js b/eventPage.js index 8b34a0b2..cc8643af 100644 --- a/eventPage.js +++ b/eventPage.js @@ -13,6 +13,8 @@ 'use strict'; function start_app() { + var applicationStartTime = new Date().getTime(); + chrome.app.window.create('main.html', { id: 'main-window', frame: 'chrome', @@ -21,21 +23,23 @@ function start_app() { minHeight: 632 } }, function (createdWindow) { - createdWindow.onClosed.addListener(function () { - // connectionId is passed from the script side through the chrome.runtime.getBackgroundPage refference - // allowing us to automatically close the port when application shut down + createdWindow.contentWindow.addEventListener('load', function () { + createdWindow.contentWindow.catch_startup_time(applicationStartTime); + }); - // save connectionId in separate variable before app_window is destroyed - var connectionId = app_window.serial.connectionId; - var valid_connection = app_window.CONFIGURATOR.connectionValid; - var mincommand = app_window.MISC.mincommand; + createdWindow.onClosed.addListener(function () { + // autoamtically close the port when application closes + // save connectionId in separate variable before createdWindow.contentWindow is destroyed + var connectionId = createdWindow.contentWindow.serial.connectionId, + valid_connection = createdWindow.contentWindow.CONFIGURATOR.connectionValid, + mincommand = createdWindow.contentWindow.MISC.mincommand; if (connectionId > 0 && valid_connection) { // code below is handmade MSP message (without pretty JS wrapper), it behaves exactly like MSP.send_message // reset motors to default (mincommand) - var bufferOut = new ArrayBuffer(22); - var bufView = new Uint8Array(bufferOut); - var checksum = 0; + var bufferOut = new ArrayBuffer(22), + bufView = new Uint8Array(bufferOut), + checksum = 0; bufView[0] = 36; // $ bufView[1] = 77; // M diff --git a/main.js b/main.js index e908cadd..e5f96847 100644 --- a/main.js +++ b/main.js @@ -1,13 +1,5 @@ 'use strict'; -// Get access to the background window object -// This object is used to pass variables between active page and background page -var backgroundPage; -chrome.runtime.getBackgroundPage(function (result) { - backgroundPage = result; - backgroundPage.app_window = window; -}); - // Google Analytics var googleAnalyticsService = analytics.getService('ice_cream_app'); var googleAnalytics = googleAnalyticsService.getTracker('UA-32728876-6'); @@ -259,6 +251,13 @@ $(document).ready(function () { }); }); +function catch_startup_time(startTime) { + var endTime = new Date().getTime(), + timeSpent = endTime - startTime; + + googleAnalytics.sendTiming('Load Times', 'Application Startup', timeSpent); +} + function microtime() { var now = new Date().getTime() / 1000;