Skip to content

Commit f3734c6

Browse files
committed
working at a basic level
1 parent 25b46a7 commit f3734c6

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

browser-extension/src/entrypoints/background.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,25 @@ export function handleCommentEvent(message: CommentEvent, sender: any): void {
4646
}
4747
}
4848

49-
export function handlePopupMessage(message: any, sender: any, sendResponse: (response: any) => void): void {
49+
export function handlePopupMessage(message: any, _sender: any, sendResponse: (response: any) => void): void {
5050
if (message.type === 'GET_OPEN_SPOTS') {
5151
const spots: CommentState[] = []
5252
for (const [, commentState] of openSpots) {
5353
spots.push(commentState)
5454
}
5555
sendResponse({ spots })
56+
} else if (message.type === 'SWITCH_TO_TAB') {
57+
browser.windows.update(message.windowId, { focused: true }).then(() => {
58+
return browser.tabs.update(message.tabId, { active: true })
59+
}).catch(error => {
60+
console.error('Error switching to tab:', error)
61+
})
5662
}
5763
}
5864

5965
export default defineBackground(() => {
6066
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
61-
if (message.type === 'GET_OPEN_SPOTS') {
67+
if (message.type === 'GET_OPEN_SPOTS' || message.type === 'SWITCH_TO_TAB') {
6268
handlePopupMessage(message, sender, sendResponse)
6369
return true
6470
} else {

browser-extension/src/entrypoints/popup/main.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import { logger } from '../../lib/logger'
55

66
// Test basic DOM access
77
try {
8-
const app = document.getElementById('app')
8+
const app = document.getElementById('app')!!
99
logger.debug('Found app element:', app)
10-
if (app) {
11-
app.innerHTML = '<div>Script is running...</div>'
12-
}
10+
app.innerHTML = '<div>Script is running...</div>'
1311
} catch (error) {
1412
logger.error('Error accessing DOM:', error)
1513
}
@@ -28,9 +26,14 @@ async function getOpenSpots(): Promise<CommentState[]> {
2826
}
2927
}
3028

31-
async function switchToTab(tabId: number, windowId: number): Promise<void> {
32-
await browser.windows.update(windowId, { focused: true })
33-
await browser.tabs.update(tabId, { active: true })
29+
function switchToTab(tabId: number, windowId: number): void {
30+
// Send message to background script to handle tab switching
31+
// This avoids the popup context being destroyed before completion
32+
browser.runtime.sendMessage({
33+
type: 'SWITCH_TO_TAB',
34+
tabId,
35+
windowId
36+
})
3437
window.close()
3538
}
3639

@@ -40,23 +43,18 @@ function createSpotElement(commentState: CommentState): HTMLElement {
4043

4144
logger.debug('Creating spot element for:', commentState.spot)
4245
const enhancer = enhancers.enhancerFor(commentState.spot)
43-
logger.debug('Found enhancer:', enhancer)
46+
if (!enhancer) {
47+
logger.error('No enhancer found for:', commentState.spot)
48+
logger.error('Only have enhancers for:', enhancers.byType)
49+
}
4450

4551
const title = document.createElement('div')
4652
title.className = 'spot-title'
47-
48-
if (enhancer) {
49-
title.textContent = enhancer.tableTitle(commentState.spot)
50-
} else {
51-
title.textContent = `${commentState.spot.type} (${commentState.spot.unique_key})`
52-
}
53-
53+
title.textContent = enhancer.tableTitle(commentState.spot)
5454
item.appendChild(title)
55-
5655
item.addEventListener('click', () => {
5756
switchToTab(commentState.tab.tabId, commentState.tab.windowId)
5857
})
59-
6058
return item
6159
}
6260

browser-extension/src/lib/enhancer.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,4 @@ export interface CommentEnhancer<Spot extends CommentSpot = CommentSpot> {
4343

4444
tableIcon(spot: Spot): string
4545
tableTitle(spot: Spot): string
46-
buildUrl(spot: Spot): string
4746
}

browser-extension/src/lib/registries.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export interface EnhancedTextarea<T extends CommentSpot = CommentSpot> {
1313
export class EnhancerRegistry {
1414
private enhancers = new Set<CommentEnhancer>()
1515
private preparedEnhancers = new Set<CommentEnhancer>()
16-
private byType = new Map<string, CommentEnhancer>()
16+
byType = new Map<string, CommentEnhancer>()
1717

1818
constructor() {
1919
// Register all available handlers
@@ -23,7 +23,7 @@ export class EnhancerRegistry {
2323

2424
private register<T extends CommentSpot>(enhancer: CommentEnhancer<T>): void {
2525
this.enhancers.add(enhancer)
26-
for (const spotType in enhancer.forSpotTypes()) {
26+
for (const spotType of enhancer.forSpotTypes()) {
2727
this.byType.set(spotType, enhancer)
2828
}
2929
}

browser-extension/wxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default defineConfig({
1111
128: '/icons/icon-128.png',
1212
},
1313
name: 'Gitcasso',
14-
permissions: ['activeTab'],
14+
permissions: ['activeTab', 'tabs'],
1515
version: '1.0.0',
1616
},
1717
modules: ['@wxt-dev/webextension-polyfill'],

0 commit comments

Comments
 (0)