stabilised a bit the replay by using the live page instead of the archive when not found

This commit is contained in:
Faraphel 2024-01-22 22:18:27 +01:00
parent 3d120dab2d
commit 0e7ddd4c53
6 changed files with 40 additions and 26 deletions

View file

@ -22,16 +22,25 @@ setup(
"build_exe": {
"include_msvcr": True,
"include_files": [
("./tools/", "./tools/"),
("./assets/", "./assets/"),
("./README.md", "./README.md"),
]
}
},
executables=[Executable(
executables=[
Executable(
"main.py",
base=base,
target_name=__appname__,
icon=__icon_ico__
)]
),
Executable(
"tools/web_replay/main.py",
base=base,
target_name="tools/web_replay/main",
icon=__icon_ico__
),
]
)

0
tools/__init__.py Normal file
View file

View file

View file

@ -1,10 +1,8 @@
import json
import sys
from datetime import datetime
from PyQt6.QtWidgets import QApplication, QFileDialog
from PyQt6.QtWidgets import QApplication
from tools.web_replay.ui import ReplayWindow
from ui import ReplayWindow
if __name__ == "__main__":

View file

@ -7,7 +7,7 @@ from PyQt6.QtGui import QKeyEvent, QMouseEvent
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QApplication, QLabel
from source.utils import compress
from tools.web_replay.ui import ReplayWebEngineView, ReplayNavigation
from . import ReplayWebEngineView, ReplayNavigation
class ReplayEngine(QWidget):
@ -186,6 +186,6 @@ class ReplayEngine(QWidget):
# prepare the timer to play the event at the corresponding time
self.timer.singleShot(
round((next_time - self.replay_time) / 1000),
round((next_time - self.replay_time) / 200),
self.next
)

View file

@ -1,4 +1,5 @@
from datetime import datetime
from typing import Optional
from PyQt6.QtCore import QObject, QEvent, QUrl
from PyQt6.QtWebEngineWidgets import QWebEngineView
@ -9,21 +10,25 @@ class ReplayWebEngineView(QWebEngineView):
super().__init__()
self.start_time = start_time
self._last_url: Optional[QUrl] = None
self.loadFinished.connect(self._initialize_proxy_event) # NOQA: connect exist
# event filter
def setUrl(self, url: QUrl) -> None:
def setUrl(self, url: QUrl, archive: bool = True) -> None:
if archive:
# get the archive.org link corresponding to that time
archive_time: str = self.start_time.strftime("%Y%m%d%H%M%S")
archive_url = f"https://web.archive.org/web/{archive_time}/{url.toString()}"
url = QUrl(f"https://web.archive.org/web/{archive_time}/{url.toString()}")
self._last_url = url
# call the super function with the archive url instead
super().setUrl(QUrl(archive_url))
super().setUrl(url)
# clean the archive header popup that will appear
self.loadFinished.connect(self._clean_archive_header) # NOQA: connect exist
self.loadFinished.connect(self._on_load_finished) # NOQA: connect exist
def eventFilter(self, obj: QObject, event: QEvent) -> bool:
match event.type():
@ -44,16 +49,18 @@ class ReplayWebEngineView(QWebEngineView):
# events
def _initialize_proxy_event(self, ok: bool):
# prevent the event from being enabled another time
self.loadFinished.disconnect(self._initialize_proxy_event) # NOQA: disconnect exist
def _initialize_proxy_event(self):
# make self.eventFilter intercept all focusProxy events
self.focusProxy().installEventFilter(self)
def _clean_archive_header(self, ok: bool):
def _on_load_finished(self, ok: bool):
# prevent the event from being enabled another time
self.loadFinished.disconnect(self._clean_archive_header) # NOQA: disconnect exist
self.loadFinished.disconnect(self._on_load_finished) # NOQA: disconnect exist
if ok:
# hide archive.org header to avoid mouse movement being shifted
self.page().runJavaScript("document.getElementById('wm-ipp-base').style.display = 'none';")
self._initialize_proxy_event()
else:
self.setUrl(self._last_url, archive=False)