Added the ability to bookmark the extension, along with some visual adjustments
This commit is contained in:
45
dist/firefox/background.js
vendored
45
dist/firefox/background.js
vendored
@@ -292,6 +292,9 @@ function createTimeEntries({ fetchJson, dates, getResourceUser, saveHeaders }) {
|
||||
/** Stable wire names. All payloads remain plain, serializable objects. */
|
||||
function createMessageTypes() {
|
||||
return Object.freeze({
|
||||
addShortcutBookmark: "opportunitiesExtension.addShortcutBookmark",
|
||||
getBookmarkFolders: "opportunitiesExtension.getBookmarkFolders",
|
||||
getShortcutBookmarkStatus: "opportunitiesExtension.getShortcutBookmarkStatus",
|
||||
loadOrganizationChart: "opportunitiesExtension.loadOrganizationChart",
|
||||
saveOrganizationChart: "opportunitiesExtension.saveOrganizationChart",
|
||||
requestWeekDetails: "opportunitiesExtension.requestWeekDetails",
|
||||
@@ -3137,10 +3140,52 @@ function registerBackgroundMessages({
|
||||
requestOpptyProducts,
|
||||
runtimeApi
|
||||
}) {
|
||||
const bookmarkPending = new Map();
|
||||
async function getBookmarkFolders() {
|
||||
const folders = [];
|
||||
function visit(nodes, ancestors = []) {
|
||||
for (const node of nodes) {
|
||||
if (node.url || node.unmodifiable) continue;
|
||||
const path = node.parentId ? [...ancestors, node.title] : ancestors;
|
||||
if (node.parentId) folders.push({ id: node.id, label: path.join(" / ") });
|
||||
visit(node.children || [], path);
|
||||
}
|
||||
}
|
||||
visit(await runtimeApi.bookmarks.getTree());
|
||||
return { ok: true, folders };
|
||||
}
|
||||
function addShortcutBookmark(parentId) {
|
||||
if (bookmarkPending.has(parentId)) return bookmarkPending.get(parentId);
|
||||
const pending = (async () => {
|
||||
const { folders } = await getBookmarkFolders();
|
||||
if (!folders.some(folder => folder.id === parentId)) throw new Error("Select an available bookmarks folder.");
|
||||
const url = "https://eeho.fa.us2.oraclecloud.com/hcmUI/faces/FuseWelcome#opportunities-extension";
|
||||
const existing = await runtimeApi.bookmarks.search({ url });
|
||||
if (existing.some(bookmark => bookmark.parentId === parentId)) return { ok: true, existing: true };
|
||||
await runtimeApi.bookmarks.create({ title: "Opportunities Extension", url, parentId });
|
||||
return { ok: true, existing: false };
|
||||
})().finally(() => { bookmarkPending.delete(parentId); });
|
||||
bookmarkPending.set(parentId, pending);
|
||||
return pending;
|
||||
}
|
||||
runtimeApi.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
if (!message || !message.type) {
|
||||
return false;
|
||||
}
|
||||
if (message.type === messageTypes.addShortcutBookmark) {
|
||||
addShortcutBookmark(message.parentId).then(sendResponse).catch(error => sendResponse({ ok: false, error: error.message }));
|
||||
return true;
|
||||
}
|
||||
if (message.type === messageTypes.getBookmarkFolders) {
|
||||
getBookmarkFolders().then(sendResponse).catch(error => sendResponse({ ok: false, error: error.message }));
|
||||
return true;
|
||||
}
|
||||
if (message.type === messageTypes.getShortcutBookmarkStatus) {
|
||||
runtimeApi.bookmarks.search({ url: "https://eeho.fa.us2.oraclecloud.com/hcmUI/faces/FuseWelcome#opportunities-extension" })
|
||||
.then(items => sendResponse({ ok: true, bookmarked: items.length > 0 }))
|
||||
.catch(error => sendResponse({ ok: false, error: error.message }));
|
||||
return true;
|
||||
}
|
||||
if ([messageTypes.loadOrganizationChart, messageTypes.saveOrganizationChart].includes(message.type)) {
|
||||
const operation = message.type === messageTypes.loadOrganizationChart ? loadOrganizationChart : saveOrganizationChart;
|
||||
operation(message).then(sendResponse).catch(error => sendResponse({ ok: false, error: error.message }));
|
||||
|
||||
Reference in New Issue
Block a user