feat: chrome extension

This commit is contained in:
Anoop M D 2022-10-17 03:57:25 +05:30
parent 579bd424fc
commit d91ee36192
11 changed files with 89 additions and 10 deletions

2
.gitignore vendored
View File

@ -11,6 +11,8 @@ coverage
# production
build
chrome-extension
chrome-extension.pem
chrome-extension.crx
bruno.zip
# misc

View File

@ -14,7 +14,8 @@
},
"scripts": {
"dev:web": "npm run dev --workspace=packages/bruno-app",
"build:web": "npm run build --workspace=packages/bruno-app",
"dev:electron": "npm run dev --workspace=packages/bruno-electron",
"build-chrome-extension": "./scripts/create-chrome-extension.sh"
"build:chrome-extension": "./scripts/create-chrome-extension.sh"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 953 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@ -0,0 +1,54 @@
(function () {
let currentTab = {
id: null,
url: null,
};
const getExtensionId = () => {
const matches = chrome.runtime.getURL('x').match(/.*\/\/(.*)\/x$/);
if (matches) {
return matches[1];
}
return chrome.runtime.id;
};
// Create a new tab for the extension
function createNewTab() {
chrome.tabs.create({ url: 'index.html' }, function (tab) {
currentTab = {
id: tab.id,
url: tab.url
};
});
}
// Focus on the open extension tab
function focusTab(tabId) {
var updateProperties = { "active": true };
chrome.tabs.update(tabId, updateProperties, function (tab) { });
}
// Open the extension tab when the extension icon is clicked
chrome.browserAction.onClicked.addListener(function (tab) {
if (!currentTab || !currentTab.id) {
createNewTab();
} else {
chrome.tabs.get(currentTab.id, function (tab) {
console.log(chrome.runtime.id, tab.url);
if (tab && tab.url && tab.url.includes(getExtensionId())) {
focusTab(currentTab.id);
} else {
createNewTab();
}
});
}
});
// When a tab is closed, check if it is the extension tab that was closed, and unset currentTabId
chrome.tabs.onRemoved.addListener(function (tabId) {
if (tabId === currentTab.id) {
currentTab = {};
}
});
})();

View File

@ -0,0 +1,26 @@
{
"manifest_version": 2,
"version": "0.1.0",
"name": "Bruno API Client",
"short_name": "Bruno",
"description": "Opensource API Client",
"icons": {
"16": "assets/images/logo-16x16.png",
"48": "assets/images/logo-48x48.png",
"128": "assets/images/logo-128x128.png"
},
"background": {
"scripts": [
"js/background.js"
]
},
"browser_action": {
"default_icon": "assets/images/logo-128x128.png"
},
"permissions": [
"http://*/",
"https://*/",
"tabs",
"storage"
]
}

View File

@ -1,5 +0,0 @@
{
"manifest_version": 2,
"name": "Bruno API Client",
"short_name": "Bruno"
}

View File

@ -13,10 +13,11 @@ mkdir chrome-extension
cp -r packages/bruno-app/out/* chrome-extension
# Copy the chrome extension files
cp -r scripts/chrome-extension-files/* chrome-extension
cp -r packages/bruno-chrome-extension/* chrome-extension
# Filenames starting with "_" are reserved for use by the system
mv chrome-extension/_next chrome-extension/next
sed -i 's@/_next/@/next/@g' chrome-extension/**.html
# Remove sourcemaps
find chrome-extension -name '*.map' -type f -delete
# Compress the chrome-extension directory into a zip file
zip -r bruno.zip chrome-extension