Skip to content

Commit

Permalink
fixup! Make EM the default translator. Rework snapshot saving pref.
Browse files Browse the repository at this point in the history
  • Loading branch information
adomasven committed Mar 1, 2018
1 parent f51a2f7 commit ffcafc0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ function processFile() {
file.contents = Buffer.from(file.contents.toString()
.replace("/*BACKGROUND SCRIPTS*/",
backgroundInclude.map((s) => `"${s}"`).join(',\n\t\t\t'))
.replace("/*INJECT SCRIPTS*/",
injectIncludeBrowserExt.map((s) => `"${s}"`).join(',\n\t\t'))
.replace(/"version": "[^"]*"/, '"version": "'+argv.version+'"'));
break;
case 'script-injection.js':
Expand Down
2 changes: 1 addition & 1 deletion src/browserExt/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ Zotero.Connector_Browser = new function() {
browser.webNavigation.onCommitted.addListener(logListenerErrors(async function(details) {
var tab = await browser.tabs.get(details.tabId);
// Ignore developer tools
if (tab.id < 0 || _isDisabledForURL(tab.url, true)) return;
if (tab.id < 0 || Zotero.Connector_Browser.isDisabledForURL(tab.url, true)) return;

if (details.frameId == 0) {
// Ignore item selector
Expand Down
13 changes: 7 additions & 6 deletions src/browserExt/script-injection.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Zotero.Extension.ScriptInjection = {
let key = tab.id+'-'+frameId;
let deferred = this.injectTranslationScripts[key];
if (deferred) {
Zotero.debug(`Extension.ScriptInjection.injectTranslationScripts: Script injection already in progress for ${key} : ${tab.url}`);
Zotero.debug(`Translation Inject: Script injection already in progress for ${key}`);
return deferred.promise;
}
deferred = Zotero.Promise.defer();
Expand All @@ -52,13 +52,14 @@ Zotero.Extension.ScriptInjection = {
Zotero.debug(`Translation Inject: Script injection rejected ${key}`);
Zotero.debug(e.message);
}).then(function() {
delete Zotero.Connector_Browser.injectTranslationScripts[key];
delete Zotero.Extension.ScriptInjection.injectTranslationScripts[key];
});

Zotero.Messaging.sendMessage('ping', null, tab, frameId).then(function(response) {
if (response && frameId == 0) return deferred.resolve();
Zotero.debug(`Injecting translation scripts into ${frameId} ${tab.url}`);
return Zotero.Connector_Browser.injectScripts(_injectTranslationScripts, tab, frameId)
return Zotero.Connector_Browser.injectScripts(
Zotero.Extension.ScriptInjection._translationScriptList, tab, frameId)
.then(deferred.resolve).catch(deferred.reject);
});
return deferred.promise;
Expand Down Expand Up @@ -114,8 +115,8 @@ Zotero.Extension.ScriptInjection = {

var timedOut = Zotero.Promise.defer();
let timeout = setTimeout(function() {
timedOut.reject(new Error (`Inject: Timed out ${frameId} - ${tab.url} after ${this.INJECTION_TIMEOUT}ms`))
}.bind(this), this.INJECTION_TIMEOUT);
timedOut.reject(new Error (`Inject: Timed out ${frameId} - ${tab.url} after ${Zotero.Extension.ScriptInjection.INJECTION_TIMEOUT}ms`))
}, Zotero.Extension.ScriptInjection.INJECTION_TIMEOUT);

// Prevent triggering multiple times
let deferred = Zotero.Connector_Browser._tabInfo[tab.id].injections[frameId];
Expand Down Expand Up @@ -153,7 +154,7 @@ Zotero.Extension.ScriptInjection = {
} finally {
browser.tabs.onRemoved.removeListener(tabRemovedListener);
deferred.resolve();
delete _tabInfo[tab.id].injections[frameId];
delete Zotero.Connector_Browser._tabInfo[tab.id].injections[frameId];
clearTimeout(timeout);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/browserExt/test/testSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Zotero.initDeferred.promise.then(function() {

let scripts = [ 'lib/sinon.js', 'test/testSetup.js' ];
try {
await Zotero.Extension.injectScripts(scripts, tab);
await Zotero.Connector_Browser.injectScripts(scripts, tab);
deferred.resolved = true;
deferred.resolve(tab.id);
} catch(e) {
Expand Down Expand Up @@ -152,6 +152,10 @@ if (typeof mocha != 'undefined') {
var deferred = Zotero.Promise.defer();
var tab = await browser.tabs.create({url, active: false});
Zotero.Background.registeredTabs[tab.id] = deferred;
Zotero.Connector_Browser._tabInfo[tab.id] = {
url: url,
injections: {}
};
return deferred.promise;
}, url);
}),
Expand Down

0 comments on commit ffcafc0

Please sign in to comment.