North on the now-playing screen, or s anywhere, shuffles what has not played yet. Off goes back to the order the tracks were queued in and carries on after the playing track. Tracks queued while shuffled go to random positions, an album as one block under album shuffle. The player reorders its own list under its lock and keeps a track it already handed to playbin next, so playback stays gapless. Each reorder bumps a queue generation that track and picture events carry, and the app drops an event sent before the last reorder. The saved queue keeps the original order and the mode; older files load unshuffled.
89 lines
2.9 KiB
Rust
89 lines
2.9 KiB
Rust
slint::include_modules!();
|
|
|
|
mod app;
|
|
mod config;
|
|
mod devscript;
|
|
mod inhibit;
|
|
mod input;
|
|
mod mpris;
|
|
mod palette;
|
|
mod player;
|
|
mod prompts;
|
|
mod saved_queue;
|
|
mod shuffle;
|
|
mod subsonic;
|
|
|
|
use std::time::Duration;
|
|
|
|
fn main() -> anyhow::Result<()> {
|
|
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("remus=info")).init();
|
|
|
|
let dev_script = std::env::var("REMUS_DEV_SCRIPT").ok();
|
|
let windowed = std::env::args().any(|a| a == "--windowed") || std::env::var_os("REMUS_WINDOWED").is_some();
|
|
|
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
|
.worker_threads(2)
|
|
.enable_all()
|
|
.build()?;
|
|
|
|
let ui = AppWindow::new()?;
|
|
ui.set_version(env!("CARGO_PKG_VERSION").into());
|
|
app::install(&ui, rt.handle().clone());
|
|
// The controller is read from the device, whichever window is in front, so
|
|
// the app needs to know when another one is, to leave the presses to it.
|
|
{
|
|
use slint::winit_030::{EventResult, WinitWindowAccessor, winit::event::WindowEvent};
|
|
ui.window().on_winit_window_event(|_, event| {
|
|
if let WindowEvent::Focused(focused) = *event {
|
|
log::debug!("window focused: {focused}");
|
|
app::with_app(move |app| app.set_window_active(focused));
|
|
}
|
|
EventResult::Propagate
|
|
});
|
|
}
|
|
input::spawn_gamepad(|ev| {
|
|
let _ = slint::invoke_from_event_loop(move || {
|
|
app::with_app(move |app| match ev {
|
|
input::PadEvent::Action(action, family) => app.pad_action(action, family),
|
|
input::PadEvent::Present(family) => app.pad_present(family),
|
|
})
|
|
});
|
|
});
|
|
|
|
// Kept alive until the event loop ends.
|
|
let fullscreen_retry = slint::Timer::default();
|
|
if !windowed {
|
|
ui.window().set_fullscreen(true);
|
|
// Compositors ignore the request until the window is mapped, and a
|
|
// tiling one (COSMIC) can take the window back right after granting
|
|
// it. Keep asking until fullscreen has held for a second, giving up
|
|
// after five. Then stop, so a later F11 to leave fullscreen sticks.
|
|
let weak = ui.as_weak();
|
|
let (mut ticks, mut held) = (0, 0);
|
|
fullscreen_retry.start(slint::TimerMode::Repeated, Duration::from_millis(100), move || {
|
|
let Some(ui) = weak.upgrade() else { return };
|
|
if ticks >= 50 || held >= 10 {
|
|
return;
|
|
}
|
|
ticks += 1;
|
|
if ui.window().is_fullscreen() {
|
|
held += 1;
|
|
return;
|
|
}
|
|
held = 0;
|
|
log::debug!("not fullscreen yet ({:?}), asking again", ui.window().size());
|
|
ui.window().set_fullscreen(false);
|
|
ui.window().set_fullscreen(true);
|
|
});
|
|
}
|
|
|
|
if let Some(script) = dev_script {
|
|
devscript::run(&ui, &script);
|
|
}
|
|
|
|
ui.run()?;
|
|
app::shutdown();
|
|
drop(rt);
|
|
Ok(())
|
|
}
|