Skip to content

Commit

Permalink
Popup: Stop refresh animation when content script is not inserted
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Mar 9, 2024
1 parent 096a9bc commit cb773c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
11 changes: 5 additions & 6 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,12 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
case "refreshSegments":
// update video on refresh if videoID invalid
if (!getVideoID()) {
checkVideoIDChange().then(() => {
if (!getVideoID()) {
// if not on a video page, send a message to the popup to stop refresh animation
chrome.runtime.sendMessage({ message: "infoUpdated" });
}
});
checkVideoIDChange()
}

// if popup rescieves no response, or the videoID is invalid,
// it will assume the page is not a video page and stop the refresh animation
sendResponse({ hasVideo: getVideoID() != null });
// fetch segments
sponsorsLookup(false);

Expand Down
7 changes: 6 additions & 1 deletion src/messageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ export type MessageResponse =
| IsChannelWhitelistedResponse
| Record<string, never> // empty object response {}
| VoteResponse
| ImportSegmentsResponse;
| ImportSegmentsResponse
| RefreshSegmentsResponse;

export interface VoteResponse {
successType: number;
Expand All @@ -114,6 +115,10 @@ interface ImportSegmentsResponse {
importedSegments: SponsorTime[];
}

export interface RefreshSegmentsResponse {
hasVideo: boolean;
}

export interface TimeUpdateMessage {
message: "time";
time: number;
Expand Down
14 changes: 12 additions & 2 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Message,
MessageResponse,
PopupMessage,
RefreshSegmentsResponse,
SponsorStartResponse,
VoteResponse,
} from "./messageTypes";
Expand Down Expand Up @@ -936,9 +937,18 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
stopLoadingAnimation = AnimationUtils.applyLoadingAnimation(PageElements.refreshSegmentsButton, 0.3);
}

function refreshSegments() {
async function refreshSegments() {
startLoadingAnimation();
sendTabMessage({ message: 'refreshSegments' });
const response = await sendTabMessageAsync({ message: 'refreshSegments' }) as RefreshSegmentsResponse;
console.log(response)

if (response == null || !response.hasVideo) {
if (stopLoadingAnimation != null) {
stopLoadingAnimation();
stopLoadingAnimation = null;
}
displayNoVideo();
}
}

function skipSegment(actionType: ActionType, UUID: SegmentUUID, element?: HTMLElement): void {
Expand Down

0 comments on commit cb773c4

Please sign in to comment.