Repository navigation
fix(ui): a tool chosen with no document runs once the picked file opens - #1681
marcoarnulfo wants to merge 1 commit into
Conversation
Since storytold#1493 a live app opens files on a background worker, so the file is not open yet when open_then_run looks for it right after open_path, and the tool never ran. The command now travels with the pending open (and with a converted text or image file), as the password prompt already did.
|
A note on the red CI here, since it looks like this PR breaks Locally on 7437bde, |
|
Follow-up to my note above: #1764 by @LabDennis already makes the |
|
Closing: #1914 (thanks @skylartaylor) landed the same continuation, on the worker, conversion and inline paths, and goes further with the one-tab-per-file case. Nothing left here. |
What this changes
Since #1493, a running app opens files on the background worker.
open_then_run(a tool chosen with no document open, e.g. Export ▸ Text) still checked for the new tab right afteropen_path. By then the file hadn't opened yet, so it opened a frame or two later and the tool never ran.a_tool_chosen_with_no_document_asks_for_one_and_runs_on_ithas been red onmainsince then.The fix reuses
PendingOpen.then, which already carried the command through the password prompt.open_pathbecomesopen_path_then(path, None), andopen_then_runcallsopen_path_then(path, Some(command)):OpenRequest, andfinish_pending_openruns it once the document is committed. An encrypted file hands it to the password prompt, as before.ResultKind::Conversion, which droppedthen. It now runs the command once the converted PDF is open.run_inline, or before the first frame): the behaviour is unchanged. It runs straight after the open, or hands the command to the password prompt.I also checked the other
open_pathcallers that look atviews.len()straight afterwards.control.rsalready handles a pending open.reopen_last_filesruns before the first frame, so it is always inline. Reopen Closed Tab does have the same pattern, but it only decides whether to pop the history entry, so I left it alone (see below).How you verified it
Commands run on macOS (Apple silicon):
cargo test -p pdfcraft-ui-egui --test commands: 22 passed. The two tests below also pass on their own with--exact.cargo test -p pdfcraft-ui-egui --lib -- open, and-- tab_context password: green.cargo clippy -p pdfcraft-ui-egui --all-targets -- -D warnings: clean.cargo fmt --all -- --check: clean.Tests. The two tests now run frames until the open lands, with a limit of 200 frames × 10 ms, instead of a fixed 3–4 frames:
a_tool_chosen_with_no_document_asks_for_one_and_runs_on_itcovers a PDF on the worker, a text file on the worker (conversion) and a PDF inline. Each case checks that the Export dialog is up.the_open_recent_menu_lists_files_and_opens_onefailed on the Windows runner in Desktop: prepare large PDFs off the UI thread #1493's CI for the same timing reason.On
mainthe first test fails withand the tool runs on it: None. I reverted each part of the fix on its own, and each one turns the test red on its own case:then: Nonein the requestConversionarmexecuteAnything a reviewer should look at first
Reopen Closed Tab (
tab_context.rs) pops its history entry only whenviews.len()grew right afteropen_path. On the worker path the entry now stays until a later reopen finds the tab already open. Popping it whenever the open is merely scheduled would lose the entry if the read then fails, and the comment there asks to keep it until a tab actually opens. That needs a decision on its own, so it isn't in this PR.