fix: reconcile reused identities and protect every native dispatch
This commit is contained in:
1 parent
cb11624b68
commit
d9a79b6535
8 files changed
+159
-13
No files matched your search
@@ -717,10 +717,22 @@ def _set_probe_field(hwnd, control_id, expected, root):
|
||||
def _probe_add_dialog(app, job, desktop, owned_pids, root, *, library=None):
|
||||
try:
|
||||
return _probe_add_dialog_impl(app, job, desktop, owned_pids, root, library=library)
|
||||
except Exception as error:
|
||||
if job.get('_native_add_pending') and str(error).startswith('NATIVE_ADD_FAILED:'):
|
||||
try:
|
||||
failure = json.loads((Path(root)/'native-add-output.json').read_text('utf-8')).get('failure', {})
|
||||
if failure.get('acknowledged') is True:
|
||||
job['_native_add_pending'] = False
|
||||
from .session_record import update_worker_state
|
||||
update_worker_state(job, 'POSTCALL')
|
||||
except (OSError, ValueError, AttributeError):
|
||||
pass
|
||||
raise
|
||||
finally:
|
||||
import gc
|
||||
gc.collect() # Release UIA wrappers before closing native child dialogs.
|
||||
_close_probe_dialogs(desktop, owned_pids)
|
||||
if not job.get('_native_add_pending'):
|
||||
_close_probe_dialogs(desktop, owned_pids)
|
||||
|
||||
|
||||
def _require_management_continuation(job, root):
|
||||
@@ -823,6 +835,9 @@ def _probe_add_dialog_impl(app, job, desktop, owned_pids, root, *, library=None)
|
||||
_write_json(root/'native-add-log-baseline.json', log_baseline)
|
||||
observed_failures = {}
|
||||
_require_add_supervisor(job, root)
|
||||
from .session_record import update_worker_state
|
||||
update_worker_state(job, 'NATIVE_CALL')
|
||||
job['_native_add_pending'] = True
|
||||
win32gui.PostMessage(ok, win32con.BM_CLICK, 0, 0)
|
||||
success = None
|
||||
while time.monotonic() < deadline:
|
||||
@@ -853,6 +868,8 @@ def _probe_add_dialog_impl(app, job, desktop, owned_pids, root, *, library=None)
|
||||
break
|
||||
if not success:
|
||||
raise TimeoutError('未取得原生新增成功消息;保留副本与私有桌面证据。')
|
||||
job['_native_add_pending'] = False
|
||||
update_worker_state(job, 'POSTCALL')
|
||||
|
||||
|
||||
def run_isolated_probe(source, root, name, *, mentor_home=None, replacement_source=None):
|
||||
@@ -1125,6 +1142,7 @@ def _catalog_com(job, root):
|
||||
if int(library.FlowType) != 1:
|
||||
raise RuntimeError('Native Add requires the DxDesigner Logical-Physical library flow.')
|
||||
_probe_add_dialog(app, job, desktop, owned_pids, root, library=library)
|
||||
update_worker_state(job, 'CLOSING')
|
||||
library.Close()
|
||||
library = None
|
||||
_require_management_continuation(job, root)
|
||||
@@ -1169,14 +1187,18 @@ def _catalog_com(job, root):
|
||||
result['detail'] = str(error)
|
||||
result['exception'] = _exception_details(error)
|
||||
finally:
|
||||
if library is not None:
|
||||
try: library.Close()
|
||||
if library is not None and not job.get('_native_add_pending'):
|
||||
try:
|
||||
update_worker_state(job, 'CLOSING')
|
||||
library.Close()
|
||||
except Exception as error:
|
||||
result['close_detail'] = str(error)
|
||||
result['close_exception'] = _exception_details(error)
|
||||
library = None
|
||||
if app is not None:
|
||||
try: app.Quit()
|
||||
if app is not None and not job.get('_native_add_pending'):
|
||||
try:
|
||||
update_worker_state(job, 'CLOSING')
|
||||
app.Quit()
|
||||
except Exception as error:
|
||||
result['quit_detail'] = str(error)
|
||||
result['quit_exception'] = _exception_details(error)
|
||||
|
||||
Reference in new issue
Block a user