2014-02-14 13:18:19 +00:00
|
|
|
/*
|
|
|
|
If an id is also specified and a window with a matching id has been shown before, the remembered bounds of the window will be used instead.
|
2014-06-24 13:15:22 +00:00
|
|
|
|
|
|
|
Size calculation for innerBounds seems to be faulty, app was designed for 960x625, using arbitrary values to make innerBounds happy for now
|
|
|
|
arbitrary values do match the windows ui, how it will affect other OSs is currently unknown
|
2014-02-14 13:18:19 +00:00
|
|
|
*/
|
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-04-19 20:43:19 +00:00
|
|
|
frame: 'chrome',
|
2014-05-08 09:31:04 +00:00
|
|
|
minWidth: 960,
|
|
|
|
minHeight: 625
|
2014-02-22 08:52:28 +00:00
|
|
|
}, function(createdWindow) {
|
|
|
|
createdWindow.onClosed.addListener(function() {
|
2013-06-19 11:06:14 +00:00
|
|
|
// 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-03-08 05:25:15 +00:00
|
|
|
|
2014-01-20 19:15:23 +00:00
|
|
|
// save connectionId in separate variable before app_window is destroyed
|
|
|
|
var connectionId = app_window.serial.connectionId;
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-01-20 19:15:23 +00:00
|
|
|
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
|
|
|
});
|
2014-06-24 13:15:22 +00:00
|
|
|
|
|
|
|
/* code belowis chrome 36+ ready, till this is enforced in manifest we have to use the old version
|
|
|
|
chrome.app.window.create('main.html', {
|
|
|
|
id: 'main-window',
|
|
|
|
frame: 'chrome',
|
|
|
|
innerBounds: {
|
|
|
|
minWidth: 974,
|
|
|
|
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
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
console.log('SERIAL: Connection closed - ' + result);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
*/
|
2013-11-12 06:15:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chrome.app.runtime.onLaunched.addListener(function() {
|
|
|
|
start_app();
|
|
|
|
});
|
|
|
|
|
|
|
|
chrome.runtime.onInstalled.addListener(function(details) {
|
2014-03-08 05:25:15 +00:00
|
|
|
if (details.reason == 'update') {
|
2014-05-10 12:24:14 +00:00
|
|
|
var previousVersionArr = details.previousVersion.split('.');
|
|
|
|
var currentVersionArr = chrome.runtime.getManifest().version.split('.');
|
2014-03-08 05:25:15 +00:00
|
|
|
|
2014-05-10 12:24:14 +00:00
|
|
|
// only fire up notification sequence when one of the major version numbers changed
|
|
|
|
if (currentVersionArr[0] != previousVersionArr[0] || currentVersionArr[1] != previousVersionArr[1]) {
|
|
|
|
chrome.storage.local.get('update_notify', function(result) {
|
|
|
|
if (typeof result.update_notify === 'undefined' || result.update_notify) {
|
|
|
|
var manifest = chrome.runtime.getManifest();
|
|
|
|
var options = {
|
|
|
|
priority: 0,
|
|
|
|
type: 'basic',
|
|
|
|
title: manifest.name,
|
|
|
|
message: chrome.i18n.getMessage('notifications_app_just_updated_to_version', [manifest.version]),
|
|
|
|
iconUrl: '/images/icon_128.png',
|
|
|
|
buttons: [{'title': chrome.i18n.getMessage('notifications_click_here_to_start_app')}]
|
|
|
|
};
|
|
|
|
|
|
|
|
chrome.notifications.create('baseflight_update', options, function(notificationId) {
|
|
|
|
// empty
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-11-12 06:15:18 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
chrome.notifications.onButtonClicked.addListener(function(notificationId, buttonIndex) {
|
|
|
|
if (notificationId == 'baseflight_update') {
|
|
|
|
start_app();
|
|
|
|
}
|
2013-04-08 15:29:52 +00:00
|
|
|
});
|