Skip to content

Commit

Permalink
shortcut and default action
Browse files Browse the repository at this point in the history
  • Loading branch information
dufoli committed Jul 15, 2024
1 parent d15d5e6 commit b0709e1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
14 changes: 14 additions & 0 deletions addon/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";
let sfHost = "";
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
// Perform cookie operations in the background page, because not all foreground pages have access to the cookie API.
// Firefox does not support incognito split mode, so we use sender.tab.cookieStoreId to select the right cookie store.
Expand All @@ -15,6 +16,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
chrome.cookies.get({url: request.url, name: "sid", storeId: sender.tab.cookieStoreId}, cookie => {
if (!cookie || currentDomain.endsWith(".mcas.ms")) { //Domain used by Microsoft Defender for Cloud Apps, where sid exists but cannot be read
sendResponse(currentDomain);
sfHost = currentDomain;
return;
}
const [orgId] = cookie.value.split("!");
Expand All @@ -25,6 +27,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
let sessionCookie = cookies.find(c => c.value.startsWith(orgId + "!"));
if (sessionCookie) {
sendResponse(sessionCookie.domain);
sfHost = sessionCookie.domain;
}
});
});
Expand All @@ -51,3 +54,14 @@ chrome.runtime.onInstalled.addListener(({reason}) => {
});
}
});
chrome.commands.onCommand.addListener((command) => {
//TODO home to open setup
chrome.tabs.create({
url: `chrome-extension://${chrome.i18n.getMessage("@@extension_id")}/${command}.html?host=${sfHost}`
});
});
chrome.action.onClicked.addListener(() => {
chrome.tabs.create({
url: `chrome-extension://${chrome.i18n.getMessage("@@extension_id")}/data-export.html?host=${sfHost}`
});
});
33 changes: 33 additions & 0 deletions addon/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,39 @@
"permissions": [
"cookies"
],
"action": {
"default_title": "Export data"
},
"commands": {
"apex-runner": {
"suggested_key": {
"default": "Ctrl+Shift+C",
"mac": "Command+Shift+C"
},
"description": "Run apex code"
},
"data-export": {
"suggested_key": {
"default": "Ctrl+Shift+E",
"mac": "Command+Shift+E"
},
"description": "Export data"
},
"data-import": {
"suggested_key": {
"default": "Ctrl+Shift+I",
"mac": "Command+Shift+I"
},
"description": "Import data"
},
"streaming": {
"suggested_key": {
"default": "Ctrl+Shift+T",
"mac": "Command+Shift+T"
},
"description": "Manage streaming"
}
},
"host_permissions": [
"https://*.salesforce.com/*",
"https://*.force.com/*",
Expand Down

0 comments on commit b0709e1

Please sign in to comment.