43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
# Capture a clean 1200x630 preview.png: fresh state, dusk theme, moderate snow,
|
|
# a little drift, one shake for motion.
|
|
import http.server, threading, functools, os
|
|
DIST = os.path.abspath('dist')
|
|
httpd = http.server.ThreadingHTTPServer(('127.0.0.1', 8767), functools.partial(http.server.SimpleHTTPRequestHandler, directory=DIST))
|
|
threading.Thread(target=httpd.serve_forever, daemon=True).start()
|
|
from playwright.sync_api import sync_playwright
|
|
with sync_playwright() as p:
|
|
b = p.chromium.launch(
|
|
executable_path='/home/hermeswebui/.hermes/home/.cache/ms-playwright/chromium-1234/chrome-linux64/chrome',
|
|
args=['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'])
|
|
pg = b.new_page(viewport={'width': 1200, 'height': 630})
|
|
pg.goto('http://127.0.0.1:8767/', wait_until='networkidle')
|
|
pg.evaluate("localStorage.clear()")
|
|
pg.reload(wait_until='networkidle')
|
|
pg.wait_for_timeout(500)
|
|
# Dusk theme, moderate snow.
|
|
pg.click('button[data-theme="dusk"]')
|
|
pg.locator('#density').fill('2')
|
|
pg.locator('#density').dispatch_event('input')
|
|
# Let snow fall and a drift form.
|
|
pg.wait_for_timeout(9000)
|
|
# One gentle shake so flakes are mid-air.
|
|
pg.click('#shake-btn')
|
|
pg.wait_for_timeout(2600)
|
|
# Fit the whole app into 630px height.
|
|
pg.evaluate("""() => {
|
|
const st = document.querySelector('#stage');
|
|
st.style.maxWidth = '360px';
|
|
st.style.margin = '0 auto';
|
|
window.dispatchEvent(new Event('resize'));
|
|
document.body.style.paddingTop = '0.1rem';
|
|
document.querySelector('header h1').style.marginTop = '0.1rem';
|
|
window.scrollTo(0, 0);
|
|
}""")
|
|
pg.wait_for_timeout(1500)
|
|
box = pg.locator('#globe').bounding_box()
|
|
print('canvas box:', box)
|
|
pg.screenshot(path='public/preview.png')
|
|
print('saved public/preview.png')
|
|
b.close()
|
|
httpd.shutdown()
|