Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/trmnlp/screenshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,13 @@ class Screenshot
})();
JS

# The preview frame has the device's CSS size, so the screen stays unscaled there.
LIVE_PREVIEW_SIZE_STYLE = '<style>.trmnl .screen { --pixel-ratio: 1 !important; }</style>'

def self.live_preview(html)
timeout = html.match?(MAPS_DOCUMENT_PATTERN) ? READINESS_TIMEOUT_WITH_MAPS_SECONDS : READINESS_TIMEOUT_SECONDS
html.sub('</head>', "#{LAYOUT_PASS_STYLE}<script>#{format(SETTLE_LIVE_PREVIEW, timeout)}</script></head>")
script = "<script>#{format(SETTLE_LIVE_PREVIEW, timeout)}</script>"
html.sub('</head>', "#{LIVE_PREVIEW_SIZE_STYLE}#{LAYOUT_PASS_STYLE}#{script}</head>")
end

def initialize(pool:, viewport_timeout: 5, fonts_timeout: FONTS_TIMEOUT_SECONDS)
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/trmnlp/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,9 @@ def in_browser(page)
expect(in_browser(page) { it.execute_script("return #{shown}") }).to eq(unscaled(page))
end

it 'shows the screen at the size of the device' do
it 'shows the screen at its CSS size, the size of the preview frame' do
width = 'return document.querySelector(".screen").getBoundingClientRect().width'
expect(in_browser(preview(table)) { it.execute_script(width) }).to eq(1872)
expect(in_browser(preview(table)) { it.execute_script(width) }).to eq(1040)
end
end

Expand Down
Loading