Skip to content

Commit

Permalink
Fix refresh not stop when on no content.js page
Browse files Browse the repository at this point in the history
  • Loading branch information
hanydd committed Mar 9, 2024
1 parent 096a9bc commit 4fe1698
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ chrome.runtime.onMessage.addListener(function (request, sender, callback) {
case "time":
case "infoUpdated":
case "videoChanged":
case "refreshAck":
if (sender.tab) {
try {
popupPort[sender.tab.id]?.postMessage(request);
Expand Down
1 change: 1 addition & 0 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ function messageListener(request: Message, sender: unknown, sendResponse: (respo
openSubmissionMenu();
break;
case "refreshSegments":
chrome.runtime.sendMessage({ message: "refreshAck" });
// update video on refresh if videoID invalid
if (!getVideoID()) {
checkVideoIDChange().then(() => {
Expand Down
6 changes: 5 additions & 1 deletion src/messageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ export type InfoUpdatedMessage = IsInfoFoundMessageResponse & {
message: "infoUpdated";
}

export interface RefreshAckMessage {
message: "refreshAck";
}

export interface VideoChangedPopupMessage {
message: "videoChanged";
videoID: string;
whitelisted: boolean;
}

export type PopupMessage = TimeUpdateMessage | InfoUpdatedMessage | VideoChangedPopupMessage;
export type PopupMessage = TimeUpdateMessage | InfoUpdatedMessage | RefreshAckMessage | VideoChangedPopupMessage;
19 changes: 19 additions & 0 deletions src/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -936,8 +936,21 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
stopLoadingAnimation = AnimationUtils.applyLoadingAnimation(PageElements.refreshSegmentsButton, 0.3);
}

let stopAnimationTimer = null;
function refreshSegments() {
if (stopAnimationTimer != null) {
return;
}
startLoadingAnimation();
stopAnimationTimer = setTimeout(() => {
// if no content script sends back acknolwedgement, assume the page is not bilibili
if (stopLoadingAnimation != null) {
stopLoadingAnimation();
stopLoadingAnimation = null;
}
displayNoVideo();
stopAnimationTimer = null;
}, 100);
sendTabMessage({ message: 'refreshSegments' });
}

Expand Down Expand Up @@ -1088,6 +1101,12 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> {
case "time":
updateCurrentTime(msg.time);
break;
case "refreshAck":
if (stopAnimationTimer != null) {
clearTimeout(stopAnimationTimer);
stopAnimationTimer = null;
}
break;
case "infoUpdated":
infoFound(msg);
break;
Expand Down

0 comments on commit 4fe1698

Please sign in to comment.