mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Allow setting APP_UID in file dialog helper process
This commit is contained in:
parent
ff3cc55f21
commit
cf248c225a
@ -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);
|
||||
}
|
||||
|
@ -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():
|
||||
|
Loading…
x
Reference in New Issue
Block a user