Disable in-page translation functionality when the built-in version is enabled (#734)
This commit is contained in:
Родитель
b00d371230
Коммит
b4c8359dde
|
@ -67,6 +67,7 @@ let pingSender = new PingSender();
|
|||
let modelFastText = null;
|
||||
let modelFastTextReadyPromise = null;
|
||||
|
||||
let isBuiltInEnabled = null;
|
||||
let telemetryByTab = new Map();
|
||||
let pingByTab = new Set();
|
||||
let translationRequestsByTab = new Map();
|
||||
|
@ -181,6 +182,7 @@ const messageListener = function(message, sender) {
|
|||
break;
|
||||
}
|
||||
case "monitorTabLoad":
|
||||
if (isBuiltInEnabled || (isBuiltInEnabled === null && await browser.experiments.translationbar.isBuiltInEnabled())) return;
|
||||
if (!await isFrameLoaded(sender.tab.id, sender.frameId)) return;
|
||||
browser.tabs.sendMessage(
|
||||
sender.tab.id,
|
||||
|
@ -531,10 +533,12 @@ browser.runtime.getPlatformInfo().then(info => {
|
|||
init();
|
||||
const retrieveOptionsFromStorage = browser.storage.local.get(["displayedConsent", "lastVersion", "showChangelog"]);
|
||||
const isMochitestPromise = browser.experiments.translationbar.isMochitest();
|
||||
const isBuiltInEnabledPromise = browser.experiments.translationbar.isBuiltInEnabled();
|
||||
|
||||
Promise.allSettled([
|
||||
retrieveOptionsFromStorage,
|
||||
isMochitestPromise,
|
||||
isBuiltInEnabledPromise,
|
||||
]).then(values => {
|
||||
const { displayedConsent, lastVersion: lastVersionDisplayed, showChangelog } = values[0].value || {};
|
||||
isMochitest = values[1].value;
|
||||
|
@ -550,6 +554,17 @@ browser.runtime.getPlatformInfo().then(info => {
|
|||
});
|
||||
browser.storage.local.set({ lastVersion: extensionVersion });
|
||||
}
|
||||
|
||||
isBuiltInEnabled = values[2].value;
|
||||
if (!isBuiltInEnabled) {
|
||||
browser.tabs.onCreated.addListener(tab => browser.pageAction.show(tab.id));
|
||||
|
||||
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||
if (changeInfo.status === "complete" && !tab.pageActionShown) {
|
||||
browser.pageAction.show(tabId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -90,6 +90,9 @@ const translationNotificationManagers = new Map();
|
|||
return {
|
||||
experiments: {
|
||||
translationbar: {
|
||||
isBuiltInEnabled: function isBuiltInEnabled() {
|
||||
return Services.prefs.getBoolPref("browser.translations.enable", false);
|
||||
},
|
||||
show: function show(tabId, detectedLanguage, navigatorLanguage, localizedLabels, pageActionRequest, infobarSettings, autoTranslate, otSupported) {
|
||||
try {
|
||||
|
||||
|
|
|
@ -2,6 +2,13 @@
|
|||
{
|
||||
"namespace": "experiments.translationbar",
|
||||
"functions": [
|
||||
{
|
||||
"name": "isBuiltInEnabled",
|
||||
"type": "function",
|
||||
"description": "Returns true if the built-in version is enabled.",
|
||||
"async": true,
|
||||
"parameters": []
|
||||
},
|
||||
{
|
||||
"name": "show",
|
||||
"type": "function",
|
||||
|
|
|
@ -145,7 +145,6 @@
|
|||
"96": "/view/icons/translation-color.svg"
|
||||
},
|
||||
"page_action": {
|
||||
"show_matches": ["<all_urls>"],
|
||||
"browser_style": true,
|
||||
"default_icon": "view/icons/translation-bw.svg",
|
||||
"default_title": "Firefox Translations"
|
||||
|
|
|
@ -79,6 +79,10 @@ class AndroidUI {
|
|||
return this.mapLangs.get(lng);
|
||||
}
|
||||
|
||||
isBuiltInEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
isMochitest() {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -145,7 +145,6 @@
|
|||
"96": "/view/icons/translation-color.svg"
|
||||
},
|
||||
"page_action": {
|
||||
"show_matches": ["<all_urls>"],
|
||||
"browser_style": true,
|
||||
"default_icon": "view/icons/translation-bw.svg",
|
||||
"default_title": "Firefox Translations"
|
||||
|
|
Загрузка…
Ссылка в новой задаче