Expose more integration pipe handling code
This should eventually reduce the amount of duplicated code needed to handle Word 2016 for Mac
This commit is contained in:
parent
e355cab886
commit
7d87d70e92
1 changed files with 25 additions and 17 deletions
|
@ -88,7 +88,7 @@ Zotero.Integration = new function() {
|
||||||
sharedPipe.append(".zoteroIntegrationPipe_"+logname);
|
sharedPipe.append(".zoteroIntegrationPipe_"+logname);
|
||||||
|
|
||||||
if(sharedPipe.exists()) {
|
if(sharedPipe.exists()) {
|
||||||
if(_deletePipe(sharedPipe) && sharedDir.isWritable()) {
|
if(this.deletePipe(sharedPipe) && sharedDir.isWritable()) {
|
||||||
pipe = sharedPipe;
|
pipe = sharedPipe;
|
||||||
}
|
}
|
||||||
} else if(sharedDir.isWritable()) {
|
} else if(sharedDir.isWritable()) {
|
||||||
|
@ -104,11 +104,24 @@ Zotero.Integration = new function() {
|
||||||
pipe.append(".zoteroIntegrationPipe");
|
pipe.append(".zoteroIntegrationPipe");
|
||||||
|
|
||||||
// destroy old pipe, if one exists
|
// destroy old pipe, if one exists
|
||||||
if(!_deletePipe(pipe)) return;
|
if(!this.deletePipe(pipe)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to initialize pipe
|
// try to initialize pipe
|
||||||
try {
|
try {
|
||||||
|
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) {
|
Zotero.IPC.Pipe.initPipeListener(pipe, function(string) {
|
||||||
if(string != "") {
|
if(string != "") {
|
||||||
// exec command if possible
|
// exec command if possible
|
||||||
|
@ -123,17 +136,12 @@ Zotero.Integration = new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch(e) {
|
|
||||||
Zotero.logError(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
Q.delay(1000).then(_checkPluginVersions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a defunct pipe on OS X
|
* Deletes a defunct pipe on OS X
|
||||||
*/
|
*/
|
||||||
function _deletePipe(pipe) {
|
this.deletePipe = function(pipe) {
|
||||||
try {
|
try {
|
||||||
if(pipe.exists()) {
|
if(pipe.exists()) {
|
||||||
Zotero.IPC.safePipeWrite(pipe, "Zotero shutdown\n");
|
Zotero.IPC.safePipeWrite(pipe, "Zotero shutdown\n");
|
||||||
|
|
Loading…
Reference in a new issue