2013-09-05 01:36:27 +00:00
|
|
|
var mainWindow = null;
|
2013-10-28 19:58:24 +00:00
|
|
|
var timeout = null;
|
|
|
|
var files = [];
|
2013-09-05 01:36:27 +00:00
|
|
|
|
2013-10-28 19:58:24 +00:00
|
|
|
var openWindow = function() {
|
2013-09-05 01:36:27 +00:00
|
|
|
|
2013-10-28 19:58:24 +00:00
|
|
|
//if window exists, re-use it
|
2013-09-05 01:36:27 +00:00
|
|
|
if (mainWindow) {
|
2013-10-28 19:58:24 +00:00
|
|
|
mainWindow.contentWindow.launchData = files;
|
2013-09-05 01:36:27 +00:00
|
|
|
mainWindow.contentWindow.require(["command"], function(c) {
|
|
|
|
c.fire("session:open-launch");
|
|
|
|
});
|
2013-09-12 02:36:14 +00:00
|
|
|
mainWindow.focus();
|
|
|
|
mainWindow.drawAttention();
|
2013-10-28 19:58:24 +00:00
|
|
|
files = [];
|
|
|
|
timeout = null;
|
2013-09-05 01:36:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-10-28 19:58:24 +00:00
|
|
|
|
|
|
|
//otherwise, open a new window
|
2013-09-05 01:36:27 +00:00
|
|
|
chrome.storage.local.get("bounds", function(data) {
|
2013-10-02 23:12:35 +00:00
|
|
|
var defaults = {
|
2013-09-05 01:36:27 +00:00
|
|
|
width: 800,
|
|
|
|
height: 600,
|
2013-09-13 18:13:00 +00:00
|
|
|
left: 50,
|
|
|
|
top: 50
|
2013-09-05 01:36:27 +00:00
|
|
|
};
|
2013-10-02 23:12:35 +00:00
|
|
|
var bounds = data.bounds || defaults;
|
|
|
|
//sanity check the bounds information -- also need to add maximums
|
|
|
|
if (bounds.left < 0 || bounds.top < 0 || bounds.width < 0 || bounds.height < 0) {
|
|
|
|
bounds = defaults;
|
|
|
|
}
|
2013-09-05 01:36:27 +00:00
|
|
|
chrome.app.window.create("main.html", {
|
|
|
|
bounds: bounds
|
|
|
|
}, function(win) {
|
|
|
|
mainWindow = win;
|
2013-10-28 19:58:24 +00:00
|
|
|
win.contentWindow.launchData = files;
|
2013-09-05 01:36:27 +00:00
|
|
|
mainWindow.onClosed.addListener(function() {
|
|
|
|
mainWindow = null;
|
2013-08-23 23:03:46 +00:00
|
|
|
});
|
2013-10-28 19:58:24 +00:00
|
|
|
files = [];
|
|
|
|
timeout = null;
|
2013-08-20 00:53:03 +00:00
|
|
|
});
|
2013-09-05 01:36:27 +00:00
|
|
|
|
|
|
|
});
|
2013-10-28 19:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var launch = function(launchData) {
|
|
|
|
|
2013-10-29 06:13:35 +00:00
|
|
|
if (launchData && launchData.items) files.push.apply(files, launchData.items);
|
2013-10-28 19:58:24 +00:00
|
|
|
//we delay opening the actual window to give multiple file events time to fire
|
|
|
|
if (timeout !== null) return;
|
|
|
|
timeout = setTimeout(openWindow, 250);
|
2013-09-05 01:36:27 +00:00
|
|
|
|
2013-10-15 05:17:58 +00:00
|
|
|
};
|
|
|
|
|
2013-10-28 19:58:24 +00:00
|
|
|
chrome.app.runtime.onLaunched.addListener(launch);
|
|
|
|
chrome.app.runtime.onRestarted.addListener(launch);
|