Duplicated screen mode: /present shows the projector view with the admin in a drawer (Gérer); both modes offered on the links page and the share tab

This commit is contained in:
2026-11-17 20:41:02 +01:00
parent cc1c46da6b
commit 450d923e78
9 changed files with 83 additions and 3 deletions
+5 -2
View File
@@ -856,7 +856,8 @@ async def ws_voter(ws: WebSocket):
CSP = ("default-src 'self'; script-src 'self'; worker-src 'self' blob:; style-src 'self'; " CSP = ("default-src 'self'; script-src 'self'; worker-src 'self' blob:; style-src 'self'; "
"img-src 'self' data: blob:; media-src 'self' blob: mediastream:; connect-src 'self' ws: wss:; " "img-src 'self' data: blob:; media-src 'self' blob: mediastream:; connect-src 'self' ws: wss:; "
"frame-ancestors 'none'; base-uri 'none'; form-action 'self'; object-src 'none'") # same origin only: the duplicated-screen page shows the admin page in a side panel
"frame-ancestors 'self'; base-uri 'none'; form-action 'self'; object-src 'none'")
class SecurityHeaders: class SecurityHeaders:
@@ -875,7 +876,7 @@ class SecurityHeaders:
(b"content-security-policy", CSP.encode()), (b"content-security-policy", CSP.encode()),
(b"referrer-policy", b"no-referrer"), (b"referrer-policy", b"no-referrer"),
(b"x-content-type-options", b"nosniff"), (b"x-content-type-options", b"nosniff"),
(b"x-frame-options", b"DENY"), (b"x-frame-options", b"SAMEORIGIN"),
(b"permissions-policy", b"camera=(self), microphone=(), geolocation=()"), (b"permissions-policy", b"camera=(self), microphone=(), geolocation=()"),
] ]
if not path.startswith("/static/vendor/"): if not path.startswith("/static/vendor/"):
@@ -911,6 +912,8 @@ routes = [
Route("/", page("index.html")), Route("/", page("index.html")),
Route("/admin/{pid}", page("admin.html")), Route("/admin/{pid}", page("admin.html")),
Route("/screen/{pid}", page("screen.html")), Route("/screen/{pid}", page("screen.html")),
# duplicated screen: the projector view with the admin in a drawer, opened with the admin key
Route("/present/{pid}", page("screen.html")),
Route("/essai", page("essai.html")), Route("/essai", page("essai.html")),
Route("/v/{pid}", page("vote.html")), Route("/v/{pid}", page("vote.html")),
Route("/V/{pid}", lambda r: RedirectResponse(f"/v/{r.path_params['pid'].lower()}", status_code=301)), Route("/V/{pid}", lambda r: RedirectResponse(f"/v/{r.path_params['pid'].lower()}", status_code=301)),
+4
View File
@@ -116,6 +116,10 @@
<div><b>Lien projecteur</b><span class="muted">Révoque le précédent</span></div> <div><b>Lien projecteur</b><span class="muted">Révoque le précédent</span></div>
<button id="screen-rotate" class="small" type="button">Nouveau lien</button> <button id="screen-rotate" class="small" type="button">Nouveau lien</button>
</div> </div>
<div class="share-row">
<div><b>Écran dupliqué</b><span class="muted">Projection et gestion sur le même écran</span></div>
<a id="open-present" class="btn small" href="#" target="_blank" rel="noopener">Ouvrir</a>
</div>
<div class="share-row"> <div class="share-row">
<div><b>Résultats</b><span class="muted">Bulletins anonymes et décomptes</span></div> <div><b>Résultats</b><span class="muted">Bulletins anonymes et décomptes</span></div>
<button id="export" class="small" type="button">Exporter</button> <button id="export" class="small" type="button">Exporter</button>
+2
View File
@@ -184,3 +184,5 @@ details.advanced { margin-top: 14px; }
details.advanced summary { font-size: .82rem; color: var(--ink-3); cursor: pointer; width: fit-content; padding: 4px 0; } details.advanced summary { font-size: .82rem; color: var(--ink-3); cursor: pointer; width: fit-content; padding: 4px 0; }
details.advanced summary:hover { color: var(--ink-2); } details.advanced summary:hover { color: var(--ink-2); }
details.advanced[open] summary { color: var(--ink-2); } details.advanced[open] summary { color: var(--ink-2); }
.mode-title { font-size: 1.05rem; margin: 22px 0 2px; }
.mode-title + .hint { margin: 0 0 8px; }
+13
View File
@@ -142,3 +142,16 @@ body.entry-q-on { --dock-qr: clamp(160px, min(46vh, 30vw), 520px); }
.s-main > section, .entry, #focus.enter *, #voters.bump { animation: none !important; } .s-main > section, .entry, #focus.enter *, #voters.bump { animation: none !important; }
.turnout .progress > div { transition: none; } .turnout .progress > div { transition: none; }
} }
/* duplicated screen: the admin slides in over the projection, the room sees it while it's open */
.ctl {
position: fixed; top: 0; right: 0; bottom: 0; z-index: 30; width: min(480px, 94vw); display: grid; grid-template-rows: auto 1fr;
background: var(--bg); box-shadow: -12px 0 40px rgba(28, 32, 54, .18); translate: 105% 0; transition: translate .35s cubic-bezier(.2, .7, .2, 1);
}
.ctl.open { translate: 0 0; }
.ctl-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; font: 700 1rem var(--round); }
.ctl iframe { width: 100%; height: 100%; border: 0; background: var(--bg); }
/* the manage button stays reachable in full screen, faint until hovered */
:fullscreen .s-tools .ctl-btn { display: inline-flex; opacity: .3; }
:fullscreen .s-tools .ctl-btn:hover, :fullscreen .s-tools .ctl-btn:focus-visible { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .ctl { transition: none; } }
+15
View File
@@ -75,6 +75,8 @@
<section id="done" class="card" hidden> <section id="done" class="card" hidden>
<h1>Scrutin créé</h1> <h1>Scrutin créé</h1>
<div class="notice warn">Conservez le lien d'administration : il ne pourra pas être récupéré.</div> <div class="notice warn">Conservez le lien d'administration : il ne pourra pas être récupéré.</div>
<h2 class="mode-title">Écran splitté</h2>
<p class="hint">L'administration sur votre écran, le projecteur sur l'écran étendu.</p>
<div class="duo stack"> <div class="duo stack">
<div class="pane"> <div class="pane">
<div class="pane-head"><svg class="icon" viewBox="0 0 24 24" width="26" height="26" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 5h16v11H4z"/><path d="M2 19.5h20"/><path d="M8 9h8"/><path d="M8 12.5h5"/></svg><p><b>Administration</b><span>Sur votre écran</span></p></div> <div class="pane-head"><svg class="icon" viewBox="0 0 24 24" width="26" height="26" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 5h16v11H4z"/><path d="M2 19.5h20"/><path d="M8 9h8"/><path d="M8 12.5h5"/></svg><p><b>Administration</b><span>Sur votre écran</span></p></div>
@@ -87,6 +89,19 @@
<a id="go-screen" class="btn block" href="#" target="_blank" rel="noopener">Ouvrir le projecteur</a> <a id="go-screen" class="btn block" href="#" target="_blank" rel="noopener">Ouvrir le projecteur</a>
</div> </div>
</div> </div>
<h2 class="mode-title">Écran dupliqué</h2>
<p class="hint">Un seul écran, recopié sur le projecteur. Le bouton « Gérer » ouvre l'administration par-dessus.</p>
<div class="duo stack">
<div class="pane">
<div class="pane-head"><svg class="icon" viewBox="0 0 24 24" width="26" height="26" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 5h16v11H4z"/><path d="M2 19.5h20"/><path d="M8 9h8"/><path d="M8 12.5h5"/></svg><p><b>Administration</b><span>Sur votre écran</span></p></div>
<div class="linkbox"><input id="admin-link" type="text" readonly aria-label="Lien d'administration"><button id="copy-admin" class="small" type="button">Copier</button></div>
<a id="go-admin" class="btn primary block" href="#" target="_blank" rel="noopener">Ouvrir l'administration</a>
</div>
<div class="pane">
<div class="pane-head"><svg class="icon" viewBox="0 0 24 24" width="26" height="26" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 4h20"/><path d="M4 4v10h16V4"/><path d="M12 14v3"/><path d="M8.5 21l3.5-4 3.5 4"/></svg><p><b>Écran unique</b><span>Projection et gestion au même endroit</span></p></div>
<a id="go-present" class="btn block" href="#" target="_blank" rel="noopener">Ouvrir l'écran dupliqué</a>
</div>
</div>
</section> </section>
</main> </main>
</body> </body>
+3
View File
@@ -321,3 +321,6 @@ liveSocket(`/ws/${pid}/admin`, {
c.textContent = "Reconnexion…"; c.textContent = "Reconnexion…";
}, },
}); });
// duplicated screen: the projector view with this admin in a drawer, same admin key
$("#open-present").href = `/present/${pid}#${encodeURIComponent(key)}`;
+1
View File
@@ -28,6 +28,7 @@ $("#form").addEventListener("submit", async (e) => {
$("#screen-link").value = screen; $("#screen-link").value = screen;
$("#go-admin").href = admin; $("#go-admin").href = admin;
$("#go-screen").href = screen; $("#go-screen").href = screen;
$("#go-present").href = `${location.origin}/present/${res.id}#${res.admin_key}`;
$("#create").hidden = true; $("#create").hidden = true;
$("#try-link").hidden = true; $("#try-link").hidden = true;
$("#done").hidden = false; $("#done").hidden = false;
+23 -1
View File
@@ -2,7 +2,9 @@ import { $, h, pollId, takeKey, liveSocket, drawQR, resultsView, pct } from "./c
import { render as drawRing, DISC } from "./ringcode.js"; import { render as drawRing, DISC } from "./ringcode.js";
const pid = pollId(); const pid = pollId();
const key = takeKey(`rv_screen_${pid}`); // /present/: duplicated screen, the laptop shows what the projector shows. admin key, admin in a drawer
const present = location.pathname.startsWith("/present/");
const key = takeKey(present ? `rv_present_${pid}` : `rv_screen_${pid}`);
let st = null; let st = null;
let qr = null; // current code message, qr or ring let qr = null; // current code message, qr or ring
let raf = 0; let raf = 0;
@@ -224,3 +226,23 @@ liveSocket(`/ws/${pid}/screen`, {
if (s !== "online") { qr = null; const cv = $("#qr"); cv.getContext("2d").clearRect(0, 0, cv.width, cv.height); } if (s !== "online") { qr = null; const cv = $("#qr"); cv.getContext("2d").clearRect(0, 0, cv.width, cv.height); }
}, },
}); });
if (present) {
const btn = h("button", { class: "small ctl-btn", type: "button", "aria-expanded": "false" }, "Gérer");
const close = h("button", { class: "small", type: "button" }, "Fermer");
const drawer = h("aside", { class: "ctl", "aria-label": "Gestion du scrutin" },
h("div", { class: "ctl-head" }, h("b", {}, "Gestion"), close));
document.body.append(drawer);
$(".s-tools").prepend(btn);
const toggle = (open) => {
// the admin page loads on first open only, and keeps its state when the drawer closes
if (open && !drawer.querySelector("iframe")) {
drawer.append(h("iframe", { src: `/admin/${pid}#${encodeURIComponent(key)}`, title: "Administration" }));
}
drawer.classList.toggle("open", open);
btn.setAttribute("aria-expanded", String(open));
};
btn.addEventListener("click", () => toggle(!drawer.classList.contains("open")));
close.addEventListener("click", () => toggle(false));
document.addEventListener("keydown", (e) => { if (e.key === "Escape") toggle(false); });
}
+17
View File
@@ -734,3 +734,20 @@ def test_hand_added_votes(server):
await a.aclose() await a.aclose()
asyncio.run(run()) asyncio.run(run())
def test_duplicated_screen_page(server):
p = create(server)
admin(server, p, "PATCH", "", json={"enrollment_open": True})
r = httpx.get(f"{server['base']}/present/{p['id']}", verify=server["verify"])
assert r.status_code == 200
# the admin page may only be framed by the site itself (duplicated screen drawer)
assert r.headers["x-frame-options"] == "SAMEORIGIN" and "frame-ancestors 'self'" in r.headers["content-security-policy"]
assert httpx.get(f"{server['base']}/present/nopenope", verify=server["verify"]).status_code == 404
async def run():
# the duplicated screen talks to the projector socket with the admin key
async with projector(server, p, key=p["admin_key"]) as next_token:
assert (await next_token()) is not None
asyncio.run(run())