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

handle disabled profile

Gildas преди 1 година
родител
ревизия
c48aaef122
променени са 1 файла, в които са добавени 67 реда и са изтрити 47 реда
  1. 67 47
      src/core/bg/business.js

+ 67 - 47
src/core/bg/business.js

@@ -65,7 +65,12 @@ export {
 
 async function saveSelectedLinks(tab) {
 	const tabOptions = { extensionScriptFiles, tabId: tab.id, tabIndex: tab.index };
-	const scriptsInjected = await injectScript(tab.id, tabOptions);
+	let scriptsInjected;
+	try {
+		scriptsInjected = await injectScript(tab.id, tabOptions);
+	} catch (error) {
+		// ignored
+	}
 	if (scriptsInjected) {
 		const response = await browser.tabs.sendMessage(tab.id, { method: "content.getSelectedLinks" });
 		if (response.urls && response.urls.length) {
@@ -91,18 +96,20 @@ async function saveUrls(urls, options = {}) {
 	await initMaxParallelWorkers();
 	await Promise.all(urls.map(async url => {
 		const tabOptions = await config.getOptions(url);
-		Object.keys(options).forEach(key => tabOptions[key] = options[key]);
-		tabOptions.autoClose = true;
-		tabOptions.extensionScriptFiles = extensionScriptFiles;
-		if (tabOptions.passReferrerOnError) {
-			requests.enableReferrerOnError();
+		if (tabOptions.profileName != config.DISABLED_PROFILE_NAME) {
+			Object.keys(options).forEach(key => tabOptions[key] = options[key]);
+			tabOptions.autoClose = true;
+			tabOptions.extensionScriptFiles = extensionScriptFiles;
+			if (tabOptions.passReferrerOnError) {
+				requests.enableReferrerOnError();
+			}
+			addTask({
+				tab: { url },
+				status: TASK_PENDING_STATE,
+				options: tabOptions,
+				method: "content.save"
+			});
 		}
-		addTask({
-			tab: { url },
-			status: TASK_PENDING_STATE,
-			options: tabOptions,
-			method: "content.save"
-		});
 	}));
 	runTasks();
 }
@@ -112,43 +119,52 @@ async function saveTabs(tabs, options = {}) {
 	await Promise.all(tabs.map(async tab => {
 		const tabId = tab.id;
 		const tabOptions = await config.getOptions(tab.url);
-		Object.keys(options).forEach(key => tabOptions[key] = options[key]);
-		tabOptions.tabId = tabId;
-		tabOptions.tabIndex = tab.index;
-		tabOptions.extensionScriptFiles = extensionScriptFiles;
-		if (tabOptions.passReferrerOnError) {
-			requests.enableReferrerOnError();
-		}
-		const tabData = {
-			id: tab.id,
-			index: tab.index,
-			url: tab.url,
-			title: tab.title
-		};
-		if (options.autoSave) {
-			if (autoSaveIsEnabled(tab)) {
-				const taskInfo = addTask({
-					status: TASK_PROCESSING_STATE,
-					tab: tabData,
-					options: tabOptions,
-					method: "content.autosave"
-				});
-				runTask(taskInfo);
+		if (tabOptions.profileName != config.DISABLED_PROFILE_NAME) {
+			Object.keys(options).forEach(key => tabOptions[key] = options[key]);
+			tabOptions.tabId = tabId;
+			tabOptions.tabIndex = tab.index;
+			tabOptions.extensionScriptFiles = extensionScriptFiles;
+			if (tabOptions.passReferrerOnError) {
+				requests.enableReferrerOnError();
 			}
-		} else {
-			ui.onStart(tabId, INJECT_SCRIPTS_STEP);
-			const scriptsInjected = await injectScript(tabId, tabOptions);
-			if (scriptsInjected || editor.isEditor(tab)) {
-				ui.onStart(tabId, EXECUTE_SCRIPTS_STEP);
-				addTask({
-					status: TASK_PENDING_STATE,
-					tab: tabData,
-					options: tabOptions,
-					method: "content.save"
-				});
+			const tabData = {
+				id: tab.id,
+				index: tab.index,
+				url: tab.url,
+				title: tab.title
+			};
+			if (options.autoSave) {
+				if (autoSaveIsEnabled(tab)) {
+					const taskInfo = addTask({
+						status: TASK_PROCESSING_STATE,
+						tab: tabData,
+						options: tabOptions,
+						method: "content.autosave"
+					});
+					runTask(taskInfo);
+				}
 			} else {
-				ui.onForbiddenDomain(tab);
+				ui.onStart(tabId, INJECT_SCRIPTS_STEP);
+				let scriptsInjected;
+				try {
+					scriptsInjected = await injectScript(tabId, tabOptions);
+				} catch (error) {
+					// ignored
+				}
+				if (scriptsInjected || editor.isEditor(tab)) {
+					ui.onStart(tabId, EXECUTE_SCRIPTS_STEP);
+					addTask({
+						status: TASK_PENDING_STATE,
+						tab: tabData,
+						options: tabOptions,
+						method: "content.save"
+					});
+				} else {
+					ui.onForbiddenDomain(tab);
+				}
 			}
+		} else {
+			ui.onForbiddenDomain(tab);
 		}
 	}));
 	runTasks();
@@ -208,7 +224,11 @@ async function runTask(taskInfo) {
 			taskInfo.tab.id = taskInfo.options.tabId = tab.id;
 			taskInfo.tab.index = taskInfo.options.tabIndex = tab.index;
 			ui.onStart(taskInfo.tab.id, INJECT_SCRIPTS_STEP);
-			scriptsInjected = await injectScript(taskInfo.tab.id, taskInfo.options);
+			try {
+				scriptsInjected = await injectScript(taskInfo.tab.id, taskInfo.options);
+			} catch (error) {
+				// ignored
+			}
 		} catch (tabId) {
 			taskInfo.tab.id = tabId;
 		}