diff --git a/src/content.ts b/src/content.ts index f0915273..465dc81b 100644 --- a/src/content.ts +++ b/src/content.ts @@ -392,6 +392,9 @@ function messageListener( }) ); break; + case "getPortVideo": + sendResponse(portVideo); + break; case "submitPortVideo": submitPortVideo(request.ytbID).then((response) => sendResponse(response)); break; @@ -1258,14 +1261,8 @@ async function updatePortVideoElements(newPortVideo: PortVideo) { waitFor(() => descriptionPill).then(() => descriptionPill.setPortVideoData(newPortVideo)); // notify popup of port video changes - chrome.runtime.sendMessage({ - message: "infoUpdated", - found: sponsorDataFound, - status: lastResponseStatus, - sponsorTimes: sponsorTimes, - portVideo: newPortVideo, - time: getVideo()?.currentTime ?? 0, - }); + console.log("send message to popup", { message: "portVideoUpdated", portVideo: newPortVideo }); + chrome.runtime.sendMessage({ message: "portVideoUpdated", portVideo: newPortVideo }); } async function getPortVideo(videoId: VideoID, bypassCache = false) { @@ -1409,7 +1406,6 @@ async function sponsorsLookup(keepOldSubmissions = true, ignoreServerCache = fal found: sponsorDataFound, status: lastResponseStatus, sponsorTimes: sponsorTimes, - portVideo: portVideo, time: getVideo()?.currentTime ?? 0, }); diff --git a/src/messageTypes.ts b/src/messageTypes.ts index 2a5f5d24..f81af60a 100644 --- a/src/messageTypes.ts +++ b/src/messageTypes.ts @@ -69,6 +69,10 @@ interface KeyDownMessage { metaKey: boolean; } +interface GetPortVideoMessage { + message: "getPortVideo"; +} + interface SubmitPortVideoMessage { message: "submitPortVideo"; ytbID: string; @@ -85,6 +89,7 @@ export type Message = BaseMessage & | CopyToClipboardMessage | ImportSegmentsMessage | KeyDownMessage + | GetPortVideoMessage | SubmitPortVideoMessage ); @@ -153,4 +158,9 @@ export interface VideoChangedPopupMessage { whitelisted: boolean; } -export type PopupMessage = TimeUpdateMessage | InfoUpdatedMessage | VideoChangedPopupMessage; +export interface PortVideoUpdateMessage { + message: "portVideoUpdated"; + portVideo: PortVideo; +} + +export type PopupMessage = TimeUpdateMessage | InfoUpdatedMessage | VideoChangedPopupMessage | PortVideoUpdateMessage; diff --git a/src/popup/PortVideoSection.tsx b/src/popup/PortVideoSection.tsx index dff1c72c..8bf2008d 100644 --- a/src/popup/PortVideoSection.tsx +++ b/src/popup/PortVideoSection.tsx @@ -20,10 +20,17 @@ export class PortVideoSection extends React.Component this.setState({ portVideo: portVideo as PortVideo })); } private inputRef = React.createRef(); + setPortVideo(portVideo: PortVideo): void { + this.setState({ portVideo }); + } + private hasPortVideo(): boolean { return !!this.state.portVideo; } diff --git a/src/popup/app.tsx b/src/popup/app.tsx index 3d320c7e..bdb01fa4 100644 --- a/src/popup/app.tsx +++ b/src/popup/app.tsx @@ -214,6 +214,7 @@ function app() { } function onMessage(msg: PopupMessage) { + console.log("onMessage", msg); switch (msg.message) { case "time": updateCurrentTime(msg.time); @@ -221,6 +222,9 @@ function app() { case "infoUpdated": infoFound(msg); break; + case "portVideoUpdated": + portVideoRef.current.setPortVideo(msg.portVideo); + break; case "videoChanged": setCurrentVideoID(msg.videoID); updateUnsubmittedSegments(); @@ -256,7 +260,7 @@ function app() { )} - {!Config.config.cleanPopup && ( + {/* {!Config.config.cleanPopup && (

{chrome.i18n.getMessage("fullName")}

- )} + )} */}