Skip to content

Commit 949a8f0

Browse files
committed
Closes rustcast immediately, even if the app doesn't launch instantly
1 parent 2f994a2 commit 949a8f0

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

src/commands.rs

Lines changed: 17 additions & 12 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,14 +40,16 @@ 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 => {

0 commit comments

Comments
 (0)