Skip to content

Commit ea49759

Browse files
authored
Merge pull request #36 from Nazeofel/windows-support
Windows support - don't kaboom macos compiling
2 parents 58cbb2d + fbb7eb3 commit ea49759

3 files changed

Lines changed: 35 additions & 23 deletions

File tree

src/app.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,25 +182,25 @@ impl Tile {
182182

183183
let (id, open) = window::open(settings);
184184

185-
#[cfg(target_os = "macos")]
186-
{
187-
let open = open.discard().chain(window::run(id, |handle| {
185+
let open = open.discard().chain(window::run(id, |handle| {
186+
{
187+
#[cfg(target_os = "macos")]
188188
{
189189
macos::macos_window_config(
190190
&handle.window_handle().expect("Unable to get window handle"),
191191
);
192192
// should work now that we have a window
193193
transform_process_to_ui_element();
194194
}
195-
}));
196-
}
195+
}
196+
}));
197197

198198
let store_icons = config.theme.show_icons;
199199
let paths;
200-
200+
let user_local_path: String;
201201
#[cfg(target_os = "macos")]
202202
{
203-
let user_local_path = std::env::var("HOME").unwrap() + "/Applications/";
203+
user_local_path = std::env::var("HOME").unwrap() + "/Applications/";
204204
paths = vec![
205205
"/Applications/",
206206
user_local_path.as_str(),
@@ -259,6 +259,15 @@ impl Tile {
259259
focus_this_app();
260260
}
261261

262+
#[cfg(target_os = "windows")]
263+
{
264+
if let Some(hwnd) = self.frontmost {
265+
unsafe {
266+
let _ = SetForegroundWindow(hwnd);
267+
}
268+
}
269+
}
270+
262271
self.focused = true;
263272
Task::none()
264273
}
@@ -581,6 +590,7 @@ fn handle_hotkeys() -> impl futures::Stream<Item = Message> {
581590
})
582591
}
583592

593+
#[cfg(target_os = "windows")]
584594
fn get_installed_windows_app(path: &Path) -> Vec<App> {
585595
use std::ffi::OsString;
586596

src/commands.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::process::Command;
22

33
use arboard::Clipboard;
4-
54
#[cfg(target_os = "macos")]
65
use objc2_app_kit::NSWorkspace;
76
#[cfg(target_os = "macos")]

src/utils.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,24 @@ use std::{
55
process::exit,
66
};
77

8+
use crate::app::{DEFAULT_WINDOW_HEIGHT, WINDOW_WIDTH};
89
use global_hotkey::hotkey::Code;
910
use iced::{futures::io::Window, widget::image::Handle};
1011
use icns::IconFamily;
1112
use image::RgbaImage;
1213
use rayon::iter::{IntoParallelIterator, ParallelIterator};
14+
15+
#[cfg(target_os = "windows")]
1316
use windows::Win32::{
1417
Graphics::Gdi::MonitorFromPoint,
1518
UI::WindowsAndMessaging::{GetCursor, GetCursorPos},
1619
};
1720

1821
use crate::{app::App, commands::Function};
22+
#[cfg(target_os = "macos")]
23+
use objc2_app_kit::NSWorkspace;
24+
#[cfg(target_os = "macos")]
25+
use objc2_foundation::NSURL;
1926

2027
const ERR_LOG_PATH: &str = "/tmp/rustscan-err.log";
2128

@@ -307,7 +314,7 @@ pub fn get_config_file_path() -> String {
307314
let file_path = if cfg!(target_os = "windows") {
308315
home + "\\rustcast\\config.toml"
309316
} else {
310-
home + "/.rustcast/config.toml"
317+
home + "/.config/rustcast/config.toml"
311318
};
312319

313320
return file_path;
@@ -327,22 +334,18 @@ pub fn create_config_file_if_not_exists(
327334
file_path: &str,
328335
config: &Config,
329336
) -> Result<(), std::io::Error> {
330-
if std::path::Path::new(&get_config_file_path()).exists() {
331-
return Ok(());
332-
}
333-
334-
#[cfg(target_os = "windows")]
335-
{
336-
use std::path::Path;
337-
let path = Path::new(&file_path);
338-
if let Some(parent) = path.parent() {
339-
std::fs::create_dir_all(parent).unwrap();
337+
// check if file exists
338+
if let Ok(exists) = std::fs::metadata(&file_path) {
339+
if exists.is_file() {
340+
return Ok(());
340341
}
341342
}
342-
#[cfg(target_os = "macos")]
343-
{
344-
std::fs::create_dir_all(&file_path).unwrap();
343+
344+
let path = Path::new(&file_path);
345+
if let Some(parent) = path.parent() {
346+
std::fs::create_dir_all(parent).unwrap();
345347
}
348+
346349
std::fs::write(
347350
&file_path,
348351
toml::to_string(&config).unwrap_or_else(|x| x.to_string()),
@@ -378,7 +381,7 @@ pub fn open_application(path: &String) {
378381
}
379382
}
380383

381-
use crate::app::{DEFAULT_WINDOW_HEIGHT, WINDOW_WIDTH};
384+
#[cfg(target_os = "windows")]
382385
pub fn open_on_focused_monitor() -> iced::Point {
383386
use windows::Win32::Foundation::POINT;
384387
use windows::Win32::Graphics::Gdi::{

0 commit comments

Comments
 (0)