commit 7d87d70e92eb03907ab3ed66b55d5133aa0609fb
parent e355cab8862548e4e0ebe5182dcd4a9618955221
Author: Simon Kornblith <simon@simonster.com>
Date: Sun, 12 Jul 2015 13:45:39 -0400
Expose more integration pipe handling code
This should eventually reduce the amount of duplicated code needed to
handle Word 2016 for Mac
Diffstat:
1 file changed, 25 insertions(+), 17 deletions(-)
diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js
@@ -88,7 +88,7 @@ Zotero.Integration = new function() {
sharedPipe.append(".zoteroIntegrationPipe_"+logname);
if(sharedPipe.exists()) {
- if(_deletePipe(sharedPipe) && sharedDir.isWritable()) {
+ if(this.deletePipe(sharedPipe) && sharedDir.isWritable()) {
pipe = sharedPipe;
}
} else if(sharedDir.isWritable()) {
@@ -104,36 +104,44 @@ Zotero.Integration = new function() {
pipe.append(".zoteroIntegrationPipe");
// destroy old pipe, if one exists
- if(!_deletePipe(pipe)) return;
+ if(!this.deletePipe(pipe)) return;
}
// try to initialize pipe
try {
- Zotero.IPC.Pipe.initPipeListener(pipe, function(string) {
- if(string != "") {
- // exec command if possible
- var parts = string.match(/^([^ \n]*) ([^ \n]*)(?: ([^\n]*))?\n?$/);
- if(parts) {
- var agent = parts[1].toString();
- var cmd = parts[2].toString();
- var document = parts[3] ? parts[3].toString() : null;
- Zotero.Integration.execCommand(agent, cmd, document);
- } else {
- Components.utils.reportError("Zotero: Invalid integration input received: "+string);
- }
- }
- });
+ this.initPipe(pipe);
} catch(e) {
Zotero.logError(e);
}
Q.delay(1000).then(_checkPluginVersions);
}
+
+ /**
+ * Begin listening for integration commands on the given pipe
+ * @param {String} pipe The path to the pipe
+ */
+ this.initPipe = function(pipe) {
+ Zotero.IPC.Pipe.initPipeListener(pipe, function(string) {
+ if(string != "") {
+ // exec command if possible
+ var parts = string.match(/^([^ \n]*) ([^ \n]*)(?: ([^\n]*))?\n?$/);
+ if(parts) {
+ var agent = parts[1].toString();
+ var cmd = parts[2].toString();
+ var document = parts[3] ? parts[3].toString() : null;
+ Zotero.Integration.execCommand(agent, cmd, document);
+ } else {
+ Components.utils.reportError("Zotero: Invalid integration input received: "+string);
+ }
+ }
+ });
+ }
/**
* Deletes a defunct pipe on OS X
*/
- function _deletePipe(pipe) {
+ this.deletePipe = function(pipe) {
try {
if(pipe.exists()) {
Zotero.IPC.safePipeWrite(pipe, "Zotero shutdown\n");