Skip to content

Commit 9f526e2

Browse files
committed
chore(imports)
Cleaned up imports so they are at the top of the file, nothing serious just picky
1 parent 3a8e96e commit 9f526e2

4 files changed

Lines changed: 49 additions & 54 deletions

File tree

src/app.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,23 @@ use iced::{
1717
};
1818

1919
#[cfg(target_os = "macos")]
20-
use crate::macos::{focus_this_app, transform_process_to_ui_element};
21-
#[cfg(target_os = "macos")]
22-
use crate::{macos, utils::get_installed_apps};
23-
#[cfg(target_os = "macos")]
24-
use objc2::rc::Retained;
25-
#[cfg(target_os = "macos")]
26-
use objc2_app_kit::NSRunningApplication;
20+
use {
21+
crate::macos::{focus_this_app, macos_window_config, transform_process_to_ui_element},
22+
objc2::rc::Retained,
23+
objc2_app_kit::NSApplicationActivationOptions,
24+
objc2_app_kit::NSRunningApplication,
25+
objc2_app_kit::NSWorkspace,
26+
};
2727

2828
#[cfg(target_os = "windows")]
29-
use windows::Win32::Foundation::HWND;
30-
#[cfg(target_os = "windows")]
31-
use windows::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, SetForegroundWindow};
29+
use {
30+
crate::windows::open_on_focused_monitor,
31+
crate::windows::open_on_focused_monitor,
32+
iced::window::Position::Specific,
33+
iced::window::Position::Specific,
34+
windows::Win32::Foundation::HWND,
35+
windows::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, SetForegroundWindow},
36+
};
3237

3338
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
3439
use rayon::slice::ParallelSliceMut;
@@ -170,8 +175,6 @@ impl Tile {
170175
#[cfg(target_os = "windows")]
171176
{
172177
// get normal settings and modify position
173-
use crate::windows::open_on_focused_monitor;
174-
use iced::window::Position::Specific;
175178
let pos = open_on_focused_monitor();
176179
settings.position = Specific(pos);
177180
}
@@ -182,7 +185,7 @@ impl Tile {
182185
{
183186
#[cfg(target_os = "macos")]
184187
{
185-
macos::macos_window_config(
188+
macos_window_config(
186189
&handle.window_handle().expect("Unable to get window handle"),
187190
);
188191
// should work now that we have a window
@@ -313,8 +316,6 @@ impl Tile {
313316
#[cfg(target_os = "windows")]
314317
{
315318
// get normal settings and modify position
316-
use crate::windows::open_on_focused_monitor;
317-
use iced::window::Position::Specific;
318319
let pos = open_on_focused_monitor();
319320
let mut settings = default_settings();
320321
settings.position = Specific(pos);
@@ -482,8 +483,6 @@ impl Tile {
482483
pub fn capture_frontmost(&mut self) {
483484
#[cfg(target_os = "macos")]
484485
{
485-
use objc2_app_kit::NSWorkspace;
486-
487486
let ws = NSWorkspace::sharedWorkspace();
488487
self.frontmost = ws.frontmostApplication();
489488
};
@@ -498,8 +497,6 @@ impl Tile {
498497
pub fn restore_frontmost(&mut self) {
499498
#[cfg(target_os = "macos")]
500499
{
501-
use objc2_app_kit::NSApplicationActivationOptions;
502-
503500
if let Some(app) = self.frontmost.take() {
504501
app.activateWithOptions(NSApplicationActivationOptions::ActivateIgnoringOtherApps);
505502
}

src/macos.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,37 @@
33
use crate::app::App;
44
use crate::commands::Function;
55
use crate::config::Config;
6+
use crate::utils::index_dirs_from_config;
67
use crate::utils::{handle_from_icns, log_error, log_error_and_exit};
8+
use std::ptr;
79
#[cfg(target_os = "macos")]
8-
use iced::wgpu::rwh::WindowHandle;
10+
use {
11+
iced::wgpu::rwh::RawWindowHandle,
12+
iced::wgpu::rwh::WindowHandle,
13+
objc2::MainThreadMarker,
14+
objc2::rc::Retained,
15+
objc2_app_kit::NSView,
16+
objc2_app_kit::{NSApp, NSApplicationActivationPolicy},
17+
objc2_app_kit::{NSFloatingWindowLevel, NSWindowCollectionBehavior},
18+
objc2_application_services::{
19+
TransformProcessType, kCurrentProcess, kProcessTransformToUIElementApplication,
20+
},
21+
};
22+
923
use rayon::iter::{IntoParallelIterator, IntoParallelRefIterator, ParallelIterator};
1024
use std::fs;
1125
use std::path::{Path, PathBuf};
1226
use std::process::exit;
13-
use crate::utils::index_dirs_from_config;
1427

1528
#[cfg(target_os = "macos")]
1629
pub fn set_activation_policy_accessory() {
17-
use objc2::MainThreadMarker;
18-
use objc2_app_kit::{NSApp, NSApplicationActivationPolicy};
19-
2030
let mtm = MainThreadMarker::new().expect("must be on main thread");
2131
let app = NSApp(mtm);
2232
app.setActivationPolicy(NSApplicationActivationPolicy::Accessory);
2333
}
2434

2535
#[cfg(target_os = "macos")]
2636
pub fn macos_window_config(handle: &WindowHandle) {
27-
use iced::wgpu::rwh::RawWindowHandle;
28-
use objc2::rc::Retained;
29-
use objc2_app_kit::NSView;
30-
3137
match handle.as_raw() {
3238
RawWindowHandle::AppKit(handle) => {
3339
let ns_view = handle.ns_view.as_ptr();
@@ -36,7 +42,6 @@ pub fn macos_window_config(handle: &WindowHandle) {
3642
.window()
3743
.expect("view was not installed in a window");
3844

39-
use objc2_app_kit::{NSFloatingWindowLevel, NSWindowCollectionBehavior};
4045
ns_window.setLevel(NSFloatingWindowLevel);
4146

4247
ns_window.setCollectionBehavior(NSWindowCollectionBehavior::CanJoinAllSpaces);
@@ -74,11 +79,6 @@ struct ProcessSerialNumber {
7479
/// doesn't seem to do anything if you haven't opened a window yet, so wait to call it until after that.
7580
#[cfg(target_os = "macos")]
7681
pub fn transform_process_to_ui_element() -> u32 {
77-
use std::ptr;
78-
79-
use objc2_application_services::{
80-
TransformProcessType, kCurrentProcess, kProcessTransformToUIElementApplication,
81-
};
8282
let psn = ProcessSerialNumber {
8383
low: 0,
8484
hi: kCurrentProcess,
@@ -218,7 +218,6 @@ pub fn get_installed_macos_apps(config: &Config) -> Vec<App> {
218218
"/System/Applications/Utilities/".to_string(),
219219
];
220220

221-
222221
let mut apps = paths
223222
.par_iter()
224223
.map(|path| get_installed_apps(path, store_icons))
@@ -227,5 +226,4 @@ pub fn get_installed_macos_apps(config: &Config) -> Vec<App> {
227226
index_dirs_from_config(&mut apps);
228227

229228
apps
230-
231229
}

src/utils.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use image::RgbaImage;
1212

1313
use crate::{app::App, commands::Function};
1414
#[cfg(target_os = "macos")]
15-
use objc2_app_kit::NSWorkspace;
16-
#[cfg(target_os = "macos")]
17-
use objc2_foundation::NSURL;
15+
use {crate::macos::get_installed_macos_apps, objc2_app_kit::NSWorkspace, objc2_foundation::NSURL};
16+
#[cfg(target_os = "windows")]
17+
use {crate::windows::get_installed_windows_apps, std::process::Command};
1818

1919
const ERR_LOG_PATH: &str = "/tmp/rustscan-err.log";
2020

@@ -229,8 +229,6 @@ pub fn create_config_file_if_not_exists(
229229
pub fn open_application(path: &String) {
230230
#[cfg(target_os = "windows")]
231231
{
232-
use std::process::Command;
233-
234232
println!("Opening application: {}", path);
235233

236234
Command::new("powershell")
@@ -298,11 +296,13 @@ pub fn index_dirs_from_config(apps: &mut Vec<App>) -> bool {
298296
}
299297

300298
pub fn get_installed_apps(config: &Config) -> Vec<App> {
301-
if cfg!(target_os = "macos") {
302-
use crate::macos::get_installed_macos_apps;
299+
#[cfg(target_os = "macos")]
300+
{
303301
get_installed_macos_apps(config)
304-
} else {
305-
use crate::windows::get_installed_windows_apps;
302+
}
303+
304+
#[cfg(target_os = "windows")]
305+
{
306306
get_installed_windows_apps()
307307
}
308308
}

src/windows.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ use walkdir::WalkDir;
44

55
use crate::app::{DEFAULT_WINDOW_HEIGHT, WINDOW_WIDTH};
66
#[cfg(target_os = "windows")]
7-
use windows::Win32::UI::WindowsAndMessaging::GetCursorPos;
8-
9-
#[cfg(target_os = "windows")]
10-
use windows::Win32::System::Com::CoTaskMemFree;
11-
#[cfg(target_os = "windows")]
12-
use windows::Win32::UI::Shell::{
13-
FOLDERID_LocalAppData, FOLDERID_ProgramFiles, FOLDERID_ProgramFilesX86, KF_FLAG_DEFAULT,
14-
SHGetKnownFolderPath,
7+
use {
8+
windows::Win32::System::Com::CoTaskMemFree,
9+
windows::Win32::UI::Shell::{
10+
FOLDERID_LocalAppData, FOLDERID_ProgramFiles, FOLDERID_ProgramFilesX86, KF_FLAG_DEFAULT,
11+
SHGetKnownFolderPath,
12+
},
13+
windows::Win32::UI::WindowsAndMessaging::GetCursorPos,
14+
windows::core::GUID,
1515
};
16-
use windows::core::GUID;
16+
1717
#[cfg(target_os = "windows")]
1818
fn get_apps_from_registry(apps: &mut Vec<App>) {
1919
use std::ffi::OsString;

0 commit comments

Comments
 (0)