Skip to content

Commit cae19ab

Browse files
committed
Activate extension on interaction
Folks might interact with controls while the extension is disabled, and wonder why none of their changes make any difference. So we turn on a turned-off extension upon interaction, so changes are always visible.
1 parent 7e80233 commit cae19ab

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/form.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
getFonts,
99
getFiles
1010
} from "./font";
11-
import { callTypeX, showReloadAnimation } from "./popup";
11+
import { callTypeX, showReloadAnimation, activateExtension } from "./popup";
1212
import { defaultFonts } from "./recursive-fonts.js";
1313

1414
const localFonts: Record<string, FontFile> = {};
@@ -194,9 +194,27 @@ export async function addFormElement(
194194
};
195195
});
196196

197+
// Auto-enable extension when interacting with font controls
198+
const fontDetails = el.querySelector(".font-details");
199+
if (fontDetails) {
200+
const formElements = fontDetails.querySelectorAll(
201+
"input, select, textarea"
202+
);
203+
formElements.forEach(element => {
204+
element.addEventListener("change", autoEnableExtension);
205+
});
206+
}
207+
197208
usedFonts.prepend(el);
198209
}
199210

211+
async function autoEnableExtension() {
212+
let { extensionActive } = await chrome.storage.local.get("extensionActive");
213+
if (!extensionActive) {
214+
await activateExtension(true);
215+
}
216+
}
217+
200218
async function changeFont(
201219
parent: HTMLFieldSetElement,
202220
newFontFileName: string

src/popup.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,19 @@ async function showStatus() {
8989
activateFonts.classList.toggle("active", !!extensionActive);
9090
}
9191

92-
// Toggle extension on/off using the button
93-
activateFonts.onclick = async () => {
92+
// Set extension state (on/off) or toggle it
93+
export async function activateExtension(setActive?: boolean) {
9494
let { extensionActive } = await chrome.storage.local.get("extensionActive");
95+
const active = setActive !== undefined ? setActive : !extensionActive;
9596
await chrome.storage.local.set({
96-
extensionActive: !extensionActive
97+
extensionActive: active
9798
});
9899
await callTypeX();
100+
}
101+
102+
// Toggle extension on/off using the button
103+
activateFonts.onclick = async () => {
104+
await activateExtension();
99105
};
100106

101107
export async function callTypeX() {

0 commit comments

Comments
 (0)