Skip to content

Commit 7ae1fae

Browse files
committed
feat: hold modifier key alt/option to measure distance b/w layers
1 parent 520165b commit 7ae1fae

17 files changed

Lines changed: 561 additions & 453 deletions

File tree

.changeset/wet-times-report.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+
feat: hold modifier key alt/option to measure distance b/w layers

src/app.d.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,32 +38,43 @@ declare global {
3838
attributes: Record<string, string>;
3939
}
4040

41+
interface TrackerTargetMetaData {
42+
bounds: DOMRect;
43+
domElement: HTMLElement;
44+
properties: ElementInfo;
45+
overlayStyles: string;
46+
distanceLines: Line[];
47+
}
48+
4149
interface TrackerState {
42-
boundingRect?: DOMRect;
43-
element?: HTMLElement;
44-
parentElement?: HTMLElement;
45-
elementInfo?: ElementInfo;
50+
hoveredAltTarget?: TrackerTargetMetaData;
51+
target?: TrackerTargetMetaData;
52+
parentOfTarget?: TrackerTargetMetaData;
4653
id: string;
4754
isLocked: boolean;
4855
isVisible: boolean;
49-
parentRect?: DOMRect;
50-
elementStyles?: string;
51-
parentStyles?: string;
5256
lines?: Lines[];
5357
}
5458

55-
interface MouseState {
56-
isPressed: boolean;
59+
interface KeyboardState {
5760
modifiers: {
5861
alt: boolean;
5962
ctrl: boolean;
63+
meta: boolean;
64+
primary: boolean;
65+
secondary: boolean;
6066
shift: boolean;
6167
};
68+
}
69+
70+
interface MouseState {
71+
isPressed: boolean;
6272
x: number;
6373
y: number;
6474
}
6575

6676
interface MetaDataStore {
77+
keyboard: KeyboardState;
6778
mouse: MouseState;
6879
scroll: {
6980
scrollX: number;
@@ -145,13 +156,17 @@ declare global {
145156
| "KEYDOWN"
146157
| "*";
147158

148-
type MessageRecipients = "popup" | "content" | "background" | "all";
159+
type MessageRecipients = Partial<{
160+
background: boolean;
161+
content: boolean;
162+
popup: boolean;
163+
}>;
149164

150165
interface Message<T = any> {
151166
type: MessageType;
152167
payload: T;
153168
timestamp: number;
154-
source: Omit<MessageRecipients, "all">;
169+
source: MessageRecipients;
155170
target?: MessageRecipients;
156171
}
157172

src/entrypoints/background.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export default defineBackground(() => {
1717
browser.runtime.onMessage.addListener(async (event, sender) => {
1818
if (event.type === "SCREENSHOT" && sender.tab) {
1919
captureHandler(sender.tab);
20+
} else if (event.type === "EXTENSION_TOGGLE") {
21+
const { domain, isActive } = event.payload;
22+
browser.storage?.local.set({
23+
[domain]: isActive,
24+
});
25+
setIcon(isActive);
2026
}
2127
});
2228

@@ -30,11 +36,11 @@ export default defineBackground(() => {
3036

3137
browser.runtime.onStartup.addListener(async () => {
3238
console.log("Extension started");
33-
await updateIconForActiveTab();
39+
updateIconForActiveTab();
3440
});
3541

3642
// Update icon when switching tabs
37-
browser.tabs.onActivated.addListener(async () => {
43+
browser.tabs.onActivated.addListener(async (_activeInfo) => {
3844
updateIconForActiveTab();
3945
});
4046

@@ -45,7 +51,7 @@ export default defineBackground(() => {
4551
}
4652
});
4753

48-
// Listen for storage changes to update icon
54+
// // Listen for storage changes to update icon
4955
browser.storage.onChanged.addListener(async (changes, areaName) => {
5056
if (areaName === "local") {
5157
updateIconForActiveTab();
@@ -56,14 +62,19 @@ export default defineBackground(() => {
5662
/**
5763
* Get the current active tab's domain
5864
*/
59-
async function getCurrentDomain(): Promise<string | null> {
65+
async function getCurrentDomain(tabId?: number): Promise<string | null> {
6066
try {
61-
const [tab] = await browser.tabs.query({
62-
active: true,
63-
currentWindow: true,
64-
});
67+
let tab: globalThis.Browser.tabs.Tab;
68+
if (tabId) {
69+
tab = await browser.tabs.get(tabId);
70+
} else {
71+
[tab] = await browser.tabs.query({
72+
active: true,
73+
currentWindow: true,
74+
});
75+
}
6576

66-
if (!tab.url) return null;
77+
if (!tab?.url) return null;
6778

6879
const url = new URL(tab.url);
6980
return url.host;
@@ -86,29 +97,31 @@ async function isDomainActive(domain: string): Promise<boolean> {
8697
}
8798
}
8899

100+
async function setIcon(isActive: boolean) {
101+
await (browser.action ?? browser.browserAction).setIcon({
102+
path: isActive ? IconOn : IconOff,
103+
});
104+
}
105+
89106
/**
90107
* Update extension icon based on current active tab's domain state
91108
*/
92-
async function updateIconForActiveTab() {
109+
async function updateIconForActiveTab(tabId?: number) {
93110
try {
94-
const domain = await getCurrentDomain();
111+
const domain = await getCurrentDomain(tabId);
95112

96113
if (!domain) {
97114
// No valid domain, show disabled state
98-
await (browser.action ?? browser.browserAction).setIcon({
99-
path: IconOff,
100-
});
115+
setIcon(false);
101116
console.log("No valid domain, icon set to disabled");
102117
return;
103118
}
104119

105120
const isActive = await isDomainActive(domain);
106121

107-
await (browser.action ?? browser.browserAction).setIcon({
108-
path: isActive ? IconOn : IconOff,
109-
});
122+
setIcon(isActive);
110123

111-
console.log(
124+
console.trace(
112125
`Icon updated for domain "${domain}": ${
113126
isActive ? "active" : "inactive"
114127
}`,

src/lib/Main.svelte

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
} from "@/lib/store/index.svelte";
88
import { Tooltip } from "bits-ui";
99
import SelectorManager from "./components/SelectorManager.svelte";
10+
// TODO: Enable Toaster when toast functionality is complete
11+
// import Toaster from "./components/Toaster.svelte";
1012
import DebugToolbar from "./modules/DebugToolbar/index.svelte";
1113
import EventsManager from "./modules/EventsManager/index.svelte";
1214
import SidePanel from "./modules/SidePanel/index.svelte";
@@ -42,6 +44,7 @@
4244
showMessages={true}
4345
/>
4446
<SidePanel />
47+
<!-- <Toaster /> -->
4548
<Toolbar />
4649
{/if}
4750
</Tooltip.Provider>

0 commit comments

Comments
 (0)