Преглед на файлове

added "auto-close the tab after the page is saved" option (fix #185)

Former-commit-id: 84d770e753f576a61fd727afa2cc38ccb325c55b
Gildas преди 6 години
родител
ревизия
14bd405120

+ 4 - 0
_locales/de/messages.json

@@ -135,6 +135,10 @@
         "message": "Inhalt des Infoknopfs im Dialogfenster eingeben",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
     },
+    "optionAutoCloseLabel": {
+        "message": "Automatisches Schließen der Registerkarte (TAB) nach dem Speichern der Seite",
+        "description": "Options page label: 'auto-close the tab after the page is saved'"
+    },
     "optionsFileNameSubTitle": {
         "message": "Dateiname",
         "description": "Options sub-title: 'File name'"

+ 4 - 0
_locales/en/messages.json

@@ -135,6 +135,10 @@
         "message": "open a prompt dialog to edit the infobar content",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
     },
+    "optionAutoCloseLabel": {
+        "message": "auto-close the tab after the page is saved",
+        "description": "Options page label: 'auto-close the tab after the page is saved'"
+    },
     "optionsFileNameSubTitle": {
         "message": "File name",
         "description": "Options sub-title: 'File name'"

+ 4 - 0
_locales/es/messages.json

@@ -135,6 +135,10 @@
         "message": "abrir un cuadro de diálogo para editar el contenido de la barra informativa",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
     },
+    "optionAutoCloseLabel": {
+        "message": "cerrar automáticamente la pestaña después de guardar la página",
+        "description": "Options page label: 'auto-close the tab after the page is saved'"
+    },
     "optionsFileNameSubTitle": {
         "message": "Nombre del archivo",
         "description": "Options sub-title: 'File name'"

+ 4 - 0
_locales/fr/messages.json

@@ -135,6 +135,10 @@
         "message": "ouvrir une boite de dialogue pour éditer le contenu de la barre d'information",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
     },
+    "optionAutoCloseLabel": {
+        "message": "fermer automatiquement l'onglet après l'enregistrement de la page",
+        "description": "Options page label: 'auto-close the tab after the page is saved'"
+    },
     "optionsFileNameSubTitle": {
         "message": "Nom de fichier",
         "description": "Options sub-title: 'File name'"

+ 4 - 0
_locales/ja/messages.json

@@ -135,6 +135,10 @@
         "message": "infobar のコンテンツを編集するためのプロンプトダイアログを開く",
         "description": "オプションのページラベル: 'infobar のコンテンツを編集するためのプロンプトダイアログを開く'"
     },
+    "optionAutoCloseLabel": {
+        "message": "auto-close the tab after the page is saved",
+        "description": "Options page label: 'auto-close the tab after the page is saved'"
+    },
     "optionsFileNameSubTitle": {
         "message": "ファイル名",
         "description": "オプションのサブタイトル: 'ファイル名'"

+ 4 - 0
_locales/pl/messages.json

@@ -135,6 +135,10 @@
         "message": "otwieraj okno dialogowe z monitem, aby edytować zawartość paska informacyjnego",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
     },
+    "optionAutoCloseLabel": {
+        "message": "auto-close the tab after the page is saved",
+        "description": "Options page label: 'auto-close the tab after the page is saved'"
+    },
     "optionsFileNameSubTitle": {
         "message": "Nazwa pliku",
         "description": "Options sub-title: 'File name'"

+ 4 - 0
_locales/ru/messages.json

@@ -135,6 +135,10 @@
         "message": "открывать диалоговое окно для редактирования содержимого информационной панели",
         "description": "Options page label: 'open a prompt dialog to edit the infobar content'"
     },
+    "optionAutoCloseLabel": {
+        "message": "auto-close the tab after the page is saved",
+        "description": "Options page label: 'auto-close the tab after the page is saved'"
+    },
     "optionsFileNameSubTitle": {
         "message": "Имя файла",
         "description": "Options sub-title: 'File name'"

+ 4 - 0
_locales/zh_CN/messages.json

@@ -135,6 +135,10 @@
         "message": "打开一个提示窗口以编辑信息栏内容",
         "description": "选项页标签: '打开一个提示窗口以编辑信息栏内容'"
     },
+    "optionAutoCloseLabel": {
+        "message": "auto-close the tab after the page is saved",
+        "description": "Options page label: 'auto-close the tab after the page is saved'"
+    },
     "optionsFileNameSubTitle": {
         "message": "文件名",
         "description": "选项页副标题: '文件名'"

+ 4 - 0
_locales/zh_TW/messages.json

@@ -135,6 +135,10 @@
         "message": "打開一個提示窗口以編輯信息欄內容",
         "description": "選項頁標籤: '打開一個提示窗口以編輯信息欄內容'"
     },
+    "optionAutoCloseLabel": {
+        "message": "auto-close the tab after the page is saved",
+        "description": "Options page label: 'auto-close the tab after the page is saved'"
+    },
     "optionsFileNameSubTitle": {
         "message": "文件名",
         "description": "選項頁副標題: '文件名'"

+ 7 - 2
extension/core/bg/autosave.js

@@ -40,9 +40,14 @@ singlefile.extension.core.bg.autosave = (() => {
 			return { options, autoSaveEnabled };
 		}
 		if (message.method.endsWith(".save")) {
-			ui.onStart(sender.tab.id, 1, true);
+			const tabId = sender.tab.id;
+			const options = await singlefile.extension.core.bg.config.getOptions(sender.tab.url, true);
+			if (options.autoClose) {
+				singlefile.extension.core.bg.tabs.remove(tabId);
+			}
+			ui.onStart(tabId, 1, true);
 			await saveContent(message, sender.tab);
-			ui.onEnd(sender.tab.id, true);
+			ui.onEnd(tabId, true);
 			return {};
 		}
 	}

+ 1 - 0
extension/core/bg/config.js

@@ -47,6 +47,7 @@ singlefile.extension.core.bg.config = (() => {
 		infobarTemplate: "",
 		includeInfobar: false,
 		confirmInfobarContent: false,
+		autoClose: false,
 		confirmFilename: false,
 		filenameConflictAction: "uniquify",
 		filenameMaxLength: 192,

+ 6 - 0
extension/core/bg/downloads.js

@@ -82,6 +82,12 @@ singlefile.extension.core.bg.downloads = (() => {
 			}
 			return {};
 		}
+		if (message.method.endsWith(".end")) {
+			const options = await singlefile.extension.core.bg.config.getOptions(sender.tab.url, true);
+			if (options.autoClose) {
+				singlefile.extension.core.bg.tabs.remove(sender.tab.id);
+			}
+		}
 	}
 
 	async function downloadPage(pageData, options) {

+ 2 - 1
extension/core/bg/tabs.js

@@ -32,7 +32,8 @@ singlefile.extension.core.bg.tabs = (() => {
 		onMessage,
 		get: options => browser.tabs.query(options),
 		sendMessage: (tabId, message, options) => browser.tabs.sendMessage(tabId, message, options),
-		executeScript: (tabId, scriptData) => browser.tabs.executeScript(tabId, scriptData)
+		executeScript: (tabId, scriptData) => browser.tabs.executeScript(tabId, scriptData),
+		remove: tabId => browser.tabs.remove(tabId)
 	};
 
 	async function onMessage(message) {

+ 1 - 0
extension/core/content/content-main.js

@@ -229,6 +229,7 @@ this.singlefile.extension.core.content.main = this.singlefile.extension.core.con
 				downloadPageForeground(pageData, options);
 			}
 		}
+		await browser.runtime.sendMessage({ method: "downloads.end" });
 	}
 
 	function downloadPageForeground(pageData, options) {

+ 6 - 1
extension/ui/bg/ui-options.js

@@ -81,6 +81,7 @@
 	const showAutoSaveProfileLabel = document.getElementById("showAutoSaveProfileLabel");
 	const groupDuplicateImagesLabel = document.getElementById("groupDuplicateImagesLabel");
 	const confirmInfobarLabel = document.getElementById("confirmInfobarLabel");
+	const autoCloseLabel = document.getElementById("autoCloseLabel");
 	const infobarTemplateLabel = document.getElementById("infobarTemplateLabel");
 	const includeInfobarLabel = document.getElementById("includeInfobarLabel");
 	const miscLabel = document.getElementById("miscLabel");
@@ -130,6 +131,7 @@
 	const infobarTemplateInput = document.getElementById("infobarTemplateInput");
 	const includeInfobarInput = document.getElementById("includeInfobarInput");
 	const confirmInfobarInput = document.getElementById("confirmInfobarInput");
+	const autoCloseInput = document.getElementById("autoCloseInput");
 	const expandAllButton = document.getElementById("expandAllButton");
 	const rulesDeleteAllButton = document.getElementById("rulesDeleteAllButton");
 	const ruleUrlInput = document.getElementById("ruleUrlInput");
@@ -414,6 +416,7 @@
 	infobarTemplateLabel.textContent = browser.i18n.getMessage("optionInfobarTemplate");
 	includeInfobarLabel.textContent = browser.i18n.getMessage("optionIncludeInfobar");
 	confirmInfobarLabel.textContent = browser.i18n.getMessage("optionConfirmInfobar");
+	autoCloseLabel.textContent = browser.i18n.getMessage("optionAutoCloseLabel");
 	resetButton.textContent = browser.i18n.getMessage("optionsResetButton");
 	exportButton.textContent = browser.i18n.getMessage("optionsExportButton");
 	importButton.textContent = browser.i18n.getMessage("optionsImportButton");
@@ -586,6 +589,7 @@
 		infobarTemplateInput.value = profileOptions.infobarTemplate;
 		includeInfobarInput.checked = profileOptions.includeInfobar;
 		confirmInfobarInput.checked = profileOptions.confirmInfobarContent;
+		autoCloseInput.checked = profileOptions.autoClose;
 		removeFramesInput.disabled = saveRawPageInput.checked;
 		removeFramesInput.checked = removeFramesInput.checked || saveRawPageInput.checked;
 		loadDeferredImagesInput.disabled = saveRawPageInput.checked;
@@ -640,7 +644,8 @@
 				groupDuplicateImages: groupDuplicateImagesInput.checked,
 				infobarTemplate: infobarTemplateInput.value,
 				includeInfobar: includeInfobarInput.checked,
-				confirmInfobarContent: confirmInfobarInput.checked
+				confirmInfobarContent: confirmInfobarInput.checked,
+				autoClose: autoCloseInput.checked
 			}
 		});
 		await pendingSave;

+ 5 - 0
extension/ui/pages/help.html

@@ -128,6 +128,11 @@
 						<p>Check this option to display a prompt dialog in order to confirm the infobar content before
 							saving the page. </p>
 					</li>
+					<li data-options-label="autoCloseLabel"> <span class="option">Option: auto-close the tab after
+							the page is saved</span>
+						<p>Check this option to automatically close the tab after saving the page displayed inside.
+						</p>
+					</li>
 				</ul>
 				<p>File name</p>
 				<ul>

+ 4 - 0
extension/ui/pages/options.html

@@ -46,6 +46,10 @@
 				<label for="confirmInfobarInput" id="confirmInfobarLabel"></label>
 				<input type="checkbox" id="confirmInfobarInput">
 			</div>
+			<div class="option">
+				<label for="autoCloseInput" id="autoCloseLabel"></label>
+				<input type="checkbox" id="autoCloseInput">
+			</div>
 		</details>
 		<details>
 			<summary id="filenameLabel"></summary>

+ 9 - 0
lib/browser-polyfill/chrome-browser-polyfill.js

@@ -318,6 +318,15 @@
 							resolve(tab);
 						}
 					});
+				}),
+				remove: tabId => new Promise((resolve, reject) => {
+					nativeAPI.tabs.remove(tabId, () => {
+						if (nativeAPI.runtime.lastError) {
+							reject(nativeAPI.runtime.lastError);
+						} else {
+							resolve();
+						}
+					});
 				})
 			},
 			devtools: nativeAPI.devtools && {