2013-11-12 06:15:18 +00:00
|
|
|
function start_app() {
|
2013-04-08 15:29:52 +00:00
|
|
|
chrome.app.window.create('main.html', {
|
|
|
|
id: 'main-window',
|
2014-01-18 18:21:30 +00:00
|
|
|
frame: 'none',
|
2014-02-03 05:19:06 +00:00
|
|
|
resizable: false,
|
|
|
|
minWidth: 962,
|
|
|
|
minHeight: 729,
|
|
|
|
maxWidth: 962,
|
|
|
|
maxHeight: 729
|
2013-06-19 11:06:14 +00:00
|
|
|
}, function(window_child) {
|
|
|
|
window_child.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
|
2014-01-20 19:15:23 +00:00
|
|
|
|
|
|
|
// save connectionId in separate variable before app_window is destroyed
|
|
|
|
var connectionId = app_window.serial.connectionId;
|
|
|
|
|
|
|
|
if (connectionId > 0) {
|
|
|
|
chrome.serial.disconnect(connectionId, function(result) {
|
2013-12-06 17:32:32 +00:00
|
|
|
console.log('SERIAL: Connection closed - ' + result);
|
2013-06-19 11:06:14 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2013-04-08 15:29:52 +00:00
|
|
|
});
|
2013-11-12 06:15:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chrome.app.runtime.onLaunched.addListener(function() {
|
|
|
|
start_app();
|
|
|
|
});
|
|
|
|
|
|
|
|
chrome.runtime.onInstalled.addListener(function(details) {
|
|
|
|
if (details.reason == 'update') {
|
|
|
|
var manifest = chrome.runtime.getManifest();
|
|
|
|
var options = {
|
|
|
|
priority: 0,
|
|
|
|
type: 'basic',
|
|
|
|
title: 'Baseflight Configurator Update',
|
|
|
|
message: 'Application just updated to version: ' + manifest.version,
|
|
|
|
iconUrl: '/images/icon_128.png',
|
|
|
|
buttons: [{'title': 'Click this button to start the application'}]
|
|
|
|
};
|
|
|
|
|
|
|
|
chrome.notifications.create('baseflight_update', options, function(notificationId) {
|
|
|
|
// empty
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
chrome.notifications.onButtonClicked.addListener(function(notificationId, buttonIndex) {
|
|
|
|
if (notificationId == 'baseflight_update') {
|
|
|
|
start_app();
|
|
|
|
}
|
2013-04-08 15:29:52 +00:00
|
|
|
});
|