Skip to content

Commit a271451

Browse files
authored
Merge pull request #43 from unsecretised/issue-fixes
Issue fixes
2 parents 1bd9dea + 478734e commit a271451

2 files changed

Lines changed: 37 additions & 26 deletions

File tree

src/commands.rs

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::process::Command;
1+
use std::{process::Command, thread};
22

33
use arboard::Clipboard;
44
use objc2_app_kit::NSWorkspace;
@@ -20,9 +20,12 @@ impl Function {
2020
pub fn execute(&self, config: &Config, query: &str) {
2121
match self {
2222
Function::OpenApp(path) => {
23-
NSWorkspace::new().openURL(&NSURL::fileURLWithPath(
24-
&objc2_foundation::NSString::from_str(path),
25-
));
23+
let path = path.to_owned();
24+
thread::spawn(move || {
25+
NSWorkspace::new().openURL(&NSURL::fileURLWithPath(
26+
&objc2_foundation::NSString::from_str(&path),
27+
));
28+
});
2629
}
2730
Function::RunShellCommand => {
2831
Command::new("sh").arg("-c").arg(query).status().ok();
@@ -37,24 +40,27 @@ impl Function {
3740
Function::GoogleSearch(query_string) => {
3841
let query_args = query_string.replace(" ", "+");
3942
let query = config.search_url.replace("%s", &query_args);
40-
let query = query.strip_suffix("?").unwrap_or(&query);
41-
NSWorkspace::new().openURL(
42-
&NSURL::URLWithString_relativeToURL(
43-
&objc2_foundation::NSString::from_str(query),
44-
None,
45-
)
46-
.unwrap(),
47-
);
43+
let query = query.strip_suffix("?").unwrap_or(&query).to_string();
44+
thread::spawn(move || {
45+
NSWorkspace::new().openURL(
46+
&NSURL::URLWithString_relativeToURL(
47+
&objc2_foundation::NSString::from_str(&query),
48+
None,
49+
)
50+
.unwrap(),
51+
);
52+
});
4853
}
4954

5055
Function::OpenPrefPane => {
51-
Command::new("open")
52-
.arg(
53-
std::env::var("HOME").unwrap_or("".to_string())
54-
+ "/.config/rustcast/config.toml",
55-
)
56-
.spawn()
57-
.ok();
56+
thread::spawn(move || {
57+
NSWorkspace::new().openURL(&NSURL::fileURLWithPath(
58+
&objc2_foundation::NSString::from_str(
59+
&(std::env::var("HOME").unwrap_or("".to_string())
60+
+ "/.config/rustcast/config.toml"),
61+
),
62+
));
63+
});
5864
}
5965
Function::Quit => std::process::exit(0),
6066
}

src/main.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ mod config;
44
mod macos;
55
mod utils;
66

7+
use std::path::Path;
8+
79
use crate::{app::Tile, config::Config, utils::to_key_code};
810

911
use global_hotkey::{
@@ -20,16 +22,19 @@ fn main() -> iced::Result {
2022
let home = std::env::var("HOME").unwrap();
2123

2224
let file_path = home.clone() + "/.config/rustcast/config.toml";
25+
if !Path::new(&file_path).exists() {
26+
std::fs::create_dir_all(home + "/.config/rustcast").unwrap();
27+
std::fs::write(
28+
&file_path,
29+
toml::to_string(&Config::default()).unwrap_or_else(|x| x.to_string()),
30+
)
31+
.unwrap();
32+
}
2333
let config: Config = match std::fs::read_to_string(&file_path) {
24-
Ok(a) => toml::from_str(&a).unwrap(),
34+
Ok(a) => toml::from_str(&a).unwrap_or(Config::default()),
2535
Err(_) => Config::default(),
2636
};
27-
std::fs::create_dir_all(home + "/.config/rustcast").unwrap();
28-
std::fs::write(
29-
&file_path,
30-
toml::to_string(&config).unwrap_or_else(|x| x.to_string()),
31-
)
32-
.unwrap();
37+
3338
let manager = GlobalHotKeyManager::new().unwrap();
3439

3540
let show_hide = HotKey::new(

0 commit comments

Comments
 (0)