Open a new window if a command is received while inactive.
Commands will be buffered and passed in to be fired on initialization. To suppress app launch, add the quiet flag to your command when firing the message from an extension. Fixes #122
This commit is contained in:
parent
5aacfc89a1
commit
2c34939a43
4 changed files with 31 additions and 3 deletions
|
@ -2,6 +2,7 @@ var mainWindow = null;
|
|||
var pending = null;
|
||||
var upgrading = false;
|
||||
var files = [];
|
||||
var commands = [];
|
||||
|
||||
var openWindow = function() {
|
||||
|
||||
|
@ -31,10 +32,12 @@ var openWindow = function() {
|
|||
}, function(win) {
|
||||
mainWindow = win;
|
||||
win.contentWindow.launchData = files;
|
||||
win.contentWindow.launchCommands = commands;
|
||||
mainWindow.onClosed.addListener(function() {
|
||||
mainWindow = null;
|
||||
});
|
||||
files = [];
|
||||
commands = [];
|
||||
pending = null;
|
||||
});
|
||||
}
|
||||
|
@ -49,5 +52,20 @@ var launch = function(launchData) {
|
|||
|
||||
};
|
||||
|
||||
var onMessage = function(message, sender, sendResponse) {
|
||||
//main window will pick up the message, if it's open
|
||||
//we also allow extensions to suppress launch behavior for spurious messages
|
||||
if (mainWindow || message.quiet) return;
|
||||
commands.push({
|
||||
message: message,
|
||||
sender: sender,
|
||||
sendResponse: sendResponse
|
||||
});
|
||||
if (pending !== null) return;
|
||||
if (upgrading) return;
|
||||
pending = setTimeout(openWindow, 250);
|
||||
};
|
||||
|
||||
chrome.app.runtime.onLaunched.addListener(launch);
|
||||
chrome.app.runtime.onRestarted.addListener(launch);
|
||||
chrome.app.runtime.onRestarted.addListener(launch);
|
||||
chrome.runtime.onMessageExternal.addListener(onMessage);
|
|
@ -77,6 +77,16 @@ define([
|
|||
}
|
||||
});
|
||||
|
||||
//register for startup and fire any commands that are pending
|
||||
register("init:startup", function() {
|
||||
if (window.launchCommands) {
|
||||
window.launchCommands.forEach(function(bundle) {
|
||||
fire(bundle.message.command, bundle.message.argument, bundle.sendResponse);
|
||||
});
|
||||
delete window.launchCommands;
|
||||
}
|
||||
});
|
||||
|
||||
var facade = {
|
||||
fire: fire,
|
||||
on: register,
|
||||
|
|
|
@ -331,7 +331,7 @@ define([
|
|||
option.value = mode.name;
|
||||
syntax.append(option);
|
||||
});
|
||||
addTab("");
|
||||
if (!tabs.length) addTab("");
|
||||
renderTabs();
|
||||
enableTabDragDrop();
|
||||
enableTabMiddleClick();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "Caret",
|
||||
"description": "Professional text editing for Chrome and Chrome OS",
|
||||
"version": "1.2.47",
|
||||
"version": "1.2.48",
|
||||
"manifest_version": 2,
|
||||
"icons": {
|
||||
"128": "icon-128.png"
|
||||
|
|
Loading…
Reference in a new issue