mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-21 15:33:11 +01:00
feat: chrome extension
This commit is contained in:
parent
579bd424fc
commit
d91ee36192
2
.gitignore
vendored
2
.gitignore
vendored
@ -11,6 +11,8 @@ coverage
|
||||
# production
|
||||
build
|
||||
chrome-extension
|
||||
chrome-extension.pem
|
||||
chrome-extension.crx
|
||||
bruno.zip
|
||||
|
||||
# misc
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
BIN
packages/bruno-chrome-extension/assets/images/logo-128x128.png
Normal file
BIN
packages/bruno-chrome-extension/assets/images/logo-128x128.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
BIN
packages/bruno-chrome-extension/assets/images/logo-16x16.png
Normal file
BIN
packages/bruno-chrome-extension/assets/images/logo-16x16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 953 B |
BIN
packages/bruno-chrome-extension/assets/images/logo-19x19.png
Normal file
BIN
packages/bruno-chrome-extension/assets/images/logo-19x19.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
packages/bruno-chrome-extension/assets/images/logo-38x38.png
Normal file
BIN
packages/bruno-chrome-extension/assets/images/logo-38x38.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
BIN
packages/bruno-chrome-extension/assets/images/logo-48x48.png
Normal file
BIN
packages/bruno-chrome-extension/assets/images/logo-48x48.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.9 KiB |
54
packages/bruno-chrome-extension/js/background.js
Normal file
54
packages/bruno-chrome-extension/js/background.js
Normal 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 = {};
|
||||
}
|
||||
});
|
||||
})();
|
26
packages/bruno-chrome-extension/manifest.json
Normal file
26
packages/bruno-chrome-extension/manifest.json
Normal 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"
|
||||
]
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"name": "Bruno API Client",
|
||||
"short_name": "Bruno"
|
||||
}
|
@ -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
|
Loading…
Reference in New Issue
Block a user