11import type { CommentEvent , CommentSpot } from '@/lib/enhancer'
22import { type DraftStats , statsFor } from '@/lib/enhancers/draft-stats'
3+ import { logger } from '@/lib/logger'
34import type { GetTableRowsResponse , ToBackgroundMessage } from '@/lib/messages'
5+
46import {
57 CLOSE_MESSAGE_PORT ,
68 isContentToBackgroundMessage ,
@@ -36,6 +38,7 @@ export interface CommentTableRow {
3638export const openSpots = new Map < string , CommentStorage > ( )
3739
3840export function handleCommentEvent ( message : CommentEvent , sender : any ) : boolean {
41+ logger . debug ( 'received comment event' , message )
3942 if (
4043 ( message . type === 'ENHANCED' || message . type === 'DESTROYED' ) &&
4144 sender . tab ?. id &&
@@ -68,6 +71,7 @@ export function handlePopupMessage(
6871 sendResponse : ( response : any ) => void ,
6972) : typeof CLOSE_MESSAGE_PORT | typeof KEEP_PORT_OPEN {
7073 if ( isGetOpenSpotsMessage ( message ) ) {
74+ logger . debug ( 'received open spots message' , message )
7175 const rows : CommentTableRow [ ] = Array . from ( openSpots . values ( ) ) . map ( ( storage ) => {
7276 const [ time , content ] = storage . drafts . at ( - 1 ) !
7377 const row : CommentTableRow = {
@@ -87,6 +91,7 @@ export function handlePopupMessage(
8791 sendResponse ( response )
8892 return KEEP_PORT_OPEN
8993 } else if ( isSwitchToTabMessage ( message ) ) {
94+ logger . debug ( 'received switch tab message' , message )
9095 browser . windows
9196 . update ( message . windowId , { focused : true } )
9297 . then ( ( ) => {
@@ -97,6 +102,7 @@ export function handlePopupMessage(
97102 } )
98103 return CLOSE_MESSAGE_PORT
99104 } else {
105+ logger . error ( 'received unknown message' , message )
100106 throw new Error ( `Unhandled popup message type: ${ message ?. type || 'unknown' } ` )
101107 }
102108}
0 commit comments