Skip to content

Commit 6b09375

Browse files
committed
refactor: use 2024 edition
1 parent 81826d4 commit 6b09375

File tree

8 files changed

+104
-101
lines changed

8 files changed

+104
-101
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "kooha"
33
version = "2.3.1"
44
authors = ["Dave Patrick Caberto <[email protected]>"]
55
license = "GPL-3.0-or-later"
6-
edition = "2021"
6+
edition = "2024"
77

88
[profile.release]
99
lto = true

src/about.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::{
77
};
88

99
use adw::prelude::*;
10-
use anyhow::anyhow;
1110
use anyhow::Result;
11+
use anyhow::anyhow;
1212
use gettextrs::gettext;
1313
use gst::prelude::*;
1414
use gtk::glib;
@@ -86,10 +86,10 @@ fn cpu_model() -> Result<String> {
8686
for res in output.stdout.lines() {
8787
let line = res?;
8888

89-
if line.contains("Model name:") {
90-
if let Some((_, value)) = line.split_once(':') {
91-
return Ok(value.trim().to_string());
92-
}
89+
if line.contains("Model name:")
90+
&& let Some((_, value)) = line.split_once(':')
91+
{
92+
return Ok(value.trim().to_string());
9393
}
9494
}
9595

@@ -105,10 +105,10 @@ fn gpu_model() -> Result<String> {
105105
for res in output.stdout.lines() {
106106
let line = res?;
107107

108-
if line.contains("VGA") {
109-
if let Some(value) = line.splitn(3, ':').last() {
110-
return Ok(value.trim().to_string());
111-
}
108+
if line.contains("VGA")
109+
&& let Some(value) = line.splitn(3, ':').last()
110+
{
111+
return Ok(value.trim().to_string());
112112
}
113113
}
114114

src/area_selector/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ mod imp {
156156
}
157157

158158
fn dispose(&self) {
159-
if let Some(pipeline) = self.pipeline.get() {
160-
if let Err(err) = pipeline.set_state(gst::State::Null) {
161-
tracing::warn!("Failed to set pipeline to Null: {}", err);
162-
}
159+
if let Some(pipeline) = self.pipeline.get()
160+
&& let Err(err) = pipeline.set_state(gst::State::Null)
161+
{
162+
tracing::warn!("Failed to set pipeline to Null: {}", err);
163163
}
164164
}
165165
}
@@ -265,10 +265,10 @@ impl AreaSelector {
265265

266266
let state_change = pipeline.set_state(gst::State::Playing)?;
267267

268-
if state_change != gst::StateChangeSuccess::Async {
269-
if let Some(async_done_tx) = imp.async_done_tx.take() {
270-
let _ = async_done_tx.send(Ok(()));
271-
}
268+
if state_change != gst::StateChangeSuccess::Async
269+
&& let Some(async_done_tx) = imp.async_done_tx.take()
270+
{
271+
let _ = async_done_tx.send(Ok(()));
272272
}
273273

274274
this.present();
@@ -302,10 +302,10 @@ impl AreaSelector {
302302
let handler_id = imp
303303
.view_port
304304
.connect_paintable_rect_notify(move |view_port| {
305-
if view_port.paintable_rect().is_some() {
306-
if let Some(selection_context_set_tx) = paintable_rect_set_tx.take() {
307-
let _ = selection_context_set_tx.send(());
308-
}
305+
if view_port.paintable_rect().is_some()
306+
&& let Some(selection_context_set_tx) = paintable_rect_set_tx.take()
307+
{
308+
let _ = selection_context_set_tx.send(());
309309
}
310310
});
311311

src/area_selector/view_port.rs

Lines changed: 52 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -274,23 +274,23 @@ mod imp {
274274
obj.notify_paintable_rect();
275275

276276
// Update selection if paintable rect changed.
277-
if let Some(prev_paintable_rect) = prev_paintable_rect {
278-
if let Some(selection) = obj.selection() {
279-
let selection_rect = selection.rect();
280-
281-
let scale_x = new_paintable_rect.width() / prev_paintable_rect.width();
282-
let scale_y = new_paintable_rect.height() / prev_paintable_rect.height();
283-
284-
let rel_x = selection_rect.x() - prev_paintable_rect.x();
285-
let rel_y = selection_rect.y() - prev_paintable_rect.y();
286-
287-
obj.set_selection(Some(Selection::from_rect(
288-
new_paintable_rect.x() + rel_x * scale_x,
289-
new_paintable_rect.y() + rel_y * scale_y,
290-
selection_rect.width() * scale_x,
291-
selection_rect.height() * scale_y,
292-
)));
293-
}
277+
if let Some(prev_paintable_rect) = prev_paintable_rect
278+
&& let Some(selection) = obj.selection()
279+
{
280+
let selection_rect = selection.rect();
281+
282+
let scale_x = new_paintable_rect.width() / prev_paintable_rect.width();
283+
let scale_y = new_paintable_rect.height() / prev_paintable_rect.height();
284+
285+
let rel_x = selection_rect.x() - prev_paintable_rect.x();
286+
let rel_y = selection_rect.y() - prev_paintable_rect.y();
287+
288+
obj.set_selection(Some(Selection::from_rect(
289+
new_paintable_rect.x() + rel_x * scale_x,
290+
new_paintable_rect.y() + rel_y * scale_y,
291+
selection_rect.width() * scale_x,
292+
selection_rect.height() * scale_y,
293+
)));
294294
}
295295
}
296296

@@ -444,8 +444,12 @@ impl ViewPort {
444444
return CursorType::Crosshair;
445445
};
446446

447-
let [top_left_handle, top_right_handle, bottom_right_handle, bottom_left_handle] =
448-
imp.selection_handles.get().unwrap();
447+
let [
448+
top_left_handle,
449+
top_right_handle,
450+
bottom_right_handle,
451+
bottom_left_handle,
452+
] = imp.selection_handles.get().unwrap();
449453

450454
if top_left_handle.contains_point(&position) {
451455
CursorType::NorthWestResize
@@ -800,37 +804,36 @@ impl ViewPort {
800804

801805
// The user clicked without dragging. Make up a larger selection
802806
// to reduce confusion.
803-
if let Some(mut selection) = self.selection() {
804-
if imp.drag_cursor.get() == CursorType::Crosshair
805-
&& selection.end_x == selection.start_x
806-
&& selection.end_y == selection.start_y
807-
{
808-
let offset = DEFAULT_SELECTION_SIZE / 2.0;
809-
selection.start_x -= offset;
810-
selection.start_y -= offset;
811-
selection.end_x += offset;
812-
selection.end_y += offset;
813-
814-
let selection_rect = selection.rect();
815-
816-
// Keep the coordinates inside the paintable rect.
817-
if selection.start_x < paintable_rect.x() {
818-
selection.start_x = paintable_rect.x();
819-
selection.end_x = selection.start_x + selection_rect.width();
820-
} else if selection.end_x > paintable_rect.width() + paintable_rect.x() {
821-
selection.end_x = paintable_rect.width() + paintable_rect.x();
822-
selection.start_x = selection.end_x - selection_rect.width();
823-
}
824-
if selection.start_y < paintable_rect.y() {
825-
selection.start_y = paintable_rect.y();
826-
selection.end_y = selection.start_y + selection_rect.height();
827-
} else if selection.end_y > paintable_rect.height() + paintable_rect.y() {
828-
selection.end_y = paintable_rect.height() + paintable_rect.y();
829-
selection.start_y = selection.end_y - selection_rect.height();
830-
}
831-
832-
self.set_selection(Some(selection));
807+
if let Some(mut selection) = self.selection()
808+
&& imp.drag_cursor.get() == CursorType::Crosshair
809+
&& selection.end_x == selection.start_x
810+
&& selection.end_y == selection.start_y
811+
{
812+
let offset = DEFAULT_SELECTION_SIZE / 2.0;
813+
selection.start_x -= offset;
814+
selection.start_y -= offset;
815+
selection.end_x += offset;
816+
selection.end_y += offset;
817+
818+
let selection_rect = selection.rect();
819+
820+
// Keep the coordinates inside the paintable rect.
821+
if selection.start_x < paintable_rect.x() {
822+
selection.start_x = paintable_rect.x();
823+
selection.end_x = selection.start_x + selection_rect.width();
824+
} else if selection.end_x > paintable_rect.width() + paintable_rect.x() {
825+
selection.end_x = paintable_rect.width() + paintable_rect.x();
826+
selection.start_x = selection.end_x - selection_rect.width();
833827
}
828+
if selection.start_y < paintable_rect.y() {
829+
selection.start_y = paintable_rect.y();
830+
selection.end_y = selection.start_y + selection_rect.height();
831+
} else if selection.end_y > paintable_rect.height() + paintable_rect.y() {
832+
selection.end_y = paintable_rect.height() + paintable_rect.y();
833+
selection.start_y = selection.end_y - selection_rect.height();
834+
}
835+
836+
self.set_selection(Some(selection));
834837
}
835838

836839
if let Some(pointer_position) = imp.pointer_position.get() {

src/preferences_dialog.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use adw::{prelude::*, subclass::prelude::*};
44
use gettextrs::gettext;
55
use gtk::{
66
gio,
7-
glib::{self, clone, BoxedAnyObject},
7+
glib::{self, BoxedAnyObject, clone},
88
};
99

1010
use crate::{
@@ -66,17 +66,15 @@ mod imp {
6666
None,
6767
|obj, _, _| async move {
6868
let parent = obj.root().map(|r| r.downcast::<gtk::Window>().unwrap());
69-
if let Err(err) = obj.settings().select_saving_location(parent.as_ref()).await {
70-
if !err
69+
if let Err(err) = obj.settings().select_saving_location(parent.as_ref()).await
70+
&& !err
7171
.downcast_ref::<glib::Error>()
7272
.is_some_and(|error| error.matches(gtk::DialogError::Dismissed))
73-
{
74-
tracing::error!("Failed to select saving location: {:?}", err);
73+
{
74+
tracing::error!("Failed to select saving location: {:?}", err);
7575

76-
let toast =
77-
adw::Toast::new(&gettext("Failed to set recordings folder"));
78-
obj.add_toast(toast);
79-
}
76+
let toast = adw::Toast::new(&gettext("Failed to set recordings folder"));
77+
obj.add_toast(toast);
8078
}
8179
},
8280
);

src/recording.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{
99
time::Duration,
1010
};
1111

12-
use anyhow::{ensure, Context, Error, Result};
12+
use anyhow::{Context, Error, Result, ensure};
1313
use gettextrs::gettext;
1414
use gst::prelude::*;
1515
use gtk::{
@@ -106,10 +106,10 @@ mod imp {
106106
timer.cancel();
107107
}
108108

109-
if let Some(pipeline) = self.pipeline.get() {
110-
if let Err(err) = pipeline.set_state(gst::State::Null) {
111-
tracing::warn!("Failed to stop pipeline on dispose: {:?}", err);
112-
}
109+
if let Some(pipeline) = self.pipeline.get()
110+
&& let Err(err) = pipeline.set_state(gst::State::Null)
111+
{
112+
tracing::warn!("Failed to stop pipeline on dispose: {:?}", err);
113113
}
114114

115115
self.obj().close_session();
@@ -121,9 +121,11 @@ mod imp {
121121

122122
fn signals() -> &'static [glib::subclass::Signal] {
123123
static SIGNALS: LazyLock<Vec<Signal>> = LazyLock::new(|| {
124-
vec![Signal::builder("finished")
125-
.param_types([BoxedResult::static_type()])
126-
.build()]
124+
vec![
125+
Signal::builder("finished")
126+
.param_types([BoxedResult::static_type()])
127+
.build(),
128+
]
127129
});
128130

129131
SIGNALS.as_ref()
@@ -343,10 +345,10 @@ impl Recording {
343345
timer.cancel();
344346
}
345347

346-
if let Some(pipeline) = imp.pipeline.get() {
347-
if let Err(err) = pipeline.set_state(gst::State::Null) {
348-
tracing::warn!("Failed to stop pipeline on cancel: {:?}", err);
349-
}
348+
if let Some(pipeline) = imp.pipeline.get()
349+
&& let Err(err) = pipeline.set_state(gst::State::Null)
350+
{
351+
tracing::warn!("Failed to stop pipeline on cancel: {:?}", err);
350352
}
351353

352354
let _ = imp.bus_watch_guard.take();

src/settings.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ mod tests {
175175
);
176176
}
177177

178-
env::set_var("GSETTINGS_SCHEMA_DIR", schema_dir);
179-
env::set_var("GSETTINGS_BACKEND", "memory");
178+
unsafe {
179+
env::set_var("GSETTINGS_SCHEMA_DIR", schema_dir);
180+
env::set_var("GSETTINGS_BACKEND", "memory");
181+
}
180182
});
181183
}
182184

src/window/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ use std::cell::RefCell;
1313

1414
use self::{progress_icon::ProgressIcon, toggle_button::ToggleButton};
1515
use crate::{
16+
Application,
1617
cancelled::Cancelled,
1718
config::PROFILE,
1819
format,
1920
help::ContextWithHelp,
2021
preferences_dialog::PreferencesDialog,
2122
recording::{NoProfileError, Recording, RecordingState},
2223
settings::CaptureMode,
23-
Application,
2424
};
2525

2626
mod imp {
@@ -420,7 +420,7 @@ impl Window {
420420
let recent_manager = gtk::RecentManager::default();
421421
recent_manager.add_item(&recording_file.uri());
422422
}
423-
Err(ref err) => {
423+
Err(err) => {
424424
if err.is::<Cancelled>() {
425425
tracing::debug!("{:?}", err);
426426
} else if err.is::<NoProfileError>() {
@@ -463,12 +463,10 @@ impl Window {
463463
imp.inhibit_cookie.replace(Some(inhibit_cookie));
464464

465465
tracing::debug!("Inhibited logout and idle");
466-
} else if !is_busy {
467-
if let Some(inhibit_cookie) = imp.inhibit_cookie.take() {
468-
app.uninhibit(inhibit_cookie);
466+
} else if !is_busy && let Some(inhibit_cookie) = imp.inhibit_cookie.take() {
467+
app.uninhibit(inhibit_cookie);
469468

470-
tracing::debug!("Uninhibited logout and idle");
471-
}
469+
tracing::debug!("Uninhibited logout and idle");
472470
}
473471
}
474472

0 commit comments

Comments
 (0)