Skip to content

Tray-gated HTML preview flow - #1455

Open
IdelsTak wants to merge 91 commits into
qzind:masterfrom
IdelsTak:issue-1357-pr1375-port
Open

Tray-gated HTML preview flow#1455
IdelsTak wants to merge 91 commits into
qzind:masterfrom
IdelsTak:issue-1357-pr1375-port

Conversation

@IdelsTak

@IdelsTak IdelsTak commented May 22, 2026

Copy link
Copy Markdown
Contributor

Changes made:

  1. Ported preview foundation classes used by PR Html preview feature #1375:
    • AbstractHtmlInstance
    • PreviewHtmlInstance
    • PreviewWindow
    • Ruler
  2. Added tray preference support for HTML preview:
    • New pref key: tray.preview (ArgValue.TRAY_PREVIEW)
    • Diagnostic menu toggle: Preview HTML Prints
  3. Integrated preview gating into HTML print path:
    • PrintHTML now calls WebApp.print(job, model, options)
    • WebApp now decides preview vs direct print based on tray prefs
  4. Added non-interactive fallback behavior:
    • If running in headless or Monocle, preview UI is skipped and print proceeds directly
  5. Enforced monocle/preview policy in tray UI:
    • Enabling preview disables Monocle
    • Enabling Monocle disables preview
    • Restart warning messaging retained for Monocle toggles
  6. Hardened icon handling used by preview window:
    • IconCache singleton access (getInstance())
    • Missing-icon guard to avoid preview init crash
  7. Removed redundant print indirection:
    • Deleted PrintHtmlInstance
    • Preview-accepted and direct paths call canonical WebApp.print(job, model)
  8. Experimental sample.html/asset-handling changes were made but then reverted on @tresf's request and are thus not part of this PR

IdelsTak added 7 commits May 21, 2026 17:23
- Read preview/monocle prefs from live `TrayManager` when available, with `PrefsSearch` fallback for non-tray contexts
- Treat Monocle as non-interactive for preview gating: when preview is enabled in headless/monocle mode, log and print directly.
- Keep direct print routed through `PrintHtmlInstance` for consistency with preview-accepted printing
- Harden `PreviewHtmlInstance` lifecycle to avoid hangs and race failures:
  - cancel cleanly when loaded content has no body,
  - guard delayed preview-height updates when preview window is not yet available,
  - treat preview init/launch runtime failures as cancel and always release latches,
  - preserve interrupt status in delayed helper thread.
- Replace reflection-based WebView peer-update in `AbstractHtmlInstance` with explicit JavaFX helper calls (`SceneHelper` + `NodeHelper`) for consistent resize behavior
Problem:
 - Browser uploads do not reliably provide trusted local file paths
 - HTML printed from path-less/plain payloads and couldn't resolve relative image assets

Solution:
 - Added websocket method `printers.pickHtmlFile`
 - Exposed JS API helper `qz.printers.pickHtmlFile()`
 - Wired Pixel-tab `Upload a file...` HTML flow to use native JavaFX file chooser and store selected path for print
- Updated dropped HTML print payload to use `format: 'html'` +  `flavor: 'file'` with the selected `file://` path
- Hardened `sample.html` drop-print payload handling for non-base64 values
1. When `Preview HTML Prints` is enabled:
   - Monocle preference is turned off (if enabled)
   - Monocle checkbox is unchecked and disabled
2. When Preview is disabled:
   - Monocle checkbox is re-enabled
3. When `Use Monocle for HTML` is enabled while Preview is on:
   - Preview preference is turned off
   - Preview checkbox is unchecked
   - A single consolidated warning is shown (policy + restart note)
- Remove redundant `PrintHtmlInstance` class and its duplicate print/raster logic
- Route preview-accepted HTML print directly to `WebApp.print(job, model)`
- Route non-preview HTML print directly to `WebApp.print(job, model)`
- Replace `Ruler` orientation boolean with `javafx.geometry.Orientation` for clearer code
- No behavior change intended, this is a readability change
setDimensions(contentWidth, contentHeight);
}

enum UNIT {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enum UNIT {
enum UNIT {
enum Unit {

May also be redundant with PrintOptions.Unit.

case MM:
setUnit(UNIT.MM);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PX is part of enum but never refernced here.

Comment thread src/qz/printer/action/html/Ruler.java Outdated
heightProperty().addListener(evt -> draw());
}

private boolean isVertical() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper can now be refactored out.

Comment thread src/qz/printer/action/html/Ruler.java Outdated

@Override
public double prefWidth(double height) {
if (isVertical()) return 20;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace with ternary.

Comment thread src/qz/printer/action/html/Ruler.java Outdated

@Override
public double prefHeight(double width) {
if (!isVertical()) return 20;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace with ternary like above.

protected CountDownLatch captureLatch;

//listens for a Succeeded state to activate image capture
protected ChangeListener<Worker.State> stateListener = (ov, oldState, newState) -> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is still redundant with WebApp.java.

@tresf

tresf commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

@IdelsTak thank you for rebasing this against ivy. I still find many redundancies between the main JavaFX classes. I've also left some other code comments. This requires some substantial work before merge.

@IdelsTak

IdelsTak commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @tresf...let me work on it

@IdelsTak thank you for rebasing this against ivy. I still find many redundancies between the main JavaFX classes. I've also left some other code comments. This requires some substantial work before merge.

@IdelsTak

IdelsTak commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Okay, so @tresf, I have done heavy removal of duplications across AbstractHtmlInstance and WebApp leaving AbstractHtmlInstance light and focused.

When I started out in the last round AbstractHtmlInstance would suffer from a major regression when I deduplicated it.

I, however, found out exactly today what was the cause. (It was the timing of its doUpdatePeer call which would lead to display of blank pages in preview)

With that identified, I was today able to gradually remove all the other related duplicate code.

In my smoke tests and auto tests I didn't find any new regressions and the required html preview features all work as expected.

@tresf

tresf commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Thanks. I will workshop the remaining items with @Vzor- at a future time as well as run comprehensive regression tests.

@IdelsTak

IdelsTak commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Awesome!

@tresf
tresf deleted the branch qzind:master July 29, 2026 17:52
@tresf tresf closed this Jul 29, 2026
@tresf tresf reopened this Jul 29, 2026
@tresf
tresf changed the base branch from ivy to master July 29, 2026 18:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants