From cf248c225a240480281c016f3d4651c9c2cb3bf7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Feb 2017 18:12:22 +0530 Subject: [PATCH] Allow setting APP_UID in file dialog helper process --- setup/installer/windows/file_dialogs.cpp | 9 ++++++++- src/calibre/gui2/win_file_dialogs.py | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/setup/installer/windows/file_dialogs.cpp b/setup/installer/windows/file_dialogs.cpp index d93dc842ab..7d6975700b 100644 --- a/setup/installer/windows/file_dialogs.cpp +++ b/setup/installer/windows/file_dialogs.cpp @@ -259,7 +259,7 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine HWND parent = NULL; bool save_dialog = false, multiselect = false, confirm_overwrite = false, only_dirs = false, no_symlinks = false; unsigned short len = 0; - LPWSTR title = NULL, folder = NULL, filename = NULL, save_path = NULL, echo = NULL, pipename = NULL, default_extension = NULL; + LPWSTR title = NULL, folder = NULL, filename = NULL, save_path = NULL, echo = NULL, pipename = NULL, default_extension = NULL, app_uid = NULL; COMDLG_FILTERSPEC *file_types = NULL; UINT num_file_types = 0; HANDLE pipe = INVALID_HANDLE_VALUE; @@ -290,6 +290,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine else if CHECK_KEY("SECRET") { if(!read_bytes(SECRET_SIZE, secret)) return 1; } + else if CHECK_KEY("APP_UID") { READSTR(app_uid) } + else if CHECK_KEY("TITLE") { READSTR(title) } else if CHECK_KEY("FOLDER") { READSTR(folder) } @@ -329,6 +331,11 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine if (!write_bytes(pipe, SECRET_SIZE+1, secret)) return 1; return write_bytes(pipe, echo_sz, echo_buf) ? 0 : 1; } + if (app_uid != NULL) { + if (SetCurrentProcessExplicitAppUserModelID(app_uid) != S_OK) { + // do nothing since this is not critical + } + } set_dpi_aware(); return show_dialog(pipe, secret, parent, save_dialog, title, folder, filename, save_path, multiselect, confirm_overwrite, only_dirs, no_symlinks, file_types, num_file_types, default_extension); } diff --git a/src/calibre/gui2/win_file_dialogs.py b/src/calibre/gui2/win_file_dialogs.py index de87b4548d..206b43cabf 100644 --- a/src/calibre/gui2/win_file_dialogs.py +++ b/src/calibre/gui2/win_file_dialogs.py @@ -13,6 +13,12 @@ from PyQt5.Qt import pyqtSignal, QEventLoop, Qt is64bit = sys.maxsize > (1 << 32) base = sys.extensions_location if hasattr(sys, 'new_app_layout') else os.path.dirname(sys.executable) HELPER = os.path.join(base, 'calibre-file-dialog.exe') +current_app_uid = None + + +def set_app_uid(val=None): + global current_app_uid + current_app_uid = val def is_ok(): @@ -122,7 +128,7 @@ def select_initial_dir(q): def run_file_dialog( parent=None, title=None, initial_folder=None, filename=None, save_path=None, allow_multiple=False, only_dirs=False, confirm_overwrite=True, save_as=False, no_symlinks=False, - file_types=(), default_ext=None + file_types=(), default_ext=None, app_uid=None ): from calibre.gui2 import sanitize_env_vars secret = os.urandom(32).replace(b'\0', b' ') @@ -169,6 +175,9 @@ def run_file_dialog( data.append(serialize_file_types(file_types)) if default_ext: data.append(serialize_string('DEFAULT_EXTENSION', default_ext)) + app_uid = app_uid or current_app_uid + if app_uid: + data.append(serialize_string('APP_UID', app_uid)) loop = Loop() server = PipeServer(pipename) with sanitize_env_vars():