Skip to content

Commit 3caa1c2

Browse files
committed
Minor code cleanup
- Removed leftover files - Fixed formatting - Fixed struct member visibility - Added a missing comment - Renamed some methods to be more generic
1 parent 14567ed commit 3caa1c2

File tree

5 files changed

+26
-131
lines changed

5 files changed

+26
-131
lines changed

src/gui/connected_tab/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ use windows_sys::Win32::UI::Controls::LVSCW_AUTOSIZE_USEHEADER;
1212
use windows_sys::Win32::UI::Shell::SIID_SHIELD;
1313

1414
use self::device_info::DeviceInfo;
15-
use crate::gui::nwg_ext::{BitmapEx, MenuItemEx};
16-
use crate::gui::usbipd_gui::GuiTab;
15+
use crate::gui::{
16+
nwg_ext::{BitmapEx, MenuItemEx},
17+
usbipd_gui::GuiTab,
18+
};
1719
use crate::usbipd::{self, UsbDevice};
1820

1921
const PADDING_LEFT: Rect<D> = Rect {
@@ -77,12 +79,12 @@ pub struct ConnectedTab {
7779
#[nwg_control(parent: buttons_frame, text: "Attach")]
7880
#[nwg_layout_item(layout: buttons_layout, flex_grow: 0.33)]
7981
#[nwg_events(OnButtonClick: [ConnectedTab::attach_detach_device])]
80-
pub attach_detach_button: nwg::Button,
82+
attach_detach_button: nwg::Button,
8183

8284
#[nwg_control(parent: buttons_frame, text: "Bind")]
8385
#[nwg_layout_item(layout: buttons_layout, flex_grow: 0.33)]
8486
#[nwg_events(OnButtonClick: [ConnectedTab::bind_unbind_device])]
85-
pub bind_unbind_button: nwg::Button,
87+
bind_unbind_button: nwg::Button,
8688

8789
// Device context menu
8890
#[nwg_control(text: "Device", popup: true)]
@@ -113,7 +115,7 @@ pub struct ConnectedTab {
113115
}
114116

115117
impl ConnectedTab {
116-
fn init_device_list(&self) {
118+
fn init_list(&self) {
117119
let dv = &self.list_view;
118120
dv.clear();
119121
dv.insert_column("Bus ID");
@@ -127,7 +129,7 @@ impl ConnectedTab {
127129
}
128130

129131
/// Clears the device list and reloads it with the currently connected devices.
130-
fn refresh_device_list(&self) {
132+
fn refresh_list(&self) {
131133
self.update_devices();
132134

133135
self.list_view.clear();
@@ -354,12 +356,12 @@ impl GuiTab for ConnectedTab {
354356

355357
self.shield_bitmap.set(shield_bitmap);
356358

357-
self.init_device_list();
359+
self.init_list();
358360
self.refresh();
359361
}
360362

361363
fn refresh(&self) {
362-
self.refresh_device_list();
364+
self.refresh_list();
363365
self.update_device_details();
364366
}
365367
}

src/gui/device_info.rs

Lines changed: 0 additions & 114 deletions
This file was deleted.

src/gui/persisted_tab/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use nwg::stretch::{
1111
use windows_sys::Win32::UI::{Controls::LVSCW_AUTOSIZE_USEHEADER, Shell::SIID_SHIELD};
1212

1313
use self::profile_info::ProfileInfo;
14-
use crate::gui::nwg_ext::BitmapEx;
15-
use crate::gui::usbipd_gui::GuiTab;
14+
use crate::gui::{
15+
nwg_ext::{BitmapEx, MenuItemEx},
16+
usbipd_gui::GuiTab,
17+
};
1618
use crate::usbipd::{self, UsbDevice};
1719

18-
use super::nwg_ext::MenuItemEx;
19-
2020
const PADDING_LEFT: Rect<D> = Rect {
2121
start: D::Points(8.0),
2222
end: D::Points(0.0),
@@ -78,7 +78,7 @@ pub struct PersistedTab {
7878
#[nwg_control(parent: buttons_frame, text: "Delete")]
7979
#[nwg_layout_item(layout: buttons_layout, flex_grow: 0.33)]
8080
#[nwg_events(OnButtonClick: [PersistedTab::delete])]
81-
pub delete_button: nwg::Button,
81+
delete_button: nwg::Button,
8282

8383
// Device context menu
8484
#[nwg_control(text: "Device", popup: true)]
@@ -90,7 +90,7 @@ pub struct PersistedTab {
9090
}
9191

9292
impl PersistedTab {
93-
fn init_device_list(&self) {
93+
fn init_list(&self) {
9494
let dv = &self.list_view;
9595
dv.clear();
9696
dv.insert_column("Profile");
@@ -101,7 +101,7 @@ impl PersistedTab {
101101
}
102102

103103
/// Clears the device list and reloads it with the currently persisted devices.
104-
fn refresh_device_list(&self) {
104+
fn refresh_list(&self) {
105105
self.update_devices();
106106

107107
self.list_view.clear();
@@ -212,12 +212,12 @@ impl GuiTab for PersistedTab {
212212

213213
self.shield_bitmap.set(shield_bitmap);
214214

215-
self.init_device_list();
215+
self.init_list();
216216
self.refresh();
217217
}
218218

219219
fn refresh(&self) {
220-
self.refresh_device_list();
220+
self.refresh_list();
221221
self.update_profile_details();
222222
}
223223
}

src/usbipd.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,22 @@ impl Display for UsbipState {
5151
pub struct UsbDevice {
5252
#[serde(rename = "BusId")]
5353
pub bus_id: Option<String>,
54+
5455
#[serde(rename = "ClientIPAddress")]
5556
pub client_ip_address: Option<String>,
57+
5658
#[serde(rename = "Description")]
5759
pub description: Option<String>,
60+
5861
#[serde(rename = "InstanceId")]
5962
pub instance_id: Option<String>,
63+
6064
#[serde(rename = "IsForced")]
6165
pub is_forced: bool,
66+
6267
#[serde(rename = "PersistedGuid")]
6368
pub persisted_guid: Option<String>,
69+
6470
#[serde(rename = "StubInstanceGuid")]
6571
pub stub_instance_id: Option<String>,
6672
}

src/win_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub fn get_last_error_string() -> String {
6363
pub fn register_usb_device_notifications(
6464
callback: impl Fn() + 'static,
6565
) -> Result<DeviceNotification, u32> {
66+
// The callback function that will be called by the system, which will then call the user's closure
6667
extern "system" fn callback_impl(
6768
_hnotify: HCMNOTIFICATION,
6869
context: *const std::ffi::c_void,

0 commit comments

Comments
 (0)