Skip to content

Commit 7ef4f11

Browse files
committed
fix: add disabled state icons
1 parent 5051bb4 commit 7ef4f11

9 files changed

Lines changed: 113 additions & 22 deletions

File tree

.changeset/kind-candies-doubt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"amgiflol": patch
3+
---
4+
5+
fix: sync action icon state disabled state

README.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,16 @@
1010

1111
**LOGO BY** - [b3an33](https://github.com/b3an33)
1212

13-
</div>
14-
1513
A browser extension that helps with design audit. Match web layouts with Figma designs through real-time element inspection, measurements, and visual overlays.
1614

17-
## Marketplace
18-
19-
### Supported Browsers
20-
21-
| Chromium | Firefox |
22-
| -------------------------------------- | ------------ |
23-
| Chrome, Edge, Brave, Vivaldi, Arc, Dia | Firefox, Zen |
15+
</div>
2416

25-
### Users
17+
## Marketplace
2618

27-
[![Chrome Web Store Users](https://img.shields.io/chrome-web-store/users/kpkpcekkflbmmmhjlnkbkfkdjfjnnonl?style=for-the-badge&logo=GoogleChrome&label=Chromium)](https://chromewebstore.google.com/detail/amgiflol/kpkpcekkflbmmmhjlnkbkfkdjfjnnonl) [![Mozilla Add-on Users](https://img.shields.io/amo/users/amgiflol?style=for-the-badge&logo=Firefox-Browser&label=Firefox)](https://addons.mozilla.org/en-US/firefox/addon/amgiflol/)
19+
| Flavour | Browsers | Web Store Links & Stats |
20+
| -------- | -------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
21+
| Chromium | Chrome, Edge, Brave, Vivaldi, Arc, Dia | [![Chrome Web Store Users](https://img.shields.io/chrome-web-store/users/kpkpcekkflbmmmhjlnkbkfkdjfjnnonl?style=for-the-badge&logo=GoogleChrome&label=Chromium)](https://chromewebstore.google.com/detail/amgiflol/kpkpcekkflbmmmhjlnkbkfkdjfjnnonl) |
22+
| Firefox | Firefox, Zen | [![Mozilla Add-on Users](https://img.shields.io/amo/users/amgiflol?style=for-the-badge&logo=Firefox-Browser&label=Firefox)](https://addons.mozilla.org/en-US/firefox/addon/amgiflol/) |
2823

2924
## Target Audience
3025

public/icons/icon-off-128.png

7.93 KB
Loading

public/icons/icon-off-16.png

694 Bytes
Loading

public/icons/icon-off-32.png

1.51 KB
Loading

public/icons/icon-off-48.png

2.44 KB
Loading

public/icons/icon-off-64.png

3.3 KB
Loading

src/assets/icon-off.png

258 KB
Loading

src/entrypoints/background.ts

Lines changed: 102 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1-
import IconOn from "@/assets/icon.png";
2-
import IconOff from "@/assets/icon.png";
1+
const IconOff = {
2+
16: "icons/icon-off-16.png",
3+
32: "icons/icon-off-32.png",
4+
48: "icons/icon-off-48.png",
5+
64: "icons/icon-off-64.png",
6+
128: "icons/icon-off-128.png",
7+
};
8+
9+
const IconOn = {
10+
16: "icons/16.png",
11+
32: "icons/32.png",
12+
48: "icons/48.png",
13+
128: "icons/128.png",
14+
};
315

416
export default defineBackground(() => {
517
browser.runtime.onMessage.addListener(async (event, sender) => {
@@ -12,19 +24,98 @@ export default defineBackground(() => {
1224
console.log(
1325
`Extension installed, reason: ${reason}, browser: ${import.meta.env.BROWSER}`,
1426
);
15-
iconActions();
1627
analytics.setEnabled(true);
28+
updateIconForActiveTab();
29+
});
30+
31+
browser.runtime.onStartup.addListener(async () => {
32+
console.log("Extension started");
33+
await updateIconForActiveTab();
34+
});
35+
36+
// Update icon when switching tabs
37+
browser.tabs.onActivated.addListener(async () => {
38+
updateIconForActiveTab();
39+
});
40+
41+
// Update icon when tab URL changes
42+
browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
43+
if (changeInfo.status === "complete" && tab.active) {
44+
updateIconForActiveTab();
45+
}
46+
});
47+
48+
// Listen for storage changes to update icon
49+
browser.storage.onChanged.addListener(async (changes, areaName) => {
50+
if (areaName === "local") {
51+
updateIconForActiveTab();
52+
}
1753
});
1854
});
1955

20-
function iconActions() {
21-
storage.watch<boolean>(
22-
"local:isExtensionEnabled",
23-
isEnabled =>
24-
browser.action.setIcon({
25-
path: isEnabled! ? IconOn : IconOff,
26-
}),
27-
);
56+
/**
57+
* Get the current active tab's domain
58+
*/
59+
async function getCurrentDomain(): Promise<string | null> {
60+
try {
61+
const [tab] = await browser.tabs.query({
62+
active: true,
63+
currentWindow: true,
64+
});
65+
66+
if (!tab.url) return null;
67+
68+
const url = new URL(tab.url);
69+
return url.host;
70+
} catch (error) {
71+
console.error("Failed to get current domain:", error);
72+
return null;
73+
}
74+
}
75+
76+
/**
77+
* Check if extension is active for a specific domain
78+
*/
79+
async function isDomainActive(domain: string): Promise<boolean> {
80+
try {
81+
const result = await browser.storage.local.get([domain]);
82+
return Boolean(result[domain]);
83+
} catch (error) {
84+
console.error("Failed to check domain state:", error);
85+
return true;
86+
}
87+
}
88+
89+
/**
90+
* Update extension icon based on current active tab's domain state
91+
*/
92+
async function updateIconForActiveTab() {
93+
try {
94+
const domain = await getCurrentDomain();
95+
96+
if (!domain) {
97+
// No valid domain, show disabled state
98+
await (browser.action ?? browser.browserAction).setIcon({
99+
path: IconOff,
100+
});
101+
console.log("No valid domain, icon set to disabled");
102+
return;
103+
}
104+
105+
const isActive = await isDomainActive(domain);
106+
107+
await (browser.action ?? browser.browserAction).setIcon({
108+
path: isActive ? IconOn : IconOff,
109+
});
110+
111+
console.log(
112+
`Icon updated for domain "${domain}": ${
113+
isActive ? "active" : "inactive"
114+
}`,
115+
);
116+
} catch (error: unknown) {
117+
console.error("Failed to update icon for active tab:", error);
118+
}
28119
}
29120

30121
async function captureHandler(tab: Browser.tabs.Tab) {

0 commit comments

Comments
 (0)