macOS: When using the single instance option of the viewer, crashes should not require a restart of the computer to use the viewer again. See #1881375 (Viewer crash on macOS when advancing to next chapter)

This commit is contained in:
Kovid Goyal 2020-06-02 15:02:11 +05:30
parent 11d608bf47
commit 5afae4c1a4
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -12,13 +12,13 @@ from PyQt5.Qt import QIcon, QObject, Qt, QTimer, pyqtSignal
from PyQt5.QtWebEngineCore import QWebEngineUrlScheme from PyQt5.QtWebEngineCore import QWebEngineUrlScheme
from calibre import as_unicode, prints from calibre import as_unicode, prints
from calibre.constants import FAKE_PROTOCOL, VIEWER_APP_UID, islinux from calibre.constants import FAKE_PROTOCOL, VIEWER_APP_UID, islinux, iswindows
from calibre.gui2 import Application, error_dialog, setup_gui_option_parser from calibre.gui2 import Application, error_dialog, setup_gui_option_parser
from calibre.gui2.viewer.ui import EbookViewer, is_float from calibre.gui2.viewer.ui import EbookViewer, is_float
from calibre.gui2.viewer.web_view import get_session_pref, vprefs
from calibre.ptempfile import reset_base_dir from calibre.ptempfile import reset_base_dir
from calibre.utils.config import JSONConfig from calibre.utils.config import JSONConfig
from calibre.utils.ipc import RC, viewer_socket_address from calibre.utils.ipc import RC, viewer_socket_address
from calibre.gui2.viewer.web_view import vprefs, get_session_pref
singleinstance_name = 'calibre_viewer' singleinstance_name = 'calibre_viewer'
@ -111,10 +111,20 @@ def listen(listener, msg_from_anotherinstance):
def create_listener(): def create_listener():
addr = viewer_socket_address()
if islinux: if islinux:
from calibre.utils.ipc.server import LinuxListener as Listener from calibre.utils.ipc.server import LinuxListener as Listener
else: else:
from multiprocessing.connection import Listener from multiprocessing.connection import Listener
if not iswindows:
# On macOS (and BSDs, I am guessing), following a crash, the
# listener socket file sticks around and needs to be explicitly
# removed. It is safe to do this since we are already guaranteed to
# be the owner of the socket by singleinstance()
try:
os.remove(addr)
except Exception:
pass
return Listener(address=viewer_socket_address()) return Listener(address=viewer_socket_address())