Skip to content
Closed
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
16 changes: 8 additions & 8 deletions src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ pub enum Expr {
Number(f64),
Unary {
op: UnaryOp,
rhs: Box<Expr>,
rhs: Box<Self>,
},
Binary {
op: BinOp,
lhs: Box<Expr>,
rhs: Box<Expr>,
lhs: Box<Self>,
rhs: Box<Self>,
},
Func {
name: String,
args: Vec<Expr>,
args: Vec<Self>,
},
}

Expand All @@ -52,17 +52,17 @@ impl Expr {
use BinOp::*;
use UnaryOp::*;
match self {
Expr::Number(x) => Some(*x),
Self::Number(x) => Some(*x),

Expr::Unary { op, rhs } => {
Self::Unary { op, rhs } => {
let v = rhs.eval()?;
Some(match op {
Plus => v,
Minus => -v,
})
}

Expr::Binary { op, lhs, rhs } => {
Self::Binary { op, lhs, rhs } => {
let a = lhs.eval()?;
let b = rhs.eval()?;
match op {
Expand All @@ -74,7 +74,7 @@ impl Expr {
}
}

Expr::Func { name, args } => {
Self::Func { name, args } => {
let name = name.as_str();
match name {
"ln" => {
Expand Down
4 changes: 2 additions & 2 deletions src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ impl ClipBoardContentType {
/// display name is only the first line
pub fn to_app(&self) -> App {
let mut name = match self {
ClipBoardContentType::Image(_) => "<img>".to_string(),
ClipBoardContentType::Text(a) => a.to_owned(),
Self::Image(_) => "<img>".to_string(),
Self::Text(a) => a.to_owned(),
};

let self_clone = self.clone();
Expand Down
18 changes: 9 additions & 9 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ impl Function {
/// Run the command
pub fn execute(&self, config: &Config, query: &str) {
match self {
Function::OpenApp(path) => {
Self::OpenApp(path) => {
let path = path.to_owned();
thread::spawn(move || {
NSWorkspace::new().openURL(&NSURL::fileURLWithPath(
&objc2_foundation::NSString::from_str(&path),
));
});
}
Function::RunShellCommand(command, alias) => {
Self::RunShellCommand(command, alias) => {
let query = query.to_string();
let final_command =
format!(r#"{} {}"#, command, query.strip_prefix(alias).unwrap_or(""));
Expand All @@ -44,14 +44,14 @@ impl Function {
.spawn()
.ok();
}
Function::RandomVar(var) => {
Self::RandomVar(var) => {
Clipboard::new()
.unwrap()
.set_text(var.to_string())
.unwrap_or(());
}

Function::GoogleSearch(query_string) => {
Self::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).to_string();
Expand All @@ -66,7 +66,7 @@ impl Function {
});
}

Function::OpenWebsite(url) => {
Self::OpenWebsite(url) => {
let open = if url.starts_with("http") {
url.to_owned()
} else {
Expand All @@ -83,14 +83,14 @@ impl Function {
});
}

Function::Calculate(expr) => {
Self::Calculate(expr) => {
Clipboard::new()
.unwrap()
.set_text(expr.eval().map(|x| x.to_string()).unwrap_or("".to_string()))
.unwrap_or(());
}

Function::CopyToClipboard(clipboard_content) => match clipboard_content {
Self::CopyToClipboard(clipboard_content) => match clipboard_content {
ClipBoardContentType::Text(text) => {
Clipboard::new().unwrap().set_text(text).ok();
}
Expand All @@ -99,7 +99,7 @@ impl Function {
}
},

Function::OpenPrefPane => {
Self::OpenPrefPane => {
thread::spawn(move || {
NSWorkspace::new().openURL(&NSURL::fileURLWithPath(
&objc2_foundation::NSString::from_str(
Expand All @@ -109,7 +109,7 @@ impl Function {
));
});
}
Function::Quit => std::process::exit(0),
Self::Quit => std::process::exit(0),
}
}
}
23 changes: 11 additions & 12 deletions src/haptics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,18 @@ fn mts_state() -> Option<&'static MtsState> {
/// Perform a haptic feedback - Just use this function to perform haptic feedback... please don't
/// remake this function unless you're a genius or absolutely have to
pub fn perform_haptic(pattern: HapticPattern) -> bool {
if let Some(state) = mts_state() {
let pat = pattern_index(pattern);
let mut any_ok = false;
unsafe {
for &act in &state.actuators {
if !act.is_null() && MTActuatorIsOpen(act) {
let kr = MTActuatorActuate(act, pat, 0, 0.0, 0.0);
any_ok |= kr == 0;
}
let Some(state) = mts_state() else {
return false;
};
let pat = pattern_index(pattern);
let mut any_ok = false;
unsafe {
for &act in &state.actuators {
if !act.is_null() && MTActuatorIsOpen(act) {
let kr = MTActuatorActuate(act, pat, 0, 0.0, 0.0);
any_ok |= kr == 0;
}
}
any_ok
} else {
false
}
any_ok
}