mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 12:55:19 +03:00
remove global access to backgroundPage, optimize eventPage, track application startup time
This commit is contained in:
parent
f9ff34fb8b
commit
a580d94d10
2 changed files with 21 additions and 18 deletions
24
eventPage.js
24
eventPage.js
|
@ -13,6 +13,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function start_app() {
|
function start_app() {
|
||||||
|
var applicationStartTime = new Date().getTime();
|
||||||
|
|
||||||
chrome.app.window.create('main.html', {
|
chrome.app.window.create('main.html', {
|
||||||
id: 'main-window',
|
id: 'main-window',
|
||||||
frame: 'chrome',
|
frame: 'chrome',
|
||||||
|
@ -21,21 +23,23 @@ function start_app() {
|
||||||
minHeight: 632
|
minHeight: 632
|
||||||
}
|
}
|
||||||
}, function (createdWindow) {
|
}, function (createdWindow) {
|
||||||
createdWindow.onClosed.addListener(function () {
|
createdWindow.contentWindow.addEventListener('load', function () {
|
||||||
// connectionId is passed from the script side through the chrome.runtime.getBackgroundPage refference
|
createdWindow.contentWindow.catch_startup_time(applicationStartTime);
|
||||||
// allowing us to automatically close the port when application shut down
|
});
|
||||||
|
|
||||||
// save connectionId in separate variable before app_window is destroyed
|
createdWindow.onClosed.addListener(function () {
|
||||||
var connectionId = app_window.serial.connectionId;
|
// autoamtically close the port when application closes
|
||||||
var valid_connection = app_window.CONFIGURATOR.connectionValid;
|
// save connectionId in separate variable before createdWindow.contentWindow is destroyed
|
||||||
var mincommand = app_window.MISC.mincommand;
|
var connectionId = createdWindow.contentWindow.serial.connectionId,
|
||||||
|
valid_connection = createdWindow.contentWindow.CONFIGURATOR.connectionValid,
|
||||||
|
mincommand = createdWindow.contentWindow.MISC.mincommand;
|
||||||
|
|
||||||
if (connectionId > 0 && valid_connection) {
|
if (connectionId > 0 && valid_connection) {
|
||||||
// code below is handmade MSP message (without pretty JS wrapper), it behaves exactly like MSP.send_message
|
// code below is handmade MSP message (without pretty JS wrapper), it behaves exactly like MSP.send_message
|
||||||
// reset motors to default (mincommand)
|
// reset motors to default (mincommand)
|
||||||
var bufferOut = new ArrayBuffer(22);
|
var bufferOut = new ArrayBuffer(22),
|
||||||
var bufView = new Uint8Array(bufferOut);
|
bufView = new Uint8Array(bufferOut),
|
||||||
var checksum = 0;
|
checksum = 0;
|
||||||
|
|
||||||
bufView[0] = 36; // $
|
bufView[0] = 36; // $
|
||||||
bufView[1] = 77; // M
|
bufView[1] = 77; // M
|
||||||
|
|
15
main.js
15
main.js
|
@ -1,13 +1,5 @@
|
||||||
'use strict';
|
'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
|
// Google Analytics
|
||||||
var googleAnalyticsService = analytics.getService('ice_cream_app');
|
var googleAnalyticsService = analytics.getService('ice_cream_app');
|
||||||
var googleAnalytics = googleAnalyticsService.getTracker('UA-32728876-6');
|
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() {
|
function microtime() {
|
||||||
var now = new Date().getTime() / 1000;
|
var now = new Date().getTime() / 1000;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue