Add resilient slide autoplay controls
Gitea/Deckstride/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-11-21 11:11:58 +01:00
parent 621d9d3d51
commit 56672964b3
12 changed files with 250 additions and 9 deletions

2
Cargo.lock generated
View File

@ -2245,7 +2245,7 @@ dependencies = [
[[package]]
name = "pdf-presenter"
version = "0.1.94"
version = "0.1.95"
dependencies = [
"bytemuck",
"chrono",

View File

@ -4,7 +4,7 @@ default-members = ["crates/pdf-presenter"]
resolver = "3"
[workspace.package]
version = "0.1.94"
version = "0.1.95"
edition = "2024"
license = "MIT"
repository = "https://proxy.dandaedre.com/gitea/idle-org/pdf-presenter"

View File

@ -289,6 +289,13 @@ fn fr(text: &str) -> &str {
"Menu" => "Menu",
"Displays" => "Écrans",
"All slides" => "Toutes les diapositives",
"Autoplay" => "Lecture automatique",
"Play automatically" => "Lire automatiquement",
"Timing" => "Durée",
"Loop" => "Boucler",
"Timing starts when the slide is visible." => {
"Le décompte commence lorsque la diapositive est visible."
}
"Layout" => "Disposition",
"Show slides" => "Afficher les diapositives",
"Blank slides" => "Masquer les diapositives",
@ -507,6 +514,11 @@ fn es(text: &str) -> &str {
"Menu" => "Menú",
"Displays" => "Pantallas",
"All slides" => "Todas las diapositivas",
"Autoplay" => "Reproducción automática",
"Play automatically" => "Reproducir automáticamente",
"Timing" => "Duración",
"Loop" => "Repetir",
"Timing starts when the slide is visible." => "El tiempo comienza cuando la diapositiva está visible.",
"Layout" => "Diseño",
"Layout…" => "Diseño…",
"Presenter layout" => "Diseño del presentador",
@ -658,6 +670,11 @@ fn ja(text: &str) -> &str {
"Menu" => "メニュー",
"Displays" => "ディスプレイ",
"All slides" => "すべてのスライド",
"Autoplay" => "自動再生",
"Play automatically" => "自動的に再生",
"Timing" => "表示時間",
"Loop" => "ループ",
"Timing starts when the slide is visible." => "スライドが表示されてから時間の計測を開始します。",
"Layout" => "レイアウト",
"Layout…" => "レイアウト…",
"Presenter layout" => "発表者レイアウト",
@ -800,6 +817,8 @@ fn zh_cn(text: &str) -> &str {
"Theme" => "主题", "Language" => "语言", "Appearance" => "外观",
"Preferences" => "首选项", "Preferences…" => "首选项…", "Quick settings" => "快速设置",
"Menu" => "菜单", "Displays" => "显示器", "All slides" => "所有幻灯片",
"Autoplay" => "自动播放", "Play automatically" => "自动播放幻灯片", "Timing" => "播放时长", "Loop" => "循环",
"Timing starts when the slide is visible." => "幻灯片显示后才开始计时。",
"Layout" => "布局", "Layout…" => "布局…", "Presenter layout" => "演讲者布局",
"Presenter" => "演讲者", "Slides" => "幻灯片", "Single screen" => "单屏模式", "Unused" => "未使用",
"Previous" => "上一张", "Current" => "当前", "Next" => "下一张",
@ -863,6 +882,8 @@ fn de(text: &str) -> &str {
"Theme" => "Design", "Language" => "Sprache", "Appearance" => "Darstellung",
"Preferences" => "Einstellungen", "Preferences…" => "Einstellungen…", "Quick settings" => "Schnelleinstellungen",
"Menu" => "Menü", "Displays" => "Bildschirme", "All slides" => "Alle Folien", "Layout" => "Layout",
"Autoplay" => "Automatische Wiedergabe", "Play automatically" => "Automatisch abspielen", "Timing" => "Anzeigedauer", "Loop" => "Wiederholen",
"Timing starts when the slide is visible." => "Die Zeitmessung beginnt, sobald die Folie sichtbar ist.",
"Layout…" => "Layout…", "Presenter layout" => "Präsentatorlayout", "Presenter" => "Präsentator",
"Slides" => "Folien", "Single screen" => "Einzelbildschirm", "Unused" => "Unbenutzt",
"Previous" => "Zurück", "Current" => "Aktuell", "Next" => "Weiter", "PREVIOUS" => "VORHERIGE",
@ -905,6 +926,8 @@ fn pt_br(text: &str) -> &str {
"Theme" => "Tema", "Language" => "Idioma", "Appearance" => "Aparência",
"Preferences" => "Preferências", "Preferences…" => "Preferências…", "Quick settings" => "Configurações rápidas",
"Menu" => "Menu", "Displays" => "Telas", "All slides" => "Todos os slides", "Layout" => "Layout",
"Autoplay" => "Reprodução automática", "Play automatically" => "Reproduzir automaticamente", "Timing" => "Duração", "Loop" => "Repetir",
"Timing starts when the slide is visible." => "A contagem começa quando o slide está visível.",
"Layout…" => "Layout…", "Presenter layout" => "Layout do apresentador", "Presenter" => "Apresentador",
"Slides" => "Slides", "Single screen" => "Tela única", "Unused" => "Não usada", "Previous" => "Anterior",
"Current" => "Atual", "Next" => "Próximo", "PREVIOUS" => "ANTERIOR", "CURRENT" => "ATUAL", "NEXT" => "PRÓXIMO",
@ -968,16 +991,17 @@ mod tests {
#[test]
fn catalogs_translate_core_presenter_controls_and_fall_back_to_english() {
let ctx = egui::Context::default();
for (language, expected) in [
(Language::Fr, "Écrans"),
(Language::Es, "Pantallas"),
(Language::Ja, "ディスプレイ"),
(Language::ZhCn, "显示器"),
(Language::De, "Bildschirme"),
(Language::PtBr, "Telas"),
for (language, expected, autoplay) in [
(Language::Fr, "Écrans", "Lecture automatique"),
(Language::Es, "Pantallas", "Reproducción automática"),
(Language::Ja, "ディスプレイ", "自動再生"),
(Language::ZhCn, "显示器", "自动播放"),
(Language::De, "Bildschirme", "Automatische Wiedergabe"),
(Language::PtBr, "Telas", "Reprodução automática"),
] {
apply(&ctx, &language);
assert_eq!(tr(&ctx, "Displays"), expected);
assert_eq!(tr(&ctx, "Autoplay"), autoplay);
assert_eq!(
tr(&ctx, "untranslated diagnostic"),
"untranslated diagnostic"

View File

@ -2632,6 +2632,35 @@ fn menu(ui: &mut Ui, s: &mut Studio, preferences_open: &mut bool) {
Action::OpenBrowser,
&mut s.actions,
);
ui.menu_button(tr(&locale, "Autoplay"), |ui| {
ui.set_min_width(250.);
let mut changed = ui
.checkbox(
&mut s.settings.autoplay_enabled,
tr(&locale, "Play automatically"),
)
.changed();
ui.horizontal(|ui| {
ui.label(tr(&locale, "Timing"));
changed |= ui
.add(
egui::DragValue::new(&mut s.settings.autoplay_seconds)
.range(0.25..=3600.0)
.speed(0.25)
.max_decimals(2)
.suffix(" s"),
)
.changed();
});
changed |= ui
.checkbox(&mut s.settings.autoplay_loop, tr(&locale, "Loop"))
.changed();
ui.small(tr(&locale, "Timing starts when the slide is visible."));
if changed {
s.autoplay_settings_changed();
ui.ctx().request_repaint();
}
});
ui.menu_button(tr(&locale, "Appearance"), |ui| {
ui.with_layout(egui::Layout::top_down(egui::Align::Min), |ui| {
ui.set_min_width(250.);

View File

@ -279,6 +279,9 @@ pub struct Settings {
pub buffer_mib: u32,
pub disk_cache: crate::cache::Policy,
pub auto_show: bool,
pub autoplay_enabled: bool,
pub autoplay_seconds: f32,
pub autoplay_loop: bool,
pub blank_picture: bool,
pub zoom_enabled: bool,
pub zoom_keep_fitted_area: bool,
@ -327,6 +330,9 @@ impl Default for Settings {
buffer_mib: default_buffer_mib(),
disk_cache: Default::default(),
auto_show: true,
autoplay_enabled: false,
autoplay_seconds: 5.0,
autoplay_loop: false,
blank_picture: false,
zoom_enabled: false,
zoom_keep_fitted_area: false,
@ -344,6 +350,9 @@ impl Settings {
if !(64..=16384).contains(&self.buffer_mib) {
return Err("RAM buffer must be 64–16384 MiB per process".into());
}
if !self.autoplay_seconds.is_finite() || !(0.25..=3600.0).contains(&self.autoplay_seconds) {
return Err("Autoplay timing must be 0.25–3600 seconds".into());
}
if self.projects.len() > 4096 || !(100. ..=400.).contains(&self.thumbnail_size) {
return Err("Invalid settings limits".into());
}

View File

@ -161,6 +161,8 @@ pub struct Studio {
pub cache_status: String,
startup_cache_pending: bool,
navigation_settle: Option<Instant>,
autoplay_deadline: Option<Instant>,
autoplay_finished: bool,
pub fg: Bridge,
pub bg: Bridge,
pub io: Bridge,
@ -281,6 +283,8 @@ impl Studio {
cache_status: String::new(),
startup_cache_pending: true,
navigation_settle: None,
autoplay_deadline: None,
autoplay_finished: false,
fg: Bridge::with_program(Duration::from_secs(30), worker_program.clone()),
bg: Bridge::with_program(Duration::from_secs(30), worker_program.clone()),
io,
@ -500,6 +504,63 @@ impl Studio {
pub fn presentation_action(&mut self) {
self.timer
.presentation_action(Instant::now(), self.layout.timer_autostart);
self.restart_autoplay();
}
fn restart_autoplay(&mut self) {
self.autoplay_deadline = None;
self.autoplay_finished = false;
}
pub fn autoplay_settings_changed(&mut self) {
self.restart_autoplay();
self.save_preferences();
}
fn poll_autoplay_at(&mut self, now: Instant) -> bool {
let paused = !self.settings.autoplay_enabled
|| !self.initialized
|| self.loading
|| self.pending_open.is_some()
|| self.blanked
|| self.dialog_busy
|| self.route_trial.is_some()
|| self.startup_single_offer()
|| self.notes_editor.is_some()
|| self.notes_import.is_some()
|| self.quit_confirmation
|| self.count() == 0;
if paused {
self.autoplay_deadline = None;
return false;
}
if self.autoplay_finished {
return false;
}
let visible = self.displayed == Some(self.requested)
|| (self.routes.presentation.is_empty() && self.frame(self.requested).is_some());
if !visible {
self.autoplay_deadline = None;
return false;
}
let deadline = self
.autoplay_deadline
.get_or_insert_with(|| now + Duration::from_secs_f32(self.settings.autoplay_seconds));
if now < *deadline {
return false;
}
let next = if self.requested + 1 < self.count() {
Some(self.requested + 1)
} else if self.settings.autoplay_loop && self.count() > 1 {
Some(0)
} else {
None
};
self.autoplay_deadline = None;
if let Some(next) = next {
self.execute(Action::Go(next));
true
} else {
self.autoplay_finished = true;
false
}
}
pub fn execute(&mut self, action: Action) {
match action {
@ -678,6 +739,7 @@ impl Studio {
return;
}
if page < self.count() {
self.restart_autoplay();
if page != self.requested
&& self.fg_busy
&& !self.loading
@ -1338,6 +1400,7 @@ impl Studio {
self.requested = 0;
self.presentation_started = false;
self.timer = crate::timer::Timer::default();
self.restart_autoplay();
self.displayed = None;
self.layout = self.settings.for_project(&info.key);
self.presenter_views.clear();
@ -1531,6 +1594,7 @@ impl Studio {
{
self.clean_cache(false);
}
self.poll_autoplay_at(Instant::now());
}
fn schedule(&mut self, page: usize, edge: u32, foreground: bool) {
// Reserve both worker slots before admission, including progressive previews.
@ -1835,6 +1899,57 @@ impl Studio {
mod tests {
use super::*;
#[test]
fn autoplay_times_visible_slides_pauses_and_loops_safely() {
let mut s = Studio::new(true, None);
s.initialized = true;
s.deck = Some(DeckInfo {
path: "test.pdf".into(),
key: "test".into(),
title: "Test".into(),
names: vec![String::new(); 3],
notes: vec![],
warnings: vec![],
sha256: String::new(),
});
s.settings.autoplay_enabled = true;
s.settings.autoplay_seconds = 2.0;
s.blanked = false;
s.displayed = Some(0);
let start = Instant::now();
assert!(!s.poll_autoplay_at(start));
assert!(!s.poll_autoplay_at(start + Duration::from_millis(1999)));
assert!(s.poll_autoplay_at(start + Duration::from_secs(2)));
assert_eq!(s.requested, 1);
// A render/output delay never consumes the new slide's interval.
assert!(!s.poll_autoplay_at(start + Duration::from_secs(20)));
assert_eq!(s.requested, 1);
s.displayed = Some(1);
assert!(!s.poll_autoplay_at(start + Duration::from_secs(20)));
assert!(s.poll_autoplay_at(start + Duration::from_secs(22)));
assert_eq!(s.requested, 2);
s.displayed = Some(2);
assert!(!s.poll_autoplay_at(start + Duration::from_secs(22)));
assert!(!s.poll_autoplay_at(start + Duration::from_secs(24)));
assert_eq!(s.requested, 2, "autoplay stops at the final slide");
s.settings.autoplay_loop = true;
s.autoplay_settings_changed();
assert!(!s.poll_autoplay_at(start + Duration::from_secs(30)));
assert!(s.poll_autoplay_at(start + Duration::from_secs(32)));
assert_eq!(s.requested, 0);
s.displayed = Some(0);
s.blanked = true;
assert!(!s.poll_autoplay_at(start + Duration::from_secs(40)));
s.blanked = false;
assert!(!s.poll_autoplay_at(start + Duration::from_secs(50)));
assert!(s.poll_autoplay_at(start + Duration::from_secs(52)));
assert_eq!(s.requested, 1, "unblanking starts a fresh interval");
}
#[test]
fn repeated_navigation_coalesces_rendering_and_clamps_without_blanking() {
let mut s = Studio::new(true, None);

View File

@ -505,6 +505,15 @@ fn quick_settings_and_preferences_window_remain_interactive() {
}
};
click(&mut s, "Menu");
click(&mut s, "Autoplay");
click(&mut s, "Play automatically");
assert!(s.settings.autoplay_enabled);
assert!(s.menu_open);
click(&mut s, "Loop");
assert!(s.settings.autoplay_loop);
assert!(s.menu_open);
click(&mut s, "Menu");
click(&mut s, "Menu");
click(&mut s, "Appearance");
click(&mut s, "Midra Dark");
assert!(

View File

@ -354,6 +354,32 @@ fn screen_modes_migrate_validate_and_roundtrip() {
assert!(s.validate().is_ok());
}
#[test]
fn autoplay_settings_migrate_validate_and_round_trip() {
let legacy: Settings = toml::from_str("version = 1").unwrap();
assert!(!legacy.autoplay_enabled);
assert_eq!(legacy.autoplay_seconds, 5.0);
assert!(!legacy.autoplay_loop);
let mut settings = legacy;
settings.autoplay_enabled = true;
settings.autoplay_seconds = 12.5;
settings.autoplay_loop = true;
let temp = tempfile::tempdir().unwrap();
let path = temp.path().join("settings.toml");
settings::write(&path, &settings).unwrap();
let loaded = settings::read(&path).unwrap();
assert!(loaded.autoplay_enabled);
assert_eq!(loaded.autoplay_seconds, 12.5);
assert!(loaded.autoplay_loop);
for invalid in [0.0, 0.24, 3600.01, f32::INFINITY, f32::NAN] {
let mut invalid_settings = loaded.clone();
invalid_settings.autoplay_seconds = invalid;
assert!(invalid_settings.validate().is_err());
}
}
#[test]
fn output_screen_modes_roundtrip_and_fall_back_to_global() {
use pdf_presenter::output::HostState;

View File

@ -2,6 +2,15 @@
## Unreleased
### 0.1.95
- Add an Autoplay menu with persistent Play automatically, per-slide timing and
loop controls. Timing starts only once the requested slide is visible; transient
dialogs and safety states pause playback, while manual interaction restarts the
interval.
- Linux formatting, warnings-denied Clippy/rustdoc, workspace tests, build and
13 Python helper tests pass. Full GUI coverage is 83.94% against the 75% floor.
### 0.1.94
- Show the full, selectable path of the running portable executable under

View File

@ -2,6 +2,9 @@ version = 1
# Optional slide-first view on an operator-owned route (0.1.89+).
single_screens = ["Primary#1"]
auto_show = true
autoplay_enabled = false
autoplay_seconds = 5.0
autoplay_loop = false
blank_picture = false
zoom_enabled = false
zoom_keep_fitted_area = false

View File

@ -33,6 +33,18 @@ flushed temporary file. Unknown fields are ignored and not preserved on round tr
document open; false starts/opens blanked. Manual navigation preserves blanking.
Since 0.1.51, display topology/fullscreen changes and host recovery preserve
the current output visibility; only explicit blank controls change it.
- `autoplay_enabled`: boolean, default false; `autoplay_seconds`: finite floating
seconds from 0.25 through 3600, default 5; and `autoplay_loop`: boolean, default
false (0.1.95). The interval begins only after the requested slide is visible on
Slides, so rendering delays do not consume a slide's display time. With no Slides
route, a ready Presenter/single-screen frame counts as visible. Manual navigation,
zoom and blank/unblank restart the interval. Blanking, loading, display trials,
startup recovery, file dialogs, notes editing/import and quit confirmation pause
autoplay and resume with a fresh interval. At the final slide autoplay stops unless
loop is enabled; a one-slide deck never repeatedly navigates. The enabled state,
timing and loop preference are global and saved immediately. Runtime deadlines and
final-slide state are transient. Older v1 files use the defaults; older binaries
ignore and discard these additive fields on resave.
- `theme`: built-in palette enum in snake_case, default `midra` (0.1.14). Values:
`midra`, `high_contrast`, `foxified_dark`, `corporate_light`, `bluecore`,
`dupont_monsanto`, `eden_green`, `foxified_light`, `hci`, `iron_docks`, `peaceframe`,

View File

@ -47,6 +47,11 @@ do not queue additional dialogs.
A single connected monitor starts presenter-only rehearsal; `--windowed` disables
fullscreen for the session. `--list-monitors` lists CLI display numbers.
Use **Menu → Autoplay** to enable automatic slide changes, choose the time each
visible slide remains on screen, and optionally loop from the final slide back to
the first. Slow preparation never shortens a slide's display time. Manual navigation,
zooming or blanking restarts the interval; dialogs and display confirmation pause it.
## Screens and presentation safety
When the application starts with exactly one connected screen, it offers