Format Rust sources at 100 columns
This commit is contained in:
1 parent
4661f595f8
commit
610478f8c7
336 files changed
+23497
-7892
No files matched your search
@@ -1,6 +1,8 @@
|
||||
//! Activity deadlines share CLOCK_BOOTTIME with the published countdowns. A
|
||||
//! monotonic calloop timer would otherwise keep waiting for time spent asleep.
|
||||
use smithay::reexports::calloop::{Interest, LoopHandle, Mode, PostAction, RegistrationToken, generic::Generic};
|
||||
use smithay::reexports::calloop::{
|
||||
Interest, LoopHandle, Mode, PostAction, RegistrationToken, generic::Generic,
|
||||
};
|
||||
use std::{
|
||||
io,
|
||||
os::fd::{AsRawFd, FromRawFd, OwnedFd},
|
||||
@@ -13,9 +15,13 @@ pub(crate) struct Deadline {
|
||||
token: RegistrationToken,
|
||||
}
|
||||
impl Deadline {
|
||||
pub fn new(handle: LoopHandle<'static, crate::Ferese>) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
pub fn new(
|
||||
handle: LoopHandle<'static, crate::Ferese>,
|
||||
) -> Result<Self, Box<dyn std::error::Error>> {
|
||||
// SAFETY: timerfd_create returns a new owned descriptor or -1.
|
||||
let fd = unsafe { libc::timerfd_create(libc::CLOCK_BOOTTIME, libc::TFD_CLOEXEC | libc::TFD_NONBLOCK) };
|
||||
let fd = unsafe {
|
||||
libc::timerfd_create(libc::CLOCK_BOOTTIME, libc::TFD_CLOEXEC | libc::TFD_NONBLOCK)
|
||||
};
|
||||
if fd < 0 {
|
||||
return Err(io::Error::last_os_error().into());
|
||||
}
|
||||
@@ -25,7 +31,8 @@ impl Deadline {
|
||||
|_, fd, state| {
|
||||
let mut expirations = 0_u64;
|
||||
// SAFETY: expirations is a writable eight-byte timerfd counter.
|
||||
let result = unsafe { libc::read(fd.as_raw_fd(), (&raw mut expirations).cast(), 8) };
|
||||
let result =
|
||||
unsafe { libc::read(fd.as_raw_fd(), (&raw mut expirations).cast(), 8) };
|
||||
if result < 0 {
|
||||
let error = io::Error::last_os_error();
|
||||
if error.kind() != io::ErrorKind::WouldBlock {
|
||||
@@ -50,7 +57,10 @@ impl Deadline {
|
||||
}
|
||||
let ms = deadline.unwrap_or(0);
|
||||
let spec = libc::itimerspec {
|
||||
it_interval: libc::timespec { tv_sec: 0, tv_nsec: 0 },
|
||||
it_interval: libc::timespec {
|
||||
tv_sec: 0,
|
||||
tv_nsec: 0,
|
||||
},
|
||||
it_value: libc::timespec {
|
||||
tv_sec: (ms / 1_000) as _,
|
||||
tv_nsec: ((ms % 1_000) * 1_000_000) as _,
|
||||
@@ -86,13 +96,17 @@ mod tests {
|
||||
fn deadline_uses_boottime_and_disarming_leaves_no_periodic_wakeups() {
|
||||
let events = smithay::reexports::calloop::EventLoop::<crate::Ferese>::try_new().unwrap();
|
||||
let deadline = Deadline::new(events.handle()).unwrap();
|
||||
let info = std::fs::read_to_string(format!("/proc/self/fdinfo/{}", deadline.fd.as_raw_fd())).unwrap();
|
||||
let info =
|
||||
std::fs::read_to_string(format!("/proc/self/fdinfo/{}", deadline.fd.as_raw_fd()))
|
||||
.unwrap();
|
||||
assert!(
|
||||
info.lines()
|
||||
.any(|line| line.split_whitespace().collect::<Vec<_>>() == ["clockid:", "7"]),
|
||||
"{info}"
|
||||
);
|
||||
deadline.update(Some(ferese_ipc::activities::now_ms() + 20)).unwrap();
|
||||
deadline
|
||||
.update(Some(ferese_ipc::activities::now_ms() + 20))
|
||||
.unwrap();
|
||||
let mut pollfd = libc::pollfd {
|
||||
fd: deadline.fd.as_raw_fd(),
|
||||
events: libc::POLLIN,
|
||||
|
||||
@@ -69,7 +69,9 @@ impl Engine {
|
||||
return Err("Pomodoro session changed; refresh its controls".into());
|
||||
}
|
||||
let now = ferese_ipc::activities::now_ms();
|
||||
if !matches!(request.action, PomodoroAction::Stop | PomodoroAction::Reset) && self.advance_pomodoro(now) {
|
||||
if !matches!(request.action, PomodoroAction::Stop | PomodoroAction::Reset)
|
||||
&& self.advance_pomodoro(now)
|
||||
{
|
||||
self.changed();
|
||||
}
|
||||
match request.action {
|
||||
@@ -85,8 +87,8 @@ impl Engine {
|
||||
}
|
||||
let session = Session::start(self.pomodoro_settings.clone(), now)?;
|
||||
// Verify the long-lived host, never the short-lived CLI, as owner.
|
||||
let (owner, _pidfd, _) =
|
||||
crate::ipc::activity_owner::inspect(std::process::id()).map_err(|error| error.to_string())?;
|
||||
let (owner, _pidfd, _) = crate::ipc::activity_owner::inspect(std::process::id())
|
||||
.map_err(|error| error.to_string())?;
|
||||
let id = Id {
|
||||
owner,
|
||||
local: "pomodoro".into(),
|
||||
@@ -104,7 +106,10 @@ impl Engine {
|
||||
self.pomodoro = None;
|
||||
}
|
||||
action => {
|
||||
let timer = self.pomodoro.as_mut().ok_or("No Pomodoro session; start one first")?;
|
||||
let timer = self
|
||||
.pomodoro
|
||||
.as_mut()
|
||||
.ok_or("No Pomodoro session; start one first")?;
|
||||
match action {
|
||||
PomodoroAction::Pause => timer.session.pause(now)?,
|
||||
PomodoroAction::Resume => timer.session.resume(now)?,
|
||||
@@ -182,14 +187,24 @@ impl Alerts {
|
||||
let connection = zbus::blocking::connection::Builder::session()?
|
||||
.method_timeout(Duration::from_secs(2))
|
||||
.build()?;
|
||||
let mut hints = std::collections::HashMap::<&str, zbus::zvariant::Value<'_>>::new();
|
||||
let mut hints =
|
||||
std::collections::HashMap::<&str, zbus::zvariant::Value<'_>>::new();
|
||||
hints.insert("suppress-sound", zbus::zvariant::Value::Bool(true));
|
||||
let reply = connection.call_method(
|
||||
Some("org.freedesktop.Notifications"),
|
||||
"/org/freedesktop/Notifications",
|
||||
Some("org.freedesktop.Notifications"),
|
||||
"Notify",
|
||||
&("Ferese", 0_u32, "", title, body, Vec::<String>::new(), hints, -1_i32),
|
||||
&(
|
||||
"Ferese",
|
||||
0_u32,
|
||||
"",
|
||||
title,
|
||||
body,
|
||||
Vec::<String>::new(),
|
||||
hints,
|
||||
-1_i32,
|
||||
),
|
||||
)?;
|
||||
let _: u32 = reply.body().deserialize()?;
|
||||
Ok(())
|
||||
@@ -218,8 +233,7 @@ mod tests {
|
||||
}
|
||||
#[test]
|
||||
fn completion_uses_the_standard_notification_service_without_sound() {
|
||||
const TEST: &str =
|
||||
"activities::pomodoro::tests::completion_uses_the_standard_notification_service_without_sound";
|
||||
const TEST: &str = "activities::pomodoro::tests::completion_uses_the_standard_notification_service_without_sound";
|
||||
if !crate::startup_tests::private_runtime(TEST) {
|
||||
return;
|
||||
}
|
||||
@@ -296,7 +310,10 @@ mod tests {
|
||||
assert_eq!(first.id.owner.pid, std::process::id());
|
||||
assert!(control(&mut engine, PomodoroAction::Start).is_err());
|
||||
engine.remove_connection(10);
|
||||
engine.owner_exit(Owner { pid: 999_999, birth: 0 });
|
||||
engine.owner_exit(Owner {
|
||||
pid: 999_999,
|
||||
birth: 0,
|
||||
});
|
||||
assert_eq!(engine.snapshot().pomodoro.as_ref().unwrap().id, first.id);
|
||||
assert_eq!(engine.snapshot().activities.len(), 1);
|
||||
control(&mut engine, PomodoroAction::Reset).unwrap();
|
||||
@@ -355,7 +372,10 @@ mod tests {
|
||||
engine.pomodoro_remove_output("test", None);
|
||||
assert!(engine.pomodoro_attach_output("new"));
|
||||
engine.changed();
|
||||
assert_eq!(engine.snapshot().activities[0].data.output.as_deref(), Some("new"));
|
||||
assert_eq!(
|
||||
engine.snapshot().activities[0].data.output.as_deref(),
|
||||
Some("new")
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn disabled_alerts_and_schema_errors_have_no_side_effects() {
|
||||
|
||||
@@ -26,7 +26,10 @@ impl Publisher {
|
||||
.as_ref()
|
||||
.is_some_and(|(snapshot, _)| Arc::ptr_eq(snapshot, &job.snapshot))
|
||||
{
|
||||
cached = Some((job.snapshot.clone(), serde_json::json!(job.snapshot.as_ref())));
|
||||
cached = Some((
|
||||
job.snapshot.clone(),
|
||||
serde_json::json!(job.snapshot.as_ref()),
|
||||
));
|
||||
}
|
||||
let value = &cached.as_ref().unwrap().1;
|
||||
// Lock acquisition revokes queued/in-flight serialization.
|
||||
@@ -54,7 +57,12 @@ impl Publisher {
|
||||
}
|
||||
}
|
||||
}
|
||||
fn deliver(epoch: u64, current: &RwLock<u64>, recipients: Vec<Recipient>, value: &serde_json::Value) {
|
||||
fn deliver(
|
||||
epoch: u64,
|
||||
current: &RwLock<u64>,
|
||||
recipients: Vec<Recipient>,
|
||||
value: &serde_json::Value,
|
||||
) {
|
||||
let current = current.read().expect("activity publication epoch");
|
||||
if epoch != *current {
|
||||
locked(recipients);
|
||||
@@ -116,9 +124,16 @@ mod tests {
|
||||
|
||||
let publisher = Publisher::new().unwrap();
|
||||
let (slow, _slow_receive) = mpsc::sync_channel(1);
|
||||
slow.send(Response::success(1, serde_json::json!({}))).unwrap();
|
||||
slow.send(Response::success(1, serde_json::json!({})))
|
||||
.unwrap();
|
||||
let (fast, fast_receive) = mpsc::sync_channel(1);
|
||||
publisher.send(Arc::new(Snapshot::default()), vec![(2, slow), (3, fast)]);
|
||||
assert_eq!(fast_receive.recv_timeout(Duration::from_secs(1)).unwrap().id, 3);
|
||||
assert_eq!(
|
||||
fast_receive
|
||||
.recv_timeout(Duration::from_secs(1))
|
||||
.unwrap()
|
||||
.id,
|
||||
3
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user