mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Probable workaround for mpv failing after a few days on macOS
Also fix the certifi bumper: it was supposed to repeat
This commit is contained in:
parent
1a444f30e9
commit
fa4fc3e15a
2 changed files with 22 additions and 4 deletions
|
@ -1382,7 +1382,14 @@ title="{}" {}>{}</button>""".format(
|
||||||
True,
|
True,
|
||||||
parent=self,
|
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:
|
def onRefreshTimer(self) -> None:
|
||||||
if self.state == "deckBrowser":
|
if self.state == "deckBrowser":
|
||||||
|
@ -1398,15 +1405,20 @@ title="{}" {}>{}</button>""".format(
|
||||||
if elap > minutes * 60:
|
if elap > minutes * 60:
|
||||||
self.maybe_auto_sync_media()
|
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,
|
# 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.
|
# and chokes when the file is later missing due to temp file cleaners.
|
||||||
# Work around the issue by accessing them once every 12 hours.
|
# Work around the issue by accessing them once every 12 hours.
|
||||||
import certifi
|
|
||||||
|
|
||||||
with open(certifi.where(), "rb") as f:
|
with open(certifi.where(), "rb") as f:
|
||||||
f.read()
|
f.read()
|
||||||
|
|
||||||
|
# Prevent the mpv socket from being removed
|
||||||
|
mpvManager.bump_socket_mtime()
|
||||||
|
|
||||||
# Backups
|
# Backups
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
|
@ -404,6 +404,12 @@ class MpvManager(MPV, SoundOrVideoPlayer):
|
||||||
self.default_argv += [f"--config-dir={base_path}"]
|
self.default_argv += [f"--config-dir={base_path}"]
|
||||||
super().__init__(window_id=None, debug=False)
|
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:
|
def on_init(self) -> None:
|
||||||
# if mpv dies and is restarted, tell Anki the
|
# if mpv dies and is restarted, tell Anki the
|
||||||
# current file is done
|
# current file is done
|
||||||
|
|
Loading…
Reference in a new issue