Przeglądaj źródła

added constants and renamed the state "initialize" to "inject"

Gildas 6 lat temu
rodzic
commit
4c681d5621
2 zmienionych plików z 9 dodań i 6 usunięć
  1. 4 2
      extension/core/bg/business.js
  2. 5 4
      extension/ui/bg/ui-button.js

+ 4 - 2
extension/core/bg/business.js

@@ -71,6 +71,8 @@ singlefile.extension.core.bg.business = (() => {
 	const ERROR_CONNECTION_ERROR_CHROMIUM = "Could not establish connection. Receiving end does not exist.";
 	const ERROR_CONNECTION_LOST_CHROMIUM = "The message port closed before a response was received.";
 	const ERROR_CONNECTION_LOST_GECKO = "Message manager disconnected";
+	const INJECT_SCRIPTS_STEP = 1;
+	const EXECUTE_SCRIPTS_STEP = 2;
 
 	const pendingSaves = new Map();
 	const currentSaves = new Map();
@@ -95,7 +97,7 @@ singlefile.extension.core.bg.business = (() => {
 					await requestSaveTab(tabId, "content.autosave", tabOptions);
 				}
 			} else {
-				ui.onStart(tabId, 1);
+				ui.onStart(tabId, INJECT_SCRIPTS_STEP);
 				const tabOptions = await config.getOptions(tab.url);
 				Object.keys(options).forEach(key => tabOptions[key] = options[key]);
 				let scriptsInjected;
@@ -114,7 +116,7 @@ singlefile.extension.core.bg.business = (() => {
 					// ignored
 				}
 				if (scriptsInjected) {
-					ui.onStart(tabId, 2);
+					ui.onStart(tabId, EXECUTE_SCRIPTS_STEP);
 					if (tabOptions.frameId) {
 						await tabs.executeScript(tabId, { code: "document.documentElement.dataset.requestedFrameId = true", frameId: tabOptions.frameId, matchAboutBlank: true, runAt: "document_start" });
 					}

+ 5 - 4
extension/ui/bg/ui-button.js

@@ -44,6 +44,7 @@ singlefile.extension.ui.bg.button = (() => {
 	const ERROR_COLOR = [229, 4, 12, 192];
 	const AUTOSAVE_DEFAULT_COLOR = [208, 208, 208, 192];
 	const AUTOSAVE_INITIALIZING_COLOR = [64, 64, 64, 192];
+	const INJECT_SCRIPTS_STEP = 1;
 
 	const BUTTON_STATES = {
 		default: {
@@ -52,7 +53,7 @@ singlefile.extension.ui.bg.button = (() => {
 			setTitle: { title: BUTTON_DEFAULT_TOOLTIP_MESSAGE },
 			setIcon: { path: DEFAULT_ICON_PATH }
 		},
-		initialize: {
+		inject: {
 			setBadgeBackgroundColor: { color: DEFAULT_COLOR },
 			setBadgeText: { text: BUTTON_INITIALIZING_BADGE_MESSAGE },
 			setTitle: { title: BUTTON_INITIALIZING_TOOLTIP_MESSAGE },
@@ -84,7 +85,7 @@ singlefile.extension.ui.bg.button = (() => {
 			setIcon: { path: DEFAULT_ICON_PATH }
 		},
 		autosave: {
-			initialize: {
+			inject: {
 				setBadgeBackgroundColor: { color: AUTOSAVE_INITIALIZING_COLOR },
 				setBadgeText: { text: BUTTON_AUTOSAVE_ACTIVE_BADGE_MESSAGE },
 				setTitle: { title: BUTTON_AUTOSAVE_ACTIVE_TOOLTIP_MESSAGE },
@@ -147,9 +148,9 @@ singlefile.extension.ui.bg.button = (() => {
 	function onStart(tabId, step, autoSave) {
 		let state;
 		if (autoSave) {
-			state = getButtonState("initialize", true);
+			state = getButtonState("inject", true);
 		} else {
-			state = step == 1 ? getButtonState("initialize") : getButtonState("execute");
+			state = step == INJECT_SCRIPTS_STEP ? getButtonState("inject") : getButtonState("execute");
 			state.setTitle = { title: BUTTON_INITIALIZING_TOOLTIP_MESSAGE + " (" + step + "/2)" };
 			state.setIcon = { path: WAIT_ICON_PATH_PREFIX + "0.png" };
 		}