Przeglądaj źródła

added feat.testing for APIs unavailable on Firefox mobile

Gildas 7 lat temu
rodzic
commit
6d5fc2614e
1 zmienionych plików z 40 dodań i 34 usunięć
  1. 40 34
      extension/ui/bg/ui.js

+ 40 - 34
extension/ui/bg/ui.js

@@ -37,17 +37,19 @@ singlefile.ui = (() => {
 	let badgeRefreshPending = [];
 
 	browser.runtime.onInstalled.addListener(refreshContextMenu);
-	browser.menus.onClicked.addListener((event, tab) => {
-		if (event.menuItemId == MENU_ID_SAVE_PAGE) {
-			processTab(tab);
-		}
-		if (event.menuItemId == MENU_ID_SAVE_SELECTED) {
-			processTab(tab, { selected: true });
-		}
-		if (event.menuItemId == MENU_ID_SAVE_FRAME) {
-			processTab(tab, { frameId: event.frameId });
-		}
-	});
+	if (browser.menus && browser.menus.onClicked) {
+		browser.menus.onClicked.addListener((event, tab) => {
+			if (event.menuItemId == MENU_ID_SAVE_PAGE) {
+				processTab(tab);
+			}
+			if (event.menuItemId == MENU_ID_SAVE_SELECTED) {
+				processTab(tab, { selected: true });
+			}
+			if (event.menuItemId == MENU_ID_SAVE_FRAME) {
+				processTab(tab, { frameId: event.frameId });
+			}
+		});
+	}
 	browser.browserAction.onClicked.addListener(async tab => {
 		if (isAllowedURL(tab.url)) {
 			const tabs = await browser.tabs.query({ currentWindow: true, highlighted: true });
@@ -83,25 +85,27 @@ singlefile.ui = (() => {
 
 	async function refreshContextMenu() {
 		const config = await singlefile.config.get();
-		if (config.contextMenuEnabled) {
-			await browser.menus.removeAll();
-			browser.menus.create({
-				id: MENU_ID_SAVE_PAGE,
-				contexts: ["page"],
-				title: "Save page with SingleFile"
-			});
-			browser.menus.create({
-				id: MENU_ID_SAVE_SELECTED,
-				contexts: ["selection"],
-				title: "Save selection"
-			});
-			browser.menus.create({
-				id: MENU_ID_SAVE_FRAME,
-				contexts: ["frame"],
-				title: "Save frame"
-			});
-		} else {
-			await browser.menus.removeAll();
+		if (browser.menus && browser.menus.removeAll && browser.menus.create) {
+			if (config.contextMenuEnabled) {
+				await browser.menus.removeAll();
+				browser.menus.create({
+					id: MENU_ID_SAVE_PAGE,
+					contexts: ["page"],
+					title: "Save page with SingleFile"
+				});
+				browser.menus.create({
+					id: MENU_ID_SAVE_SELECTED,
+					contexts: ["selection"],
+					title: "Save selection"
+				});
+				browser.menus.create({
+					id: MENU_ID_SAVE_FRAME,
+					contexts: ["frame"],
+					title: "Save frame"
+				});
+			} else {
+				await browser.menus.removeAll();
+			}
 		}
 	}
 
@@ -179,10 +183,12 @@ singlefile.ui = (() => {
 	}
 
 	function onTabActivated(tabId, isActive) {
-		if (isActive) {
-			browser.browserAction.enable(tabId);
-		} else {
-			browser.browserAction.disable(tabId);
+		if (browser.browserAction && browser.browserAction.enable && browser.browserAction.disable) {
+			if (isActive) {
+				browser.browserAction.enable(tabId);
+			} else {
+				browser.browserAction.disable(tabId);
+			}
 		}
 	}