diff --git a/qt/aqt/main.py b/qt/aqt/main.py index 579c75cf4..50919890a 100644 --- a/qt/aqt/main.py +++ b/qt/aqt/main.py @@ -1382,7 +1382,14 @@ title="{}" {}>{}""".format( True, parent=self, ) - self.progress.timer(12 * 60 * 1000, self.refresh_certs, False, parent=self) + if not is_win: + self.progress.timer( + 12 * 60 * 1000, + self.temp_file_workarounds, + repeat=True, + requiresCollection=False, + parent=self, + ) def onRefreshTimer(self) -> None: if self.state == "deckBrowser": @@ -1398,15 +1405,20 @@ title="{}" {}>{}""".format( if elap > minutes * 60: self.maybe_auto_sync_media() - def refresh_certs(self) -> None: + def temp_file_workarounds(self) -> None: + import certifi + + from aqt.sound import mpvManager + # The requests library copies the certs into a temporary folder on startup, # and chokes when the file is later missing due to temp file cleaners. # Work around the issue by accessing them once every 12 hours. - import certifi - with open(certifi.where(), "rb") as f: f.read() + # Prevent the mpv socket from being removed + mpvManager.bump_socket_mtime() + # Backups ########################################################################## diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index 5839d2dae..93a379360 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -404,6 +404,12 @@ class MpvManager(MPV, SoundOrVideoPlayer): self.default_argv += [f"--config-dir={base_path}"] super().__init__(window_id=None, debug=False) + def bump_socket_mtime(self) -> None: + "Update mtime on socket to prevent temp file cleaners from removing it." + path = Path(self._sock_filename) + if path.exists(): + os.utime(path, None) + def on_init(self) -> None: # if mpv dies and is restarted, tell Anki the # current file is done