Skip to content

Commit

Permalink
TBX-13272: fix duplicate elements in Firefox
Browse files Browse the repository at this point in the history
Drop the enterprise support for now as it was broken anyway
  • Loading branch information
maximmig committed Dec 1, 2024
1 parent 3fc4a19 commit fe8d8c3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 272 deletions.
228 changes: 0 additions & 228 deletions api/menu.js

This file was deleted.

22 changes: 4 additions & 18 deletions api/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ const saveToStorage = async (key, value) => {
try {
await chrome.storage.local.set({ [key]: value });
} catch (e) {
console.error(
"Failed to save %s: %s to storage: %s",
key,
value,
e.message,
);
console.error("Failed to save %s: %s to storage: %s", key, value, e.message);
}
};

Expand All @@ -35,20 +30,11 @@ const getFromStorage = async (key, defaultValue) => {
}
};

export const getProtocol = () =>
getFromStorage(STORAGE_ITEMS.PROTOCOL, DEFAULTS.PROTOCOL);
export const getProtocol = () => getFromStorage(STORAGE_ITEMS.PROTOCOL, DEFAULTS.PROTOCOL);

export const saveProtocol = (protocol) =>
saveToStorage(STORAGE_ITEMS.PROTOCOL, protocol);
export const saveProtocol = (protocol) => saveToStorage(STORAGE_ITEMS.PROTOCOL, protocol);

export const getModifyPages = () =>
getFromStorage(STORAGE_ITEMS.MODIFY_PAGES, DEFAULTS.MODIFY_PAGES);

export const saveModifyPages = (allow) =>
saveToStorage(STORAGE_ITEMS.MODIFY_PAGES, allow);

export const getActiveTabId = () =>
getFromStorage(STORAGE_ITEMS.ACTIVE_TAB_ID, DEFAULTS.ACTIVE_TAB_ID);

export const setActiveTabId = (tabId) =>
saveToStorage(STORAGE_ITEMS.ACTIVE_TAB_ID, tabId ?? DEFAULTS.ACTIVE_TAB_ID);
export const saveModifyPages = (allow) => saveToStorage(STORAGE_ITEMS.MODIFY_PAGES, allow);
21 changes: 5 additions & 16 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import {
getProtocol,
saveProtocol,
getModifyPages,
saveModifyPages,
} from "./api/storage.js";
import { createExtensionMenu } from "./api/menu.js";
import { getProtocol, saveProtocol, getModifyPages, saveModifyPages } from "./api/storage.js";

const handleInstalled = () => {
const manifest = chrome.runtime.getManifest();
const uninstallUrl = `https://www.jetbrains.com/toolbox-app/uninstall/extension/?version=${manifest.version}`;
chrome.runtime.setUninstallURL(uninstallUrl).catch((e) => {
console.error("Failed to set uninstall URL: %s", e.message);
});

createExtensionMenu();
void chrome.runtime.setUninstallURL(
`https://www.jetbrains.com/toolbox-app/uninstall/extension/?version=${manifest.version}`,
);
};

const handleMessage = (message, sender, sendResponse) => {
Expand All @@ -25,9 +16,7 @@ const handleMessage = (message, sender, sendResponse) => {
});

const { project, https, ssh } = message;
const url = encodeURI(
`popups/clone.html?project=${project}&https=${https}&ssh=${ssh}`,
);
const url = encodeURI(`popups/clone.html?project=${project}&https=${https}&ssh=${ssh}`);
chrome.action.setPopup({
tabId: sender.tab.id,
popup: chrome.runtime.getURL(url),
Expand Down
21 changes: 14 additions & 7 deletions detect-enterprise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ import toolboxifyBitbucket from "./bitbucket-server.js";
const nameMeta =
document.querySelector('meta[property="og:site_name"]') ||
document.querySelector('meta[name="application-name"]');

if (nameMeta) {
const siteName = nameMeta.content;
if (siteName.startsWith("GitHub")) {
toolboxifyGithub();
} else if (siteName.startsWith("GitLab")) {
toolboxifyGitlab();
} else if (siteName.startsWith("Bitbucket")) {
toolboxifyBitbucket();
switch (nameMeta.content) {
case "GitHub":
toolboxifyGithub();
break;
case "GitLab":
toolboxifyGitlab();
break;
case "Bitbucket":
toolboxifyBitbucket();
break;
case "Gitee":
// toolboxifyGitee();
break;
}
}
})();
5 changes: 2 additions & 3 deletions manifests/firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@
"https://github.com/*",
"https://gitlab.com/*",
"https://bitbucket.org/*",
"https://gitee.com/*",
"http://*/*",
"https://*/*"
"https://gitee.com/*"
],
"optional_host_permissions": ["http://*/*", "https://*/*"],
"browser_specific_settings": {
"gecko": {
"id": "{bf9e77ee-c405-4dd7-9bed-2f55e448d19a}"
Expand Down

0 comments on commit fe8d8c3

Please sign in to comment.