Files
ubuntu-based-kiosk/kiosk-app/docview.html
Claude 4b85ae59fc Slideshow folders can mix Word documents in with images
A slideshow folder now plays .docx files alongside images: a one-page
document is shown whole (letterboxed like a photo); a longer one fills
the width and scrolls smoothly top to bottom during its docInterval
(new slideshow.json key, default 2x interval). Word's ~$ lock files are
skipped; changed documents (by mtime) are re-read on the minute refresh.

- kiosk-app/docx-render.js: the docx-preview rendering now shared by
  docview.html and slideshow.html. Each render gets its own class prefix
  and keeps its styles in its own container, so two documents crossfading
  can't restyle each other. "One page" is judged by content fitting the
  paper height, not section count - docx-preview only starts a new
  section at explicit page breaks, so a long unbroken document is one
  tall section.
- Document bytes are fetched on demand: the page sets its title to a
  request, slideshow.js answers via executeJavaScript - only for a .docx
  in that slideshow's own current listing (no file-read API exposed to
  pages; the preload is shared by every site).

Tested with the real main.js on Electron 44.5.1 under Xvfb + Openbox on a
folder of 2 images + a 1-page and a long .docx (+ a ~$ lock file): order,
crossfades, whole-page fit, scroll to the end, lock file skipped; the
single-.docx site still renders. The request handler answered a listed
.docx and refused /etc/passwd, a listed image, and a .docx outside the
folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cjz8a58eB5P9sUweqd3NHm
2026-10-03 15:07:24 +00:00

59 lines
1.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Document</title>
<!-- Shown for a site that's a local .docx file - see docview.js. The
document's bytes arrive from main.js via window.kioskDocView.show(). -->
<style>
html, body { margin: 0; background: #666; }
#msg {
position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
color: #eee; font: 22px sans-serif; text-align: center; padding: 2em; box-sizing: border-box;
}
</style>
<script src="node_modules/jszip/dist/jszip.min.js"></script>
<script src="node_modules/docx-preview/dist/docx-preview.min.js"></script>
<script src="docx-render.js"></script>
</head>
<body>
<div id="msg">Loading document…</div>
<div id="doc"></div>
<script>
(() => {
const docEl = document.getElementById('doc');
const msg = document.getElementById('msg');
let cls = null;
function showMessage(text) {
msg.textContent = text;
msg.style.display = 'flex';
docEl.innerHTML = '';
}
window.addEventListener('resize', () => cls && KioskDocx.fit(docEl, cls, window.innerWidth));
window.kioskDocView = {
async show(d) {
if (d.error) { showMessage(d.error); return; }
if (!window.KioskDocx || !KioskDocx.available()) {
showMessage('Word document viewer is missing (docx-preview) - run Advanced -> Upgrade.');
return;
}
try {
cls = await KioskDocx.render(KioskDocx.base64ToBytes(d.data), docEl);
msg.style.display = 'none';
KioskDocx.fit(docEl, cls, window.innerWidth);
// Only called on first load or when the file changed on disk -
// start a changed document from the top.
window.scrollTo(0, 0);
} catch (e) {
showMessage(`Couldn't show ${d.file}: ${e.message || e}`);
}
},
};
})();
</script>
</body>
</html>