From fdf95531e089b952b288ffe65f4a63b130bd0dd4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 12 Jun 2023 13:50:26 +0530 Subject: [PATCH] macOS: Fix extra dock icons visible when doing a job using Qt WebEngine such as converting to PDF or searching in Get books. Fixes #2023395 [Multiple Dock Icons When Searching for Books](https://bugs.launchpad.net/calibre/+bug/2023395) Apparently a recent macOS update changed some behavior. Now we need to have LSBackgroundOnly=1 in the Info.plist for calibre-parallel otherwise when using Qt we get a dock icon for the process. Sigh. --- bypy/macos/__main__.py | 11 ++++++++++- src/calibre/utils/ipc/launch.py | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bypy/macos/__main__.py b/bypy/macos/__main__.py index 4ac6831aba..c3a8924d00 100644 --- a/bypy/macos/__main__.py +++ b/bypy/macos/__main__.py @@ -742,15 +742,24 @@ class Freeze: e = plist['CFBundleDocumentTypes'][0] e['CFBundleTypeExtensions'] = [x.lower() for x in formats] + def headless_plist(plist): + plist['CFBundleDisplayName'] = 'calibre worker process' + plist['CFBundleExecutable'] = 'calibre-parallel' + plist['CFBundleIdentifier'] = 'com.calibre-ebook.calibre-parallel' + plist['LSBackgroundOnly'] = '1' + plist.pop('CFBundleDocumentTypes') + self.create_app_clone('ebook-viewer.app', partial(specialise_plist, 'ebook-viewer', input_formats)) self.create_app_clone('ebook-edit.app', partial(specialise_plist, 'ebook-edit', edit_formats), base_dir=join(self.contents_dir, 'ebook-viewer.app', 'Contents')) + self.create_app_clone('headless.app', headless_plist, + base_dir=join(self.contents_dir, 'ebook-viewer.app', 'Contents', 'ebook-edit.app', 'Contents')) # We need to move the webengine resources into the deepest sub-app # because the sandbox gets set to the nearest enclosing app which # means that WebEngine will fail to access its resources when running # in the sub-apps unless they are present inside the sub app bundle # somewhere - base_dest = join(self.contents_dir, 'ebook-viewer.app', 'Contents', 'ebook-edit.app', 'Contents', 'SharedSupport') + base_dest = join(self.contents_dir, 'ebook-viewer.app', 'Contents', 'ebook-edit.app', 'Contents', 'headless.app', 'Contents', 'SharedSupport') os.mkdir(base_dest) base_src = os.path.realpath(join(self.frameworks_dir, 'QtWebEngineCore.framework/Resources')) items = [join(base_src, 'qtwebengine_locales')] + glob.glob(join(base_src, '*.pak')) + glob.glob(join(base_src, '*.dat')) diff --git a/src/calibre/utils/ipc/launch.py b/src/calibre/utils/ipc/launch.py index a48178f048..7fdf1889df 100644 --- a/src/calibre/utils/ipc/launch.py +++ b/src/calibre/utils/ipc/launch.py @@ -73,6 +73,9 @@ class Worker: @property def executable(self): + if ismacos and not hasattr(sys, 'running_from_setup'): + base = os.path.dirname(sys.executables_location) + return os.path.join(base, 'ebook-viewer.app/Contents/ebook-edit.app/Contents/headless.app/Contents/MacOS', self.exe_name) return exe_path(self.exe_name) @property