Skip to content

Commit 4d84dbb

Browse files
committed
Set action *and* pageAction on Firefox.
Fixes #67
1 parent 105e6e4 commit 4d84dbb

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

src/background.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,24 @@ function reformatForNAT64(addr, doLookup=true) {
143143
return formatIPv6(packed128, /*with_dots=*/isNAT64);
144144
}
145145

146+
// Magic object that calls action and/or pageAction. We want an icon in the
147+
// address bar when possible (e.g. desktop Firefox) but have a fallback option
148+
// when browsers forget to implement pageAction (e.g. Firefox 142 for Android).
149+
const actions = new Proxy({}, {
150+
get(target, prop) {
151+
const apis = [chrome.action, chrome.pageAction].filter(Boolean);
152+
return (...args) => {
153+
for (const api of apis) {
154+
if (typeof api[prop] === 'function') {
155+
api[prop](...args);
156+
} else if (prop != 'show') { // action.show() shouldn't exist.
157+
throw new Error(`actions.${prop} is not a function`);
158+
}
159+
}
160+
};
161+
}
162+
});
163+
146164
class SaveableEntry {
147165
#prefix;
148166
#id;
@@ -420,13 +438,9 @@ class TabInfo extends SaveableEntry {
420438
if (has4) pattern += "4";
421439
if (has6) pattern += "6";
422440

423-
// Firefox might drop support for pageAction someday, but until then
424-
// let's keep the icon in the address bar.
425-
const action = chrome.pageAction || chrome.action;
426-
427441
// Don't waste time rewriting the same tooltip.
428442
if (this.lastTooltip != tooltip) {
429-
action.setTitle({
443+
actions.setTitle({
430444
"tabId": this.id(),
431445
"title": tooltip,
432446
});
@@ -440,7 +454,7 @@ class TabInfo extends SaveableEntry {
440454
if (color == "auto") {
441455
color = darkMode.value ? "lightfg" : "darkfg";
442456
}
443-
action.setIcon({
457+
actions.setIcon({
444458
"tabId": this.id(),
445459
"imageData": {
446460
"16": buildIcon(pattern, 16, color),
@@ -449,13 +463,11 @@ class TabInfo extends SaveableEntry {
449463
});
450464
// Send icon to the popup window (mobile only)
451465
popups.pushPattern(this.id(), pattern);
452-
action.setPopup({
466+
actions.setPopup({
453467
"tabId": this.id(),
454468
"popup": `popup.html#${this.id()}`,
455469
});
456-
if (action.show) {
457-
action.show(this.id()); // Firefox only
458-
}
470+
actions.show(this.id());
459471
this.lastPattern = pattern;
460472
this.save();
461473
}

src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "IPvFoo",
33
"manifest_version": 3,
4-
"version": "2.24",
4+
"version": "2.25",
55
"description": "Display the server IP address, with a realtime summary of IPv4, IPv6, and HTTPS information across all page elements.",
66
"homepage_url": "https://github.com/pmarks-net/ipvfoo",
77
"icons": {

src/manifest/chrome-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "IPvFoo",
33
"manifest_version": 3,
4-
"version": "2.24",
4+
"version": "2.25",
55
"description": "Display the server IP address, with a realtime summary of IPv4, IPv6, and HTTPS information across all page elements.",
66
"homepage_url": "https://github.com/pmarks-net/ipvfoo",
77
"icons": {

src/manifest/firefox-manifest.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "IPvFoo",
33
"manifest_version": 3,
4-
"version": "2.24",
4+
"version": "2.25",
55
"description": "Display the server IP address, with a realtime summary of IPv4, IPv6, and HTTPS information across all page elements.",
66
"homepage_url": "https://github.com/pmarks-net/ipvfoo",
77
"icons": {
@@ -20,6 +20,11 @@
2020
"strict_min_version": "120.0"
2121
}
2222
},
23+
"action": {
24+
"default_icon": {
25+
"16": "icon16_transparent.png"
26+
}
27+
},
2328
"page_action": {
2429
"default_icon": {
2530
"16": "icon16_transparent.png"

0 commit comments

Comments
 (0)