Skip to content

armgit / Kooha

Public Imported from GitHub
0

Elegantly record your screen

refactor: use 2024 edition

Dave Patrick Caberto6b093759196b
diff --git a/Cargo.toml b/Cargo.toml
index c314743..bb39b3d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,7 +3,7 @@ name = "kooha"
version = "2.3.1"
authors = ["Dave Patrick Caberto <[email protected]>"]
license = "GPL-3.0-or-later"
-edition = "2021"
+edition = "2024"
[profile.release]
lto = true
diff --git a/src/about.rs b/src/about.rs
index 2585ae6..00a8324 100644
--- a/src/about.rs
+++ b/src/about.rs
@@ -7,8 +7,8 @@ use std::{
};
use adw::prelude::*;
-use anyhow::anyhow;
use anyhow::Result;
+use anyhow::anyhow;
use gettextrs::gettext;
use gst::prelude::*;
use gtk::glib;
@@ -86,10 +86,10 @@ fn cpu_model() -> Result<String> {
for res in output.stdout.lines() {
let line = res?;
- if line.contains("Model name:") {
- if let Some((_, value)) = line.split_once(':') {
- return Ok(value.trim().to_string());
- }
+ if line.contains("Model name:")
+ && let Some((_, value)) = line.split_once(':')
+ {
+ return Ok(value.trim().to_string());
}
}
@@ -105,10 +105,10 @@ fn gpu_model() -> Result<String> {
for res in output.stdout.lines() {
let line = res?;
- if line.contains("VGA") {
- if let Some(value) = line.splitn(3, ':').last() {
- return Ok(value.trim().to_string());
- }
+ if line.contains("VGA")
+ && let Some(value) = line.splitn(3, ':').last()
+ {
+ return Ok(value.trim().to_string());
}
}
diff --git a/src/area_selector/mod.rs b/src/area_selector/mod.rs
index caa54e0..5fd6844 100644
--- a/src/area_selector/mod.rs
+++ b/src/area_selector/mod.rs
@@ -156,10 +156,10 @@ mod imp {
}
fn dispose(&self) {
- if let Some(pipeline) = self.pipeline.get() {
- if let Err(err) = pipeline.set_state(gst::State::Null) {
- tracing::warn!("Failed to set pipeline to Null: {}", err);
- }
+ if let Some(pipeline) = self.pipeline.get()
+ && let Err(err) = pipeline.set_state(gst::State::Null)
+ {
+ tracing::warn!("Failed to set pipeline to Null: {}", err);
}
}
}
@@ -265,10 +265,10 @@ impl AreaSelector {
let state_change = pipeline.set_state(gst::State::Playing)?;
- if state_change != gst::StateChangeSuccess::Async {
- if let Some(async_done_tx) = imp.async_done_tx.take() {
- let _ = async_done_tx.send(Ok(()));
- }
+ if state_change != gst::StateChangeSuccess::Async
+ && let Some(async_done_tx) = imp.async_done_tx.take()
+ {
+ let _ = async_done_tx.send(Ok(()));
}
this.present();
@@ -302,10 +302,10 @@ impl AreaSelector {
let handler_id = imp
.view_port
.connect_paintable_rect_notify(move |view_port| {
- if view_port.paintable_rect().is_some() {
- if let Some(selection_context_set_tx) = paintable_rect_set_tx.take() {
- let _ = selection_context_set_tx.send(());
- }
+ if view_port.paintable_rect().is_some()
+ && let Some(selection_context_set_tx) = paintable_rect_set_tx.take()
+ {
+ let _ = selection_context_set_tx.send(());
}
});
diff --git a/src/area_selector/view_port.rs b/src/area_selector/view_port.rs
index 7e8d5d0..d575e61 100644
--- a/src/area_selector/view_port.rs
+++ b/src/area_selector/view_port.rs
@@ -274,23 +274,23 @@ mod imp {
obj.notify_paintable_rect();
// Update selection if paintable rect changed.
- if let Some(prev_paintable_rect) = prev_paintable_rect {
- if let Some(selection) = obj.selection() {
- let selection_rect = selection.rect();
-
- let scale_x = new_paintable_rect.width() / prev_paintable_rect.width();
- let scale_y = new_paintable_rect.height() / prev_paintable_rect.height();
-
- let rel_x = selection_rect.x() - prev_paintable_rect.x();
- let rel_y = selection_rect.y() - prev_paintable_rect.y();
-
- obj.set_selection(Some(Selection::from_rect(
- new_paintable_rect.x() + rel_x * scale_x,
- new_paintable_rect.y() + rel_y * scale_y,
- selection_rect.width() * scale_x,
- selection_rect.height() * scale_y,
- )));
- }
+ if let Some(prev_paintable_rect) = prev_paintable_rect
+ && let Some(selection) = obj.selection()
+ {
+ let selection_rect = selection.rect();
+
+ let scale_x = new_paintable_rect.width() / prev_paintable_rect.width();
+ let scale_y = new_paintable_rect.height() / prev_paintable_rect.height();
+
+ let rel_x = selection_rect.x() - prev_paintable_rect.x();
+ let rel_y = selection_rect.y() - prev_paintable_rect.y();
+
+ obj.set_selection(Some(Selection::from_rect(
+ new_paintable_rect.x() + rel_x * scale_x,
+ new_paintable_rect.y() + rel_y * scale_y,
+ selection_rect.width() * scale_x,
+ selection_rect.height() * scale_y,
+ )));
}
}
@@ -444,8 +444,12 @@ impl ViewPort {
return CursorType::Crosshair;
};
- let [top_left_handle, top_right_handle, bottom_right_handle, bottom_left_handle] =
- imp.selection_handles.get().unwrap();
+ let [
+ top_left_handle,
+ top_right_handle,
+ bottom_right_handle,
+ bottom_left_handle,
+ ] = imp.selection_handles.get().unwrap();
if top_left_handle.contains_point(&position) {
CursorType::NorthWestResize
@@ -800,37 +804,36 @@ impl ViewPort {
// The user clicked without dragging. Make up a larger selection
// to reduce confusion.
- if let Some(mut selection) = self.selection() {
- if imp.drag_cursor.get() == CursorType::Crosshair
- && selection.end_x == selection.start_x
- && selection.end_y == selection.start_y
- {
- let offset = DEFAULT_SELECTION_SIZE / 2.0;
- selection.start_x -= offset;
- selection.start_y -= offset;
- selection.end_x += offset;
- selection.end_y += offset;
-
- let selection_rect = selection.rect();
-
- // Keep the coordinates inside the paintable rect.
- if selection.start_x < paintable_rect.x() {
- selection.start_x = paintable_rect.x();
- selection.end_x = selection.start_x + selection_rect.width();
- } else if selection.end_x > paintable_rect.width() + paintable_rect.x() {
- selection.end_x = paintable_rect.width() + paintable_rect.x();
- selection.start_x = selection.end_x - selection_rect.width();
- }
- if selection.start_y < paintable_rect.y() {
- selection.start_y = paintable_rect.y();
- selection.end_y = selection.start_y + selection_rect.height();
- } else if selection.end_y > paintable_rect.height() + paintable_rect.y() {
- selection.end_y = paintable_rect.height() + paintable_rect.y();
- selection.start_y = selection.end_y - selection_rect.height();
- }
-
- self.set_selection(Some(selection));
+ if let Some(mut selection) = self.selection()
+ && imp.drag_cursor.get() == CursorType::Crosshair
+ && selection.end_x == selection.start_x
+ && selection.end_y == selection.start_y
+ {
+ let offset = DEFAULT_SELECTION_SIZE / 2.0;
+ selection.start_x -= offset;
+ selection.start_y -= offset;
+ selection.end_x += offset;
+ selection.end_y += offset;
+
+ let selection_rect = selection.rect();
+
+ // Keep the coordinates inside the paintable rect.
+ if selection.start_x < paintable_rect.x() {
+ selection.start_x = paintable_rect.x();
+ selection.end_x = selection.start_x + selection_rect.width();
+ } else if selection.end_x > paintable_rect.width() + paintable_rect.x() {
+ selection.end_x = paintable_rect.width() + paintable_rect.x();
+ selection.start_x = selection.end_x - selection_rect.width();
}
+ if selection.start_y < paintable_rect.y() {
+ selection.start_y = paintable_rect.y();
+ selection.end_y = selection.start_y + selection_rect.height();
+ } else if selection.end_y > paintable_rect.height() + paintable_rect.y() {
+ selection.end_y = paintable_rect.height() + paintable_rect.y();
+ selection.start_y = selection.end_y - selection_rect.height();
+ }
+
+ self.set_selection(Some(selection));
}
if let Some(pointer_position) = imp.pointer_position.get() {
diff --git a/src/preferences_dialog.rs b/src/preferences_dialog.rs
index a7a3fe6..a196d0f 100644
--- a/src/preferences_dialog.rs
+++ b/src/preferences_dialog.rs
@@ -4,7 +4,7 @@ use adw::{prelude::*, subclass::prelude::*};
use gettextrs::gettext;
use gtk::{
gio,
- glib::{self, clone, BoxedAnyObject},
+ glib::{self, BoxedAnyObject, clone},
};
use crate::{
@@ -66,17 +66,15 @@ mod imp {
None,
|obj, _, _| async move {
let parent = obj.root().map(|r| r.downcast::<gtk::Window>().unwrap());
- if let Err(err) = obj.settings().select_saving_location(parent.as_ref()).await {
- if !err
+ if let Err(err) = obj.settings().select_saving_location(parent.as_ref()).await
+ && !err
.downcast_ref::<glib::Error>()
.is_some_and(|error| error.matches(gtk::DialogError::Dismissed))
- {
- tracing::error!("Failed to select saving location: {:?}", err);
+ {
+ tracing::error!("Failed to select saving location: {:?}", err);
- let toast =
- adw::Toast::new(&gettext("Failed to set recordings folder"));
- obj.add_toast(toast);
- }
+ let toast = adw::Toast::new(&gettext("Failed to set recordings folder"));
+ obj.add_toast(toast);
}
},
);
diff --git a/src/recording.rs b/src/recording.rs
index f5e5bd2..899c681 100644
--- a/src/recording.rs
+++ b/src/recording.rs
@@ -9,7 +9,7 @@ use std::{
time::Duration,
};
-use anyhow::{ensure, Context, Error, Result};
+use anyhow::{Context, Error, Result, ensure};
use gettextrs::gettext;
use gst::prelude::*;
use gtk::{
@@ -106,10 +106,10 @@ mod imp {
timer.cancel();
}
- if let Some(pipeline) = self.pipeline.get() {
- if let Err(err) = pipeline.set_state(gst::State::Null) {
- tracing::warn!("Failed to stop pipeline on dispose: {:?}", err);
- }
+ if let Some(pipeline) = self.pipeline.get()
+ && let Err(err) = pipeline.set_state(gst::State::Null)
+ {
+ tracing::warn!("Failed to stop pipeline on dispose: {:?}", err);
}
self.obj().close_session();
@@ -121,9 +121,11 @@ mod imp {
fn signals() -> &'static [glib::subclass::Signal] {
static SIGNALS: LazyLock<Vec<Signal>> = LazyLock::new(|| {
- vec![Signal::builder("finished")
- .param_types([BoxedResult::static_type()])
- .build()]
+ vec![
+ Signal::builder("finished")
+ .param_types([BoxedResult::static_type()])
+ .build(),
+ ]
});
SIGNALS.as_ref()
@@ -343,10 +345,10 @@ impl Recording {
timer.cancel();
}
- if let Some(pipeline) = imp.pipeline.get() {
- if let Err(err) = pipeline.set_state(gst::State::Null) {
- tracing::warn!("Failed to stop pipeline on cancel: {:?}", err);
- }
+ if let Some(pipeline) = imp.pipeline.get()
+ && let Err(err) = pipeline.set_state(gst::State::Null)
+ {
+ tracing::warn!("Failed to stop pipeline on cancel: {:?}", err);
}
let _ = imp.bus_watch_guard.take();
diff --git a/src/settings.rs b/src/settings.rs
index 179cc98..3bff188 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -175,8 +175,10 @@ mod tests {
);
}
- env::set_var("GSETTINGS_SCHEMA_DIR", schema_dir);
- env::set_var("GSETTINGS_BACKEND", "memory");
+ unsafe {
+ env::set_var("GSETTINGS_SCHEMA_DIR", schema_dir);
+ env::set_var("GSETTINGS_BACKEND", "memory");
+ }
});
}
diff --git a/src/window/mod.rs b/src/window/mod.rs
index f84969a..7a2315e 100644
--- a/src/window/mod.rs
+++ b/src/window/mod.rs
@@ -13,6 +13,7 @@ use std::cell::RefCell;
use self::{progress_icon::ProgressIcon, toggle_button::ToggleButton};
use crate::{
+ Application,
cancelled::Cancelled,
config::PROFILE,
format,
@@ -20,7 +21,6 @@ use crate::{
preferences_dialog::PreferencesDialog,
recording::{NoProfileError, Recording, RecordingState},
settings::CaptureMode,
- Application,
};
mod imp {
@@ -420,7 +420,7 @@ impl Window {
let recent_manager = gtk::RecentManager::default();
recent_manager.add_item(&recording_file.uri());
}
- Err(ref err) => {
+ Err(err) => {
if err.is::<Cancelled>() {
tracing::debug!("{:?}", err);
} else if err.is::<NoProfileError>() {
@@ -463,12 +463,10 @@ impl Window {
imp.inhibit_cookie.replace(Some(inhibit_cookie));
tracing::debug!("Inhibited logout and idle");
- } else if !is_busy {
- if let Some(inhibit_cookie) = imp.inhibit_cookie.take() {
- app.uninhibit(inhibit_cookie);
+ } else if !is_busy && let Some(inhibit_cookie) = imp.inhibit_cookie.take() {
+ app.uninhibit(inhibit_cookie);
- tracing::debug!("Uninhibited logout and idle");
- }
+ tracing::debug!("Uninhibited logout and idle");
}
}