Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 25 additions & 19 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::process::Command;
use std::{process::Command, thread};

use arboard::Clipboard;
use objc2_app_kit::NSWorkspace;
Expand All @@ -20,9 +20,12 @@ impl Function {
pub fn execute(&self, config: &Config, query: &str) {
match self {
Function::OpenApp(path) => {
NSWorkspace::new().openURL(&NSURL::fileURLWithPath(
&objc2_foundation::NSString::from_str(path),
));
let path = path.to_owned();
thread::spawn(move || {
NSWorkspace::new().openURL(&NSURL::fileURLWithPath(
&objc2_foundation::NSString::from_str(&path),
));
});
}
Function::RunShellCommand => {
Command::new("sh").arg("-c").arg(query).status().ok();
Expand All @@ -37,24 +40,27 @@ impl Function {
Function::GoogleSearch(query_string) => {
let query_args = query_string.replace(" ", "+");
let query = config.search_url.replace("%s", &query_args);
let query = query.strip_suffix("?").unwrap_or(&query);
NSWorkspace::new().openURL(
&NSURL::URLWithString_relativeToURL(
&objc2_foundation::NSString::from_str(query),
None,
)
.unwrap(),
);
let query = query.strip_suffix("?").unwrap_or(&query).to_string();
thread::spawn(move || {
NSWorkspace::new().openURL(
&NSURL::URLWithString_relativeToURL(
&objc2_foundation::NSString::from_str(&query),
None,
)
.unwrap(),
);
});
}

Function::OpenPrefPane => {
Command::new("open")
.arg(
std::env::var("HOME").unwrap_or("".to_string())
+ "/.config/rustcast/config.toml",
)
.spawn()
.ok();
thread::spawn(move || {
NSWorkspace::new().openURL(&NSURL::fileURLWithPath(
&objc2_foundation::NSString::from_str(
&(std::env::var("HOME").unwrap_or("".to_string())
+ "/.config/rustcast/config.toml"),
),
));
});
}
Function::Quit => std::process::exit(0),
}
Expand Down
19 changes: 12 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ mod config;
mod macos;
mod utils;

use std::path::Path;

use crate::{app::Tile, config::Config, utils::to_key_code};

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

let file_path = home.clone() + "/.config/rustcast/config.toml";
if !Path::new(&file_path).exists() {
std::fs::create_dir_all(home + "/.config/rustcast").unwrap();
std::fs::write(
&file_path,
toml::to_string(&Config::default()).unwrap_or_else(|x| x.to_string()),
)
.unwrap();
}
let config: Config = match std::fs::read_to_string(&file_path) {
Ok(a) => toml::from_str(&a).unwrap(),
Ok(a) => toml::from_str(&a).unwrap_or(Config::default()),
Err(_) => Config::default(),
};
std::fs::create_dir_all(home + "/.config/rustcast").unwrap();
std::fs::write(
&file_path,
toml::to_string(&config).unwrap_or_else(|x| x.to_string()),
)
.unwrap();

let manager = GlobalHotKeyManager::new().unwrap();

let show_hide = HotKey::new(
Expand Down