Skip to content

Commit

Permalink
Another speculative fix for missing overlay that actually seems to work
Browse files Browse the repository at this point in the history
  • Loading branch information
killergerbah committed Feb 25, 2024
1 parent d52774c commit f20a304
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
5 changes: 5 additions & 0 deletions extension/src/controllers/mobile-video-overlay-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ export class MobileVideoOverlayController {
this._show();
}

disposeOverlay() {
this._overlay.dispose();
this._overlay = MobileVideoOverlayController._elementOverlay(this._context.video, this._overlay.offsetAnchor);
}

private _show() {
if (!this._context.synced || this._forceHiding) {
return;
Expand Down
1 change: 1 addition & 0 deletions extension/src/services/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ export default class Binding {
if (this.subSyncAvailable) {
this.videoChangeListener = () => {
this.videoDataSyncController.requestSubtitles();
this.mobileVideoOverlayController.disposeOverlay();
};
this.video.addEventListener('loadedmetadata', this.videoChangeListener);
}
Expand Down
18 changes: 15 additions & 3 deletions extension/src/ui/hooks/use-mobile-video-overlay-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface Params {

export const useMobileVideoOverlayModel = ({ location }: Params) => {
const [model, setModel] = useState<MobileOverlayModel>();

useEffect(() => {
if (!location) {
return;
Expand All @@ -30,17 +31,25 @@ export const useMobileVideoOverlayModel = ({ location }: Params) => {
},
src: location.src,
};
const model = await chrome.tabs.sendMessage(location.tabId, command);
setModel(model);
const initialModel = await chrome.tabs.sendMessage(location.tabId, command);
setModel(initialModel);
};

let timeout: NodeJS.Timeout | undefined;
let cancelled = false;

const init = async () => {
try {
if (cancelled) {
return;
}

await requestModel();
} catch (e) {
console.log('Failed to request overlay model, retrying in 1s');
console.log(
'Failed to request overlay model, retrying in 1s. Message: ' +
(e instanceof Error ? e.message : String(e))
);
timeout = setTimeout(() => init(), 1000);
}
};
Expand All @@ -51,8 +60,11 @@ export const useMobileVideoOverlayModel = ({ location }: Params) => {
if (timeout !== undefined) {
clearTimeout(timeout);
}

cancelled = true;
};
}, [location]);

useEffect(() => {
if (!location) {
return;
Expand Down

0 comments on commit f20a304

Please sign in to comment.